Search Unity

Interpolating in RGB space from Unlit to Standard Shader

Discussion in 'Shaders' started by ferretnt, May 23, 2018.

  1. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    I'd like, for an effect, to perform a cross-fade between a completely unlit mesh and the Unity Standard shader.

    i.e. imagine

    float4 standardShaderColour = [evaluate the standard shader]
    float4 unlit = tex2d(maintex, texcoord);
    float4 output = lerp (standardShaderColour, unlit, blendFactor);

    My first thought was that it should be possible to do this within a Unity Standard surface shader by driving either the Albedo or emission terms (they summing to 1) and feeding mainTex to them. But it looks like this isn't sufficient, as the sky env map and other terms contribute additive lighting effects so that my "unlit" effect is still somewhat lit. I *think* this used to be possible in the old non-PBR model if you set specular to zero, thus turning the rest of the lighting calculation into a massive nop. (Actually, maybe that's still possible if I use the Standard (Specular Setup) shader, haven't tried yet.)

    Is there an easy way to tag such epilogue code onto the tail of a standard surface shader's fragment shader? Yes, I know this is totally not-PBR...

    Obviously, I could duplicate the entire Unity Standard Shader tree, and make myself a StandardNonStandardUnlitBlend by hacking the lerp onto the very end of the pixel shader in the various render paths that I use.
     
  2. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    Ooh, looks like you can use the finalcolor directive. Didn't know that... trying...
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    finalcolor is a good option. Another is to just render the object again with an alpha blend Unlit shader on top of the standard shader.
     
  4. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    Thanks, although in this case I already had a custom shader on the object so adding the finalcolour was less work than managing an extra material / pass.

    I'll keep the extra pass suggestion in my back pocket for the undoubtedly "interesting" Android video driver behaviour that will show up just before ship...