Search Unity

Feeding depth into the next pass (camera stack or 'render objects'-feature)

Discussion in 'Universal Render Pipeline' started by Waarten, Feb 22, 2021.

  1. Waarten

    Waarten

    Joined:
    Aug 24, 2018
    Posts:
    38
    I have a (non-standard, mesh based) terrain and several sprite renderers. Think: trees on a curved plane. I'm trying to render these in two distinct steps: first the terrain (which writes depth), and then the sprites.

    I'm using shader graph to make a custom shader for my 2D sprites. For these sprites, I want to sample the scene depth as it was in step 1 (terrain).

    My assumption is: if the terrain and the sprites are seperated into different passes, then the 'Scene Depth' node in shader graph will point towards the last depth buffer. But this seems not the case.
    scene_graph_node.png
    Image A: The shadergraph node I would like to use

    I've tried two approaches:

    Approach 1: Camera stack
    I have a base camera (rendering some background stuff and effects) and two overlay cameras.
    • One overlay camera for the terrain, rendering simple vertex colored geometry
    • Another overlay camera for the sprites, rendering with my custom shader graph shader
    Interestingly, I seem to be able to sample depth rendered by the base camera, even if it was overdrawn by something from an overlay camera after that.

    renderdoc_depth.png
    Image B: Renderdoc tells me that depth _is_ being written by the terrain.

    Approach 2: "Render objects" feature
    Through 'render objects' in a URP renderer, I add a custom pass that only renders the terrain, and I make sure this happens before the sprites are rendered. But this resulted to the same situation as approach 1.

    What I think is going wrong is that the 'Scene Depth' node is sampling some copy of the depth buffer that is not yet updated my terrain geometry. Am I missing something simple? I'm willing to 'isolate' my 'passes' more to make this work, but at the same time I'm hoping to find a solution for this that uses URP in it's intended way.

    Does anyone have an idea?

    Thanks a lot,

    UPDATE 1:
    The docs at https://docs.unity3d.com/Packages/c...s.universal@10.3/manual/cameras-advanced.html explicitly mention that "At the start of its render loop, an Overlay Camera receives a depth buffer containing depth data from the previous Cameras in the Camera Stack." This is probably the case, but the 'Scene Depth' node still uses depth from only the base camera.
     
    Last edited: Feb 22, 2021
    ManuelKers likes this.
  2. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    68
    Yes I just spent the past two days trying to figure this out as well. Looks like camera stacking / overlay cameras don't work with the URP decal shader [ https://github.com/ColinLeung-NiloCat/UnityURPUnlitScreenSpaceDecalShader ] and mesh intersection shaders [
    ].

    Like you mentioned, I'm guessing it's because the 'Scene Depth' is probably using the depth information from the base camera and not the overlay camera(s).

    Very frustrating...
     
  3. Miltan_

    Miltan_

    Joined:
    Sep 7, 2013
    Posts:
    7
    I'm having the same issue.
    One render object for walls one renders object for the floor.
    Intersection shader at a third object can't intersect both wall and floor.
    The depth pass is split and not combined somehow.
    Is there a click to marge depth or pass to the next layer... idk
    Check screenshots.
    One is all on the same layer, other are on different layers.
    Help is welcome :)
     

    Attached Files:

  4. Miltan_

    Miltan_

    Joined:
    Sep 7, 2013
    Posts:
    7
    Anti Aliasing (MSAAA) << Also disabling this in Render Settings affects the depth outcome on the intersection shader depth scene node.