hi guys, i have a problem with shadows receiving on sprite well i have some cute shadow-cast shader: Code (CSharp): 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; } fixed _Cutoff; void surf(Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color; o.Albedo = c.rgb; o.Alpha = c.a; clip(o.Alpha - _Cutoff); } ENDCG } Fallback "Transparent/Cutout/VertexLit" } this shader allows my sprites to cast some shadows but they cant be received by them. how can i add the possibility of receiving shadows in this shader? spriteRenderer.receiveShadows is ON spriteRenderer.castShadows is ON too. P.S. yes, i know that meshRenderer could receive any shadow, but i need to attach this possibility to sprites. please help!)
if you are using desktop then this shader is built into unity? see standard shader drop down for blend modes like Transparent, Fade, Cutout...
Anything with a transparency queue will not receive shadows. Try "Queue"="AlphaTest" "RenderType"="TransparentCutout" ZWrite On and remove the blend line.
i tried now, it does not work :X here is some explanation about my problem: bg is mesh with standart shader, it receive shadows easily if sprite's shadow comes on other sprite, it isnt receiving by it i turned off bg "receiveShadows": which part of standart(specular) shader allows it to receive shadows? must i mix it with my shader or something?
You might try adding fullforwardshadows to the #pragma surface line, along with replacing keepalpha with alphatest:_Cutoff
OK, i found the solution if someone needed, you can get it from my github: https://github.com/anlev/Unity-2D-Sprite-cast-and-receive-shadows
Hi @anlev, Could you please show me how to use your shader in version 5.4 of Unity? You have a sample project? I'm having trouble playing shadows on my sprite object Please!