Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Basic Question: Render Queue and ZWrite

Discussion in 'Shaders' started by Blastom, May 6, 2016.

  1. Blastom

    Blastom

    Joined:
    Aug 13, 2013
    Posts:
    24
    I explain this with an example:
    I have Cube A at "RenderQueue" = "Transparent+100" and "Z Write On" with alpha blending
    and Cube B at "RenderQueue" = "Transparent" and further from the camera than A.

    The display will be like:
    Cube B will be "clipped" by Cube A, while I think the Cube B shall be rendered first and then "alpha blended" by Cube A.
    I tried to set the blending of the shader of cube A to "Zero One" and clearly saw Cube B is clipped by Cube A, which is transparent like a mask.

    So Z Write and Z Test will "bypass" the render queue or something? Can anyone explain this to help me on better understanding of the rendering order?
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,590
    There is an annoying bug in Unity that affects the RenderQueue tag:
    [Material] Render Queue value is not updated until shader is changed and reverted

    Basically, if you change the RenderQueue value in a shader, it won't have any effect until you do some material trickery to workaround this bug.

    I could imagine your issue is related to that, or at least give it a try. I stumbled across various really odd mask/clip/order issues caused by this bug.

    To test if it's related to this bug, switch the Inspector to Debug Mode. Then select your "Cube A" and "Cube B" materials and set their "Render Queue Order" property to -1. This will make sure it uses the RenderQueue from the shader, rather than the cached value in the material.

    Here is a related post that shows how to workaround the issue:
    http://forum.unity3d.com/threads/solved-render-order-trouble-opaque-vs-transparent.401034/
     
    a_p_u_r_o likes this.
  3. Blastom

    Blastom

    Joined:
    Aug 13, 2013
    Posts:
    24
    OH MY GOD...
    Yes, that what happened. Thanks a lot, I would start to question my whole understanding of queue order :) if I didn't see your reply.
     
    Peter77 likes this.