Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Scene fade in/out script error in 4.5

Discussion in 'Editor & General Support' started by SimonDarksideJ, Jun 4, 2014.

  1. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    I have a scene fade in / out script that I've used since 4.0 and has been working fine. But since 4.5 it has stopped working.

    If simply draws a quad over the scene which gradually fades:
    public static void DrawQuad(Material aMaterial, Color aColor, float aAlpha)
    {
    aColor.a = aAlpha;
    aMaterial.SetPass(0);
    GL.Color(aColor);
    GL.PushMatrix();
    GL.LoadOrtho();
    GL.Begin(GL.QUADS);
    GL.Vertex3(0, 0, -1);
    GL.Vertex3(0, 1, -1);
    GL.Vertex3(1, 1, -1);
    GL.Vertex3(1, 0, -1);
    GL.End();
    GL.PopMatrix();
    }

    With a simple custom material :
    fadeMaterial = new Material("Shader \"Plane/No zTest\" {" +
    "SubShader { Pass { " +
    " Blend SrcAlpha OneMinusSrcAlpha " +
    " ZWrite Off Cull Off Fog { Mode Off } " +
    " BindChannels {" +
    " Bind \"color\", color }" +
    "} } }");

    No idea why but since the 4.5 upgrade this script no longer fades, just drops to black for the entire length of the transition.

    Script can be found here : http://bit.ly/1kCkJ8L
     
  2. duck

    duck

    Unity Technologies

    Joined:
    Oct 21, 2008
    Posts:
    358
    Had a quick look at this. Looks dx11 related, since turning off dx11 in the player settings fixes the issue. I've dropped a note to our graphics team to see if they have any further info and I'll let you know what they come back with.
     
  3. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    I think what happens, is that calling things like GL.Color outside of GL.Begin/End is technically "undefined". It happens to work on some platforms, but does not work on others (e.g. DX11).
     
  4. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Just as well the docs say this, then. ;-)

    This function can only be called between GL.Begin and GL.End functions.
     
    SimonDarksideJ likes this.
  5. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    Ok, I'll try updating the shader portion of the code to move those segments within the begin and end block. Thanks.

    Just odd that this was working perfectly fine prior to 4.5
     
  6. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    That fixed it, thanks for all the help.

    Guess there must have been either a tweak workaround before 4.5 or as stated, the update to dx 11 made this invalid.

    Anyway working now, thanks again.
     
  7. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    And so begins the proverbial face slap moment :D RTFM.

    Although I'm still a noob to shaders, learning more each day.
     
  8. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    Hmm. Seems not all the docs agree. Since this is proven true, all the docs should state the same thing. Just fond this while checking the other functions the script uses
    http://docs.unity3d.com/ScriptReference/GL.PushMatrix.html
    And here
    http://docs.unity3d.com/ScriptReference/GL.LoadOrtho.html

    Has GL.Color before the GL.Begin

    #Facepalm