Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Trying to figure out Depth Priming

Discussion in 'Universal Render Pipeline' started by cthuludanyan, Feb 29, 2024.

  1. cthuludanyan

    cthuludanyan

    Joined:
    Feb 29, 2024
    Posts:
    1
    I'm trying to improve shader performance in Unity by enabling Depth Priming. This is for alpha cutout shaders with high overdraw.
    Some info:
    • Unity 2022.3.2f1
    • URP
    • Rendering Path: Forward
    • Depth Priming Mode: Auto
    • Depth Texture Mode: After Opaques
    • Shader is written in HLSL
    From searches on the internet/forums, it seems like a depth pass is required, but I haven't been able to figure out the implementation specifics/requirements of a depth pass. Would appreciate examples(or pointers). I've tried repurposing the code for DepthOnlyPass from Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl. However, the meshes go invisible. I'm not sure what the incorrect parts are, or what code the shader is lacking.
    I've uploaded a basic alpha cutout shader that I'm currently testing.
     

    Attached Files:

    Last edited: Feb 29, 2024
  2. Arithmetica

    Arithmetica

    Joined:
    Feb 11, 2019
    Posts:
    44
    You need to tell Unity that the pass is for Depth writing, so set LightMode to DepthOnly.
    Code (CSharp):
    1.             Tags
    2.             {
    3.                 "LightMode" = "DepthOnly"
    4.             }
    I recommend copying the DepthOnly pass from Unlit.shader as is.
     
  3. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    787
    Hi, Depth Priming is also called Depth Pre-pass, it improves performance on the GPU side by moving the cost of overdraw from complex lighting passes to simple DepthOnly passes.

    When enabled:
    • URP renders the DepthOnly pass of all opaque objects to the camera's depth target
    • render the lighting pass of all opaque objects with ZWrite Off, ZTest Equal (only pixels with the same depth as in the depth target can pass the z-test)
    So you need to make sure that the depth written by DepthOnly pass matches your lighting pass, or (parts of) the object will be invisible.
     
    tw00275 likes this.