Search Unity

Question How to enable ZTest LEQual on transparent queue?

Discussion in 'Universal Render Pipeline' started by ClosingTime, Apr 18, 2023.

  1. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    241
    I would like to render a transparent queue that also does LEqual test.
    The Shader sets the ZTest to LEQual, howerver, the Transparent object draw command buffer, seem to override it to always.

    How can I render a transparent material in the transparent queue, that doesn't ignore the LEqual ZTest?
     
  2. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    766
    Hi, have you enabled ZWrite in the shader (or force depth write in shader graph)?
     
  3. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    241
    I tired, but it's not really related. I need ZTest not ZWrite

    Edit: Transparent renderer buffer is set to ZTest Always, so I am guessing it is overriding everything under it. I have no other explanation.
     
  4. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    766
    Are you doing custom transparent objects rendering in a renderer feature?

    If transparent objects are inside "DrawTransparentObjects" in URP Frame Debugger, you can achieve what you need by setting ZTest to LEqual in shader.
    ZTest.png

    If no (custom rendering), you can override the depth state of the whole pass with RenderStateBlock in your custom renderer feature.
     
  5. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    241
    The ZTest is ignored in the shader graph.
    Maybe I need to update Unity version.
     
  6. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    241
    As you can see, the transparent web completely ignores the ZTest.
     
  7. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    241
  8. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    766
    Have you checked the depth render target in Frame Debugger?

    If ZTest is set to LEqual there and you can see transparent objects in depth RT (when ZWrite On), then there should be nothing wrong with Unity. If not, yes you can try upgrading Unity.

    By the way, as the spider web is not a semi-transparent object. You can also use alpha clipping for 0/1 transparency. Alpha clipping objects are considered as opaque so you won't need to upgrade URP.
     
  9. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    241
    Ok, it worked after updating to 2022.
     
    wwWwwwW1 likes this.
  10. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    241