Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Help Wanted Strange issue with two CopyDepthPasses in one pipeline

Discussion in 'Universal Render Pipeline' started by Waarten, Apr 9, 2021.

  1. Waarten

    Waarten

    Joined:
    Aug 24, 2018
    Posts:
    25
    I'm having a strange issue with my scene depth. My URP pipeline looks like this:
    • render objects (a custom terrain mesh) [opaque, WRITES depth]
    • XXX
    • render objects (blob shadows, cube meshes intersecting the terrain) [transparent, SAMPLES depth]
    • render objects (trees and plants as sprites on quads) [opaque, WRITES depth]
    • XXX
    • render objects (a fog effect, as a plane above the terrain) [transparent, SAMPLES depth]
    Because this rendering happens in a stacked overlay camera, I need to manually copy over the depth before I can sample it. This happens at the "XXX" above, so twice.

    For copying the depth buffer to where ShaderGraph can sample it (the "Scene Depth" node) I'm using a custom ScriptableRenderFeature (posted below).

    The strange thing is, that when zooming (thus changing depth) the depth starts 'lagging' like in this GIF:

    scene_depth_issue.gif

    What's strange is that this is an effect over multiple frames. To me it looks like some value being relative instead of being absolute, stabilizing only over multiple frames. Or perhaps some other system interfering?

    The crux is, that this ONLY happens when I have TWO passes that copy depth. With either one of the depth copies disabled, things work as expected (yet, either the blob shadow or the fog has no depth info).

    I'm puzzled and hopefully someone can help me.

    This is my ScriptableRenderFeature:
    Code (CSharp):
    1. using UnityEngine.Rendering;
    2. using UnityEngine.Rendering.Universal;
    3. using UnityEngine.Rendering.Universal.Internal;
    4. public class CopyDepthRenderFeature : ScriptableRendererFeature
    5. {
    6.     CopyDepthPass _pass;
    7.     RenderTargetHandle _depthDestHandle;
    8.     RenderTargetHandle _depthSourceHandle;
    9.     public RenderPassEvent renderPassEvent;
    10.     public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    11.     {
    12.         _pass.Setup(_depthSourceHandle, _depthDestHandle);
    13.         renderer.EnqueuePass(_pass);
    14.     }
    15.     public override void Create()
    16.     {
    17.         if (_pass != null)
    18.         {
    19.             _pass = null;
    20.         }
    21.         if (_pass == null)
    22.         {
    23.             _pass = new CopyDepthPass(renderPassEvent, CoreUtils.CreateEngineMaterial("Hidden/Universal Render Pipeline/CopyDepth"));
    24.             _depthDestHandle = new RenderTargetHandle();
    25.             _depthSourceHandle = new RenderTargetHandle();
    26.             _depthSourceHandle.Init("_CameraDepthAttachment");
    27.             _depthDestHandle.Init("_CameraDepthTexture");
    28.         }
    29.     }
    30. }
     
  2. Waarten

    Waarten

    Joined:
    Aug 24, 2018
    Posts:
    25
    I'm using 2020.2.4 but I've verified that this also happens in 2020.3.3 LTS.
     
  3. Waarten

    Waarten

    Joined:
    Aug 24, 2018
    Posts:
    25
unityunity