2D Sprite Shadow Shader - jagged edges

Hello,
i found great 2D sprite shadow shader here GitHub - anlev/Unity-2D-Sprite-cast-and-receive-shadows. Its working great but after spending some time testing it i noticed jagged edges on sprites where this shader is apply. On attached screenshot i marked sprite which had shadow shader applied. Other sprites use built-in sprite diffuse shader and they looks slightly better.
If some shader guru would provide idea how to smooth the edges for sprite shadow shader, probably whole 2D community will be grateful :slight_smile:
Thank you!

Shader "Custom/SpriteShadow" {
    Properties {
        _Color ("Color", Color) = (1,1,1,1)
        [PerRendererData]_MainTex ("Sprite Texture", 2D) = "white" {}
        _Cutoff("Shadow alpha cutoff", Range(0,1)) = 0.5
    }
    SubShader {
        Tags
        {
            "Queue"="Geometry"
            "RenderType"="TransparentCutout"
        }
        LOD 200

        Cull Off

        CGPROGRAM
        // Lambert lighting model, and enable shadows on all light types
        #pragma surface surf Lambert addshadow fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
        fixed4 _Color;
        fixed _Cutoff;

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutput o) {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            o.Alpha = c.a;
            clip(o.Alpha - _Cutoff);
        }
        ENDCG
    }
    FallBack "Diffuse"
}

Unity doesn’t support transparent objects receiving shadows, and to have a soft edge requires transparency. Thus the only general way to get sprites to receive shadows is with the hard, jagged edge (using alpha test) and then using a post processes anti-aliasing full screen camera image effect to smooth out the edges.

Hello mattdwnet,
did you solve the problem with this shader or found another solution?

Greetings
Pat

It’s more work, but you can stack two textures on top of each other, and apply shadows to the lower texture with a high alpha cutoff. Although, at that point you might as well just create your own shadow system by tinting the texture black, reducing the alpha level, and offsetting it to create your own shadow.