Search Unity

How to cast shadows on transparent object

Discussion in 'General Graphics' started by JoseEDC, Sep 29, 2017.

  1. JoseEDC

    JoseEDC

    Joined:
    May 15, 2017
    Posts:
    8
    Hi there.

    I'm currently trying to cast a shadow into a transparent object but it just doesn't work. I've found some discussions about this in the forum and I read there that Unity simply doesn't support this but they are from years ago and someone wrote that at some point after Unity 5 the team will work on this feature so... is there any way to cast shadows on transparent objects now? or any workaround?

    Thanks!
     
  2. Elandir

    Elandir

    Joined:
    Feb 9, 2014
    Posts:
    32
    There is a shader in the Wikitude package for doing just that:

    Code (CSharp):
    1. Shader "Custom/Transparent Shadow Receiver" {
    2. Properties {
    3. }
    4. SubShader {
    5.     Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    6.     LOD 200
    7.     ZWrite Off
    8.     Blend Zero SrcColor
    9. CGPROGRAM
    10. #pragma surface surf ShadowOnly alphatest:_Cutoff
    11. fixed4 _Color;
    12. struct Input {
    13.     float2 uv_MainTex;
    14. };
    15. inline fixed4 LightingShadowOnly (SurfaceOutput s, fixed3 lightDir, fixed atten)
    16. {
    17.     fixed4 c;
    18.     c.rgb = s.Albedo * atten;
    19.     c.a = s.Alpha;
    20.     return c;
    21. }
    22. void surf (Input IN, inout SurfaceOutput o) {
    23.     o.Albedo = 1;
    24.     o.Alpha = 1;
    25. }
    26. ENDCG
    27. }
    28. Fallback "Transparent/Cutout/VertexLit"
    29. }
     
  3. ayazsabir123

    ayazsabir123

    Joined:
    Jan 10, 2021
    Posts:
    1
    hi, I tried this using a cube and the shadow is working good but the cube seems to have some sort of a weird blend with my transparent background and the line is visible. Any solution?