Sprite Diffuse without shadows

hi,

I’ve used Sprite Default but it’s not reacting to fog and ambiant etc… so I’ve used Sprite Diffuse but…

I’d like the sprite not to get darker when not directly facing the light source.

So I’d like a shader that reacts to ambient light etc… and fog but not getting darker if not facing a light source.

I was planning to modify the standard unity shaders but I have no experience in doing this so if anyone has a tip / idea that would be welcome.

Thanks,

I guess the easiest way to get there is to download the Unity built-in shaders, copy “DefaultResourcesExtra/Sprites-Diffuse.shader” to your project and implement a custom lighting model.

The surface shader examples page features a Diffuse shader example that you can use as foundation. Take a look at the 2nd Diffuse example, it shows how to implement the custom lighting model. Notice the LightingSimpleLambert function, which you want to copy to your shader.

#pragma surface surf SimpleLambert

half4 LightingSimpleLambert (SurfaceOutput s, half3 lightDir, half atten) {
  half NdotL = dot (s.Normal, lightDir);
  half4 c;
  c.rgb = s.Albedo * _LightColor0.rgb * (NdotL * atten * 2);
  c.a = s.Alpha;
  return c;
}

The following line in the example makes that the surfaces’ illumination depend on the angle between the surface normal direction and light direction:

half NdotL = dot (s.Normal, lightDir);

Click here for a dot-product refresher.

If you want to remove that behavior and illuminate the surface with full intensity always, you can get rid of the NdotL term and use 1 instead:

half NdotL = 1;

This is equal to when the surface normal and light direction are parallel and point into opposite directions.

There might be other approaches how to achieve this effect, but I believe, even though it’s a bit of a text here, the modifications to get the custom lighting model in are not too difficult.

Hope it helps!

PS:
I’m not sure if the following line in the example is correct when using Unity 5:

c.rgb = s.Albedo * _LightColor0.rgb * (NdotL * atten * 2);

I think in Unity 5, you do not multiply by 2. If your sprite is too bright, change that line to:

c.rgb = s.Albedo * _LightColor0.rgb * (NdotL * atten);

thanks Peter77 for this nice start of solution.

so far, as I understood you, I’ve made this shader :

Shader "apelab/Sprites/Diffuse"
{
    Properties
    {
        [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
        _Color ("Tint", Color) = (1,1,1,1)
        [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    }

    SubShader
    {
        Tags
        {
            "Queue"="Transparent"
            "IgnoreProjector"="True"
            "RenderType"="Transparent"
            "PreviewType"="Plane"
            "CanUseSpriteAtlas"="True"
        }

        Cull Off
        Lighting Off
        ZWrite Off
        Blend One OneMinusSrcAlpha

        CGPROGRAM
        #pragma surface surf SimpleLambert vertex:vert nofog keepalpha
        #pragma multi_compile _ PIXELSNAP_ON

        sampler2D _MainTex;
        fixed4 _Color;

        struct Input
        {
            float2 uv_MainTex;
            fixed4 color;
        };
    
        void vert (inout appdata_full v, out Input o)
        {
            #if defined(PIXELSNAP_ON)
            v.vertex = UnityPixelSnap (v.vertex);
            #endif
        
            UNITY_INITIALIZE_OUTPUT(Input, o);
            o.color = v.color * _Color;
        }


        half4 LightingSimpleLambert (SurfaceOutput s, half3 lightDir, half atten) {
            half4 c;
            c.rgb = s.Albedo * _LightColor0.rgb * atten;
            c.a = s.Alpha;
            return c;
        }
    
        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
            o.Albedo = c.rgb * c.a;
            o.Alpha = c.a;
        }
        ENDCG
    }

Fallback "Transparent/VertexLit"
}

but the sprite now turns very bright when standing straight and normal when facing down.

I’ve tried to remove the attenuation or to multiply it by .5 but there’s always a variation of light intensity when I rotate the sprite that I want to get rid of.