As far as I am aware semi-transparent objects can not receive shadows, but alpha tested objects can.
So I tried to adapt the default sprite diffuse shader to include the necessary changes:
renderer.receiveShadows is set to true.
The shader looks as following:
Shader "Sprites/Normal"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader
{
Tags
{
"Queue"="Geometry+1"
"IgnoreProjector"="True"
"RenderType"="TransparentCutout"
"PreviewType"="Plane"
}
Cull Off
Lighting On
ZWrite On
Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma target 2.0
#pragma surface surf SimpleLambert alphatest:_Cutoff addshadow vertex:vert
#pragma multi_compile DUMMY PIXELSNAP_ON
sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
fixed4 color;
};
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;
}
void vert (inout appdata_full v, out Input o)
{
#if defined(PIXELSNAP_ON) !defined(SHADER_API_FLASH)
v.vertex = UnityPixelSnap (v.vertex);
#endif
v.normal = float3(0,0,-1);
v.tangent = float4(1, 0, 0, -1);
UNITY_INITIALIZE_OUTPUT(Input, o);
o.color = _Color;
}
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
o.Albedo = c.rgb;
o.Alpha = c.a;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
Fallback "Transparent/Cutout/VertexLit"
}
As far as I am aware all the necessities are there:
The sprite is rendered after the geometry pass and the surface shader uses alphatesting and specifies addshadow.
My current assumption is that it has to do with the custom vertex shader, because it is the only major difference to the original cutout shader?
Let me know if you need further informations let me know!
Thanking you in anticipation,
Nik / trevex