- Home /
2D Sprite shadow artifact when using Spotlight
Hey guys,
I am doing a experiment where my sprites are layout in 3D space and I am applying a shader to force them to cast and receive shadows. This works great when I am only using a Directional Light, but as soon as I have a Spot Light, all the sprites get weird artifacts, black lines (shadows are still casted normally). This is a side by side comparison between Directional and Spot Light (Closed-up look below):

Does anyone experience this before, or know why this is happening? I know that if I use a Quad instead of the Sprite everything works fine, but I really wanted to keep using Sprites since I can use my spritesheet animations (not quite sure if I can do that in a regular MeshRenderer).
This is the shader I am currently using in my Sprites (provided by @anlev):
 Shader "Sprite/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"
 }
Your answer
 
 
             Follow this Question
Related Questions
2D sprite shadows onto 3D objects 0 Answers
Platform Grills Scroll Animation - 2D Game 0 Answers
How do I have a 2D sprite fade in and out? (C#) 1 Answer
Unable to drag image from Assets folder to Sprite: None under Sprite Renderer. 0 Answers
Why does rotating sprites work well in Unity editor but not so much in other programs? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                