How to Get the depth Texture for each camera on HDRP or URP

Thanks for taking a look. This is my first post.

Is there a way to write out the per-camera depth to a Render Texture in HDRP or URP ?

If it was a legacy pipeline, I would have written out the _CameraDepthTexture to the render target like this from a #C script through a shader.

{
Graphics.Blit(source, dest, _material);
}

Alternatively,I could use a CommundBuffer to write out the texture at the appropriate stage.

However, for HDRP or URP, I think there is a no way to get the depth for each camera, because of the graphics pipeline specification.

I imagine this is because the way to get the DepthBuffer depends on the post-effects, so we can only get the DepthBuffer of the final rendered result.

I’ve been investigating for about a week and have come to this conclusion.

However, if there is some other way, please let me know.

Thanks!

Did you ever find a solution for this?

You can write a custom pass. The depth buffer is available in the AfterOpaqueDepthAndNormal injection point, for example.

https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@15.0/manual/Custom-Pass-Injection-Points.html

Thanks! Does this work in URP 12.1 the same way? I know they have changed a lot since then.

I don’t know, sorry.