Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question GraphicsFormat error

Discussion in 'Universal Render Pipeline' started by feeonyt, Jan 4, 2024.

  1. feeonyt

    feeonyt

    Joined:
    Nov 16, 2022
    Posts:
    2
    Hello,
    For the past hour I've been following this tutorial by Game Dev Guide. At one point in the video, he uses a GraphicsFormat. Now, after trying to find documentation about this i stumbled upon the its unity documentation, where it said that it used UnityEngine.Experimental.Rendering. I tried putting that behind the GraphicsFormat, but the only thing it does is present 30 errors from different parts of the script. Could anyone help me with this? Here's the code:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.Universal;
    4.  
    5. public class CustomPostProcessPass : ScriptableRenderPass
    6. {
    7.     private Material m_bloomMaterial;
    8.     private Material m_compositeMaterial;
    9.  
    10.     const int k_MaxPyramidSize = 16;
    11.     private int[] _BloomMipUp;
    12.     private int[] _BloomMipDown;
    13.     private RTHandle[] m_BloomMipUp;
    14.     private RTHandle[] m_BloomMipDown;
    15.     private GraphicsFormat hdrFormat;
    16.  
    17.     public CustomPostProcessPass(Material bloomMaterial, Material compositeMaterial) {
    18.         m_bloomMaterial = bloomMaterial;
    19.         m_compositeMaterial = compositeMaterial;
    20.  
    21.         renderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing;
    22.  
    23.         _BloomMipUp = new int[k_MaxPyramidSize];
    24.         _BloomMipDown = new int[k_MaxPyramidSize];
    25.         m_BloomMipUp = new RTHandle[k_MaxPyramidSize];
    26.         m_BloomMipDown = new RTHandle[k_MaxPyramidSize];
    27.  
    28.         for (int i = 0; i < k_MaxPyramidSize; i++)
    29.         {
    30.             ShaderConstants._BloomMipUp[i] = Shader.PropertyToID("_BloomMipUp" + i);
    31.             ShaderConstants._BloomMipDown[i] = Shader.PropertyToID("_BloomMipDown" + i);
    32.             // Get name, will get Allocated with descriptor later
    33.             m_BloomMipUp[i] = RTHandles.Alloc(ShaderConstants._BloomMipUp[i], name: "_BloomMipUp" + i);
    34.             m_BloomMipDown[i] = RTHandles.Alloc(ShaderConstants._BloomMipDown[i], name: "_BloomMipDown" + i);
    35.            
    36.         }
    37.  
    38.         const FormatUsage usage = FormatUsage.Linear | FormatUsage.Renderer;
    39.         if(SystemInfo.IsFormatSupported(GraphicsFormat.B10G11R11_UFloatPack32, usage)) {
    40.             hdrFormat = GraphicsFormat.B10G11R11_UFloatPack32;
    41.         }
    42.         else {
    43.             hdrFormat = QualitySettings.activeColorSpace == ColorSpace.Linear
    44.                 ? GraphicsFormat.R8G8B8A8_SRGB
    45.                 : GraphicsFormat.R8G8B8A8_UNorm;
    46.         }
    47.     }
    48.     public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData) {
    49.         m_Descriptor = renderingData.cameraData.cameraTargetDescriptor;
    50.     }
    51.  
    52.     public void SetTarget(RTHandle cameraColorTargetHandle, RTHandle cameraDepthTargetHandle) {
    53.         m_CameraColorTarget = cameraColorTargetHandle;
    54.         m_CameraDepthTarget = cameraDepthTargetHandle;
    55.     }
    56.  
    57.     public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    58.     {
    59.         VolumeStack stack = VolumeManager.instance.stack;
    60.         m_BloomEffect = stack.GetComponent<BloomEffect>();
    61.  
    62.         CommandBuffer cmd = CommandBufferPool.Get();
    63.  
    64.         using (new ProfilingScope(cmd, new ProfilingSampler("Custom Post Process Effects"))) {
    65.             SetupBloom(cmd, m_CameraColorTarget);
    66.         }
    67.     }
    68.  
    69.     private void SetupBloom(CommandBuffer cmd, RTHandle source, Material uberMaterial)
    70.         {
    71.             // Start at half-res
    72.             int downres = 1;
    73.             switch (m_Bloom.downscale.value)
    74.             {
    75.                 case BloomDownscaleMode.Half:
    76.                     downres = 1;
    77.                     break;
    78.                 case BloomDownscaleMode.Quarter:
    79.                     downres = 2;
    80.                     break;
    81.                 default:
    82.                     throw new System.ArgumentOutOfRangeException();
    83.             }
    84.             int tw = m_Descriptor.width >> downres;
    85.             int th = m_Descriptor.height >> downres;
    86.  
    87.             // Determine the iteration count
    88.             int maxSize = Mathf.Max(tw, th);
    89.             int iterations = Mathf.FloorToInt(Mathf.Log(maxSize, 2f) - 1);
    90.             int mipCount = Mathf.Clamp(iterations, 1, m_Bloom.maxIterations.value);
    91.  
    92.             // Pre-filtering parameters
    93.             float clamp = m_Bloom.clamp.value;
    94.             float threshold = Mathf.GammaToLinearSpace(m_Bloom.threshold.value);
    95.             float thresholdKnee = threshold * 0.5f; // Hardcoded soft knee
    96.  
    97.             // Material setup
    98.             float scatter = Mathf.Lerp(0.05f, 0.95f, m_Bloom.scatter.value);
    99.             var bloomMaterial = m_Materials.bloom;
    100.             bloomMaterial.SetVector(ShaderConstants._Params, new Vector4(scatter, clamp, threshold, thresholdKnee));
    101.             CoreUtils.SetKeyword(bloomMaterial, ShaderKeywordStrings.BloomHQ, m_Bloom.highQualityFiltering.value);
    102.             CoreUtils.SetKeyword(bloomMaterial, ShaderKeywordStrings.UseRGBM, m_UseRGBM);
    103.  
    104.             // Prefilter
    105.             var desc = GetCompatibleDescriptor(tw, th, m_DefaultHDRFormat);
    106.             for (int i = 0; i < mipCount; i++)
    107.             {
    108.                 RenderingUtils.ReAllocateIfNeeded(ref m_BloomMipUp[i], desc, FilterMode.Bilinear, TextureWrapMode.Clamp, name: m_BloomMipUp[i].name);
    109.                 RenderingUtils.ReAllocateIfNeeded(ref m_BloomMipDown[i], desc, FilterMode.Bilinear, TextureWrapMode.Clamp, name: m_BloomMipDown[i].name);
    110.                 desc.width = Mathf.Max(1, desc.width >> 1);
    111.                 desc.height = Mathf.Max(1, desc.height >> 1);
    112.             }
    113.  
    114.             Blitter.BlitCameraTexture(cmd, source, m_BloomMipDown[0], RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, bloomMaterial, 0);
    115.         }
    116. }
    117.  
    And the error: Assets\CustomPostProcessPass.cs(15,13): error CS0246: The type or namespace name 'GraphicsFormat' could not be found (are you missing a using directive or an assembly reference?)
     
  2. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    788
    Hi have you tried adding the namespace
    using UnityEngine.Experimental.Rendering;
    ?
     
  3. feeonyt

    feeonyt

    Joined:
    Nov 16, 2022
    Posts:
    2
    I tried it before, but the same thing as putting it behind it happened. I got multiple errors.
     
  4. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    788
    I don't see there's
    ShaderConstants
    in your code and the tutorial. Maybe you can remove it?

    The
    m_Descriptor
    defined in
    OnCameraSetup()
    is a local variable, so you cannot access it in another function.

    The
    SetTarget()
    is never called and
    m_CameraColorTarget
    &
    m_CameraDepthTarget
    is not defined anywhere.

    I think you can watch the video again and check if the code is the same.