Could we get depth priming for more layers

I want to rely on the depth prepass for our renderer, as that makes some custom passes a lot easier to write:

But, those custom passes draw some layers that are not included in the opaque layer mask. Here’s the mask:

And here’s the passes:

And the depth prepass is defined like this in the UniversalRenderer in Core RP:

m_DepthPrepass = new DepthOnlyPass(RenderPassEvent.BeforeRenderingPrePasses, RenderQueueRange.opaque, data.opaqueLayerMask);
m_DepthNormalPrepass = new DepthNormalOnlyPass(RenderPassEvent.BeforeRenderingPrePasses, RenderQueueRange.opaque, data.opaqueLayerMask);

Ie. the opaque layer mask is included. This means that I don’t get depth for my layers, which again means that I have to do a bunch of extra work to get them to write to the depth.

I’d really love to be able to just override the layers that are used for the depth prepass - especially if I’m forcing the depth priming mode. If I modify the Core RP package like this:

m_DepthPrepass = new DepthOnlyPass(RenderPassEvent.BeforeRenderingPrePasses, RenderQueueRange.opaque, -1);
m_DepthNormalPrepass = new DepthNormalOnlyPass(RenderPassEvent.BeforeRenderingPrePasses, RenderQueueRange.opaque, -1);

I get the depth that I need. I could fork Core RP, but that is always a bit of a headache.

Hey @Baste, we are currently exploring the option of a new Prepass Layer Mask where you could select through the renderer asset inspector the layers that you want to render in your depth/depthNormal prepass. It would sit below existing Opaque and Transparent Layer Mask options.

In your case, it would mean that you have to select Background-Render and Foreground-Render layers in the Prepass Layer Mask in addition to the layers that are also selected in Opaque.

Doing so, during the render loop you would have:

  1. Depth prepass renders the depth buffer taking into account the opaque layers AND Background-Render + Foreground-Render layers.
  2. Opaque pass renders the opaque layers.
  3. Draw Background Layers renders Background-Render layer.
  4. Draw Foreground Layers renders Foreground-Render layer.

How does it sounds? Happy to get any feedback!

Hi! That sounds good - in fact I pretty much ended up doing exactly the same thing in our URP fork. it worked pretty well, although I ended up having to ditch the solution due to other problems that arose. But it would for sure be useful in the future!

Related, it would also be nice if the DepthOnlyPass was made useable as-is. I ended up having to copy-paste it if I wanted my own depth only pass, because the Render function is internal, but otherwise it’s perfectly good to use if we want a different depth for a different problem.

You mean being able to call the DepthOnly prepass in your scripts directly?

Yes! There’s probably a way to wrangle the API to do a depth pass without that, but that’s a bit daunting. Having a class that does the correct thing :trade_mark: in order to do a depth pass (like AddBlitPass does the correct thing for a normal blit) would be a great utility.

Changelog

[17.2.0] - 2025-05-14

Added Prepass Layer Mask to determine which GameObjects write depth.

Says Prepass Layer Mask is there and avalible and shows a screenshot.

I have 17.3.0 6.3. Here is my screenshot:

I have a trouble, where i have 2 absolutely identical cameras. Both do DepthNormals, but one does render Depth and another does not. I’ve spent a week trying to understand what is going on. Can you please help me?

Hey @Lynxed,

I’m not sure what’s going on here. The prepass layer mask should have landed in 6000.2.0b2. I can see it in my current dev version of Unity. Could you try with latest 6000.5?