Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SetGlobalBuffer causing artifacts in scene/game view when binding a view dependent buffer

Discussion in 'Shaders' started by davehun, Jul 21, 2017.

  1. davehun

    davehun

    Joined:
    Jun 27, 2017
    Posts:
    6
    Hi,

    I'm currently working on cascade shadow maps in ScriptableRenderLoop and I'm running into a problem where only one view is rendering correctly. I did some investigation using RenderDoc and found that both views have the same cascade information which was weird since they have different camera views.

    I'm currently using CommandBuffer.SetGlobalBuffer to bind the cascade information for my directional lights. I have feeling Unity is referencing a global resource map when executing command buffers on the render thread which means it only uses the most up to date ones. So I'm basically overwriting my view dependent SetGlobalBuffer calls for any previous views.

    I was wondering if there is a workaround for this or if this is a known bug/limitation in Unity?

    I did a simple experiment with SetGlobalVector and I ran into the same problem.:
    Code (CSharp):
    1. // SceneView = Red, GameView = Green
    2. var cmd = new CommandBuffer();
    3.  
    4. if (camera.cameraType == CameraType.SceneView)
    5. {
    6.     cmd.SetGlobalVector("_DebugColor", new Vector4(1.0f, 0.0f, 0.0f, 1.0f));  
    7. }
    8. else if (camera.cameraType == CameraType.Game)
    9. {
    10.     cmd.SetGlobalVector("_DebugColor", new Vector4(0.0f, 1.0f, 0.0f, 1.0f));
    11. }
    12.  
    13. context.ExecuteCommandBuffer(cmd);              
    14. cmd.Dispose();
    15.  
    16. var settings = new DrawRendererSettings(cull, camera, new ShaderPassName("ForwardBase"))
    17. {
    18.     rendererConfiguration = RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe,
    19.     sorting = { flags = SortFlags.CommonOpaque }
    20. };
    21.  
    22. settings.inputFilter.SetQueuesOpaque();
    23. context.DrawRenderers(ref settings);
    Thanks.
     
  2. davehun

    davehun

    Joined:
    Jun 27, 2017
    Posts:
    6
    Quick update.

    I figured out what was wrong. RenderDoc wasn't capture the correct render view. I closed the game view and I was able to get a correct capture of the scene view.