Search Unity

Broken rendering order in Unity 5

Discussion in 'General Graphics' started by Ferb, Mar 13, 2015.

  1. Ferb

    Ferb

    Joined:
    Jan 4, 2014
    Posts:
    25
    In my game I use a lot of meshes with sorting orders and sorting layers set in code, which worked perfectly in Unity 4.3 through 4.6. (The shaders had to have ZWrite set to off, but other than that, no problem.) It's made it easy to make my 2D game with things like sprite distortion and lighting while still using a 2D layering system. But since upgrading to Unity 5, this system has been broken. Things are still in the right order sometimes, sometimes they aren't, I can't figure out any pattern as to when they are or not. I'm getting around it by switching Z-Write back on in my shaders and setting the z-position of sprites according to what order they were meant to be in, but why is this now necessary? Even setting the rendering queue tag in my shaders doesn't seem to affect what order my meshes are drawn in, I have things with "Queue"="Background" in the shader sometimes being drawn over things with the tag "Queue"="Transparent". Has anybody else noticed Unity 5 breaking the draw-ordering mechanism? Does the draw-ordering mechanism even exist anymore, or are meshes just drawn in the order their gameobjects are created or something?
     
  2. Trigve

    Trigve

    Joined:
    Mar 17, 2013
    Posts:
    139
    I'm experiencing the same problem.

    I would really like to know the priority between render queue and sorting layers.

    It looks like that sorting layer has always the biggest priority. Then order in layer if the object are in the same sorting layer. But what about if objects have same sorting layer and same order in layer? Changing the render queue in shader does nothing. Also Frame debugger confirm this behavior. I'm using Unity 5.2.2p2

    Could someone shed some light on this?

    Thank You
     
  3. WillFei

    WillFei

    Joined:
    Jul 28, 2015
    Posts:
    7
    I have struggled on this problems for some time. Then I found it is a bug in the Unity5( I'm not sure it's fixed in the latest version or not). It seems Unity doesn't update the material's rendering queue after you change the queue in your shader. so the engine still takes the old queue tag from the material. To make sure, you can make the assets as text format and open it to check the queue tag. So you could modify it as the same tag as in your shader for a workaround.
     
  4. Trigve

    Trigve

    Joined:
    Mar 17, 2013
    Posts:
    139
    Thanks for the reply,
    that's interesting and you're right that render queue isn't updated in the material. I've just checked the material file.

    The bug has been filled already http://issuetracker.unity3d.com/iss...-updated-until-shader-is-changed-and-reverted .

    The workaround:
    edit: I have also submitted the bug with the test case, 754960.
     
    Last edited: Dec 17, 2015
    Nonakesh likes this.
  5. jistyles

    jistyles

    Joined:
    Nov 6, 2013
    Posts:
    34
    So I've done a triage pass and found where this bug is coming from.

    It's caused by the Standard Shader material interface which you can find the source in the built-in shader package under \Editor\StandardShaderGUI.cs

    The Standard Shader supports a variety of "render modes". These change things like blend op's, zwrite, set keywords, etc... but it also explicitly sets the Material.renderQueue
    If you ever have a material reference the Standard Shader, then it will stomp the -1 default with whatever is relevent for its "Render Mode", but it won't clean itself up if you then change the shader to something else.