Legacy Deferred bug.

Hey,
I’m having issues with a simple shader that used to work fine.
I want to blend 2 colors / textures depending on the viewDir.

If I output it in the Albedo it does not work.
If I output it in the emission it works.
Works with new deferred.
Works with forward.
Problem occurs only with legacy Deferred

code:

Shader "Custom/RimBug"
{
    Properties
    {
        _Color1("Color1", Color) = (1,1,1,1)
        _Color2("Color2", Color) = (1,1,1,1)
        _BlendPower("Blend", Range(0,10)) = 0.5

    }
    SubShader
    {
        Tags {"Queue" = "Geometry" "RenderType"="Opaque"}

        CGPROGRAM
        #pragma surface surf Lambert
        #pragma target 3.0
     
        fixed4 _Color1;
        fixed4 _Color2;
        float _BlendPower;  
     
        struct Input
        {
            float3 viewDir;
        };
     
        void surf(Input IN, inout SurfaceOutput o)
        {
            half rim = saturate(dot (Unity_SafeNormalize(IN.viewDir), o.Normal));
            half mask = pow(rim,_BlendPower);
         
            o.Albedo = lerp(_Color1,_Color2,mask);
        }
        ENDCG
    }
    Fallback "Diffuse"
}

Anyone has a clue on what’s going on?

Thanks!

Here’s a visual example of the problem:

Unfortunately in Legacy Deferred the normal is 0 in the surface shader.
A better way to use a normal to achieve this effect is to use the built in vector worldNormal:

  • add float3 worldNormal; to your Input structure;
  • instead of o.Normal use IN.worldNormal;

I see, so I guess having a texture in o.Normal would also fix the issue. Thanks! :slight_smile: