Search Unity

[Solved] Render order trouble - Opaque vs Transparent

Discussion in 'Shaders' started by MSplitz-PsychoK, Apr 28, 2016.

  1. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    Hello, I'm getting really frustrated and would really appreciate some help.

    For stencilling reasons, I need a "hole" to render before the "floor". Problem is, my floor always renders first.

    My floor shader is a surface shader, while my hole shader is not a surface shader. I've tried every combination of setting Queue and RenderType Tags on each to Transparent, Opaque, and Transparent-10. I've tried every combination of enabling/disabling blending, zwrite, and ztest.

    The crazy part is that the frame debugger always shows that it renders my floor first as an opaque object and my hole next as a transparent object. Even when I change the queue/renderType of each shader, this fact is always the same.

    How in the hell do I make my hole shader render first??
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    Ok, I found a workaround. It seems surface shaders don't care for render queues and will completely ruin the order of rendering.

    To get the floor rendering before the holes, I had to give the floor the hole material then set that material back to the floor shader. Likewise, I gave the holes the floor material and switched the shader back to the hole shader.

    I'm a bit angry because that change should have done nothing, but it completely changed my render order. Surface shaders seem to do nothing but cause problems in all my Unity shader experience, but I can't live without them because lighting is a pain. UHHG.
     
  3. a_p_u_r_o

    a_p_u_r_o

    Joined:
    May 27, 2015
    Posts:
    23
    I had the very same problem the other day.
    Have a look inside the debug view of your material's inspector.
    If the value of "Custom Render Queue" is not -1, then the value specified in your shader is being overridden.
    CustomRenderQueueDebug.png
     
    MSplitz-PsychoK likes this.
  4. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    Perfect, you're right! I feel much better knowing why this happens now, I wish it wasn't so well hidden. They should add a note about this in the shader lab documentation where they talk about render queues.
     
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    MSplitz-PsychoK and a_p_u_r_o like this.
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Please vote on that issue so they pay more attention to it. It's a very frustrating bug for shader dev.
     
    a_p_u_r_o and MSplitz-PsychoK like this.