Search Unity

Shadow on a transparent object

Discussion in 'Shaders' started by yazZ6va, May 11, 2017.

  1. yazZ6va

    yazZ6va

    Joined:
    May 11, 2017
    Posts:
    5
    Hi
    Does anyone know if it's possible to get a shadow on a completely transparent object?
    Need to cast a shadow from the 3d character on the sidewalk



     
    Last edited: May 11, 2017
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
  3. yazZ6va

    yazZ6va

    Joined:
    May 11, 2017
    Posts:
    5
    Last edited: May 19, 2017
  4. yazZ6va

    yazZ6va

    Joined:
    May 11, 2017
    Posts:
    5
  5. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    This one works for me:

    Code (CSharp):
    1. Shader "Shadow Collector" {
    2.     Properties
    3.     {
    4.         _Color("Main Color", Color) = (1,1,1,.5)
    5.         _ShadowIntensity("Shadow Intensity", Range(0, 1)) = 0.6
    6.     }
    7.     SubShader
    8.     {
    9.         Tags{ "Queue" = "AlphaTest" }
    10.    
    11.         Pass
    12.         {
    13.             Tags{ "LightMode" = "ForwardBase" }
    14.             Cull Back
    15.             Blend SrcAlpha OneMinusSrcAlpha
    16.             CGPROGRAM
    17.             #pragma vertex vert
    18.             #pragma fragment frag
    19.             #pragma multi_compile_fwdbase
    20.             #include "UnityCG.cginc"
    21.             #include "AutoLight.cginc"
    22.             uniform fixed4  _Color;
    23.             uniform float _ShadowIntensity;
    24.             struct v2f
    25.             {
    26.                 float4 pos : SV_POSITION;
    27.                 LIGHTING_COORDS(1,2)
    28.             };
    29.             v2f vert(appdata_base v)
    30.             {
    31.                 v2f o;
    32.                 o.pos = UnityObjectToClipPos(v.vertex);
    33.                 TRANSFER_VERTEX_TO_FRAGMENT(o);
    34.                 return o;
    35.             }
    36.  
    37.             fixed4 frag(v2f i) : COLOR
    38.             {
    39.                 float attenuation = LIGHT_ATTENUATION(i);
    40.                 return fixed4(0,0,0,(1 - attenuation)*_ShadowIntensity) * _Color;
    41.             }
    42.            
    43.             ENDCG
    44.         }
    45.     }
    46.    
    47.     Fallback "VertexLit"
    48. }