Search Unity

Unity 5.4 - Sprite Shadow

Discussion in '2D' started by IgorUnity3D, Sep 24, 2016.

  1. IgorUnity3D

    IgorUnity3D

    Joined:
    Aug 28, 2014
    Posts:
    66
    Hello guys,

    I am trying apply shadow do my sprites on the following shader, but unsuccessfully!:(



    I am using the Shader "Sprites/Bumped Diffuse with Shadows"

    Code (CSharp):
    1. Shader "Sprites/Bumped Diffuse with Shadows"
    2. {
    3.     Properties
    4.     {
    5.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    6.         _BumpMap ("Normalmap", 2D) = "bump" {}
    7.         _Color ("Tint", Color) = (1,1,1,1)
    8.         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    9.                 _Cutoff ("Alpha Cutoff", Range (0,1)) = 0.5
    10.  
    11.     }
    12.  
    13.     SubShader
    14.     {
    15.         Tags
    16.         {
    17.             "Queue"="AlphaTest"
    18.             "IgnoreProjector"="True"
    19.             "RenderType"="TransparentCutOut"
    20.             "PreviewType"="Plane"
    21.             "CanUseSpriteAtlas"="True"
    22.        
    23.         }
    24.             LOD 300
    25.  
    26.  
    27.         Cull Off
    28.         Lighting On
    29.         ZWrite On
    30.         Fog { Mode Off }
    31.    
    32.  
    33.         CGPROGRAM
    34.         #pragma surface surf Lambert alpha vertex:vert  alphatest:_Cutoff fullforwardshadows
    35.         #pragma multi_compile DUMMY PIXELSNAP_ON
    36.  
    37.         sampler2D _MainTex;
    38.         sampler2D _BumpMap;
    39.         fixed4 _Color;
    40.  
    41.         struct Input
    42.         {
    43.             float2 uv_MainTex;
    44.             float2 uv_BumpMap;
    45.             fixed4 color;
    46.         };
    47.    
    48.         void vert (inout appdata_full v, out Input o)
    49.         {
    50.             #if defined(PIXELSNAP_ON) && !defined(SHADER_API_FLASH)
    51.             v.vertex = UnityPixelSnap (v.vertex);
    52.             #endif
    53.             v.normal = float3(0,0,-1);
    54.             v.tangent =  float4(1, 0, 0, 1);
    55.        
    56.             UNITY_INITIALIZE_OUTPUT(Input, o);
    57.             o.color = _Color;
    58.         }
    59.  
    60.         void surf (Input IN, inout SurfaceOutput o)
    61.         {
    62.             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
    63.             o.Albedo = c.rgb;
    64.             o.Alpha = c.a;
    65.             o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    66.         }
    67.         ENDCG
    68.     }
    69.  
    70. Fallback "Transparent/Cutout/Diffuse"
    71. }
    72.  
    What am I doing wrong? Does this still work in older versions of Unity?

    Could someone please help me?