Search Unity

2D Sprite shadow artifact when using Spotlight

Discussion in '2D' started by adsk_marcopaivaf, Feb 24, 2017.

  1. adsk_marcopaivaf

    adsk_marcopaivaf

    Joined:
    Feb 5, 2015
    Posts:
    3
    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). Attached 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):

    Code (CSharp):
    1. Shader "Sprite/SpriteShadow" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.         [PerRendererData]_MainTex ("Sprite Texture", 2D) = "white" {}
    5.         _Cutoff("Shadow alpha cutoff", Range(0,1)) = 0.5
    6.     }
    7.     SubShader {
    8.         Tags
    9.         {
    10.             "Queue"="Geometry"
    11.             "RenderType"="TransparentCutout"
    12.         }
    13.         LOD 200
    14.  
    15.         Cull Off
    16.  
    17.         CGPROGRAM
    18.         // Lambert lighting model, and enable shadows on all light types
    19.         #pragma surface surf Lambert addshadow fullforwardshadows
    20.  
    21.         // Use shader model 3.0 target, to get nicer looking lighting
    22.         #pragma target 3.0
    23.  
    24.         sampler2D _MainTex;
    25.         fixed4 _Color;
    26.         fixed _Cutoff;
    27.  
    28.         struct Input
    29.         {
    30.             float2 uv_MainTex;
    31.         };
    32.  
    33.         void surf (Input IN, inout SurfaceOutput o) {
    34.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    35.             o.Albedo = c.rgb;
    36.             o.Alpha = c.a;
    37.             clip(o.Alpha - _Cutoff);
    38.         }
    39.         ENDCG
    40.     }
    41.     FallBack "Diffuse"
    42. }
     

    Attached Files: