I am new to Unity; just picked it up this week; so please bear with me.
I have been playing around with this all day and I still can’t seem to get a Sprite to RECEIVE a shadow. I figured the best way to approach this would be to go step by step on what I did to get to where I am then hopefully you guys can tell me what I missed.
- I created a new scene in 2D mode.
- I added a Sprite “character”, Sprite “wall”, 3D cube and a Spotlight into the scene then positioned them in a way that could test shadows:
- I created my custom Shader, applied it to a custom Material then added that Material to both of my Sprite elements, Then using the Inspectors Debug mode I enabled both Receive and Cast Shadows for both Sprite Elements.
Custom Shader:
Shader "Sprites/Diffuse/Shadows"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.5
}
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 Lambert vertex:vert nofog keepalpha addshadow
#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;
}
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/Cutout/VertexLit"
}
As you can see the Sprite “character” cast a shadow, the 3D Cube receives it but the Sprite “wall” does not. Any idea as to why?