Unity Shader
Undocumented rules https://medium.com/@jasonbooth_86226/loose-ends-in-unity-shaders-df5e98bdcc3
URP
Depth https://www.cyanilux.com/tutorials/depth/ https://forum.unity.com/threads/need-clarification-on-urps-use-of-the-depth-prepass.1004577/
Between rendering opaque and transparent objects, URP copies the depth buffer and store it to the depth texture. Transparent objects don’t write to it, because writing happened before the transparent rendering. Whenever URP can not copy depth, it uses Depth Prepass. It uses DepthOnly pass in the shader to write the depth.
The following situation cannot copy the depth:
- URP Asset enabled MSAA
- Hardware doesn’t support copying or the RT format
- URP resolves depth with MSAA and keeps precision (future update)
- Scene Camera or Preview Camera
- Rendering to XR
In the scene view, any shader that has not DepthOnly pass will not write depth.
Please note that URP12 separated Depth Prepass as a feature to reduce overdraw.