Cutout shadows are only culled through the shader properties

I want to create a “wipe” effect, such as is often done by using a black and white gradient texture and changing the cutoff value of the cutout shader to create the desired animation. However, this only works on very basic UV maps; as soon as you have a real world scenario, you’re not going to have a correct wipe using this method.

I’m still very new to shaders, but I adapted a custom cutout shader that I happened across to have a “Height” property, which can be used to create a cut off based on the world position of the pixels. (if the object starts at y = 0, but for my specific case this is always true)

 Shader "Animations/VerticalFadeInCutout" 
 {
    Properties 
    {
        _Color ("Main Color", Color) = (1,1,1,1)
        _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
        _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
        _Height("Height", Float) = 1
    }
     
    SubShader 
    {
        Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
        LOD 200
        Cull Off
           
        CGPROGRAM
        #pragma surface surf Lambert alphatest:_Cutoff
         
        sampler2D _MainTex;
        fixed4 _Color;
        float _Height;
         
        struct Input 
        {
            float2 uv_MainTex;
            float3 worldPos;
        };
         
        void surf (Input IN, inout SurfaceOutput o) 
        {
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            o.Alpha = (_Height - IN.worldPos.y) - (_Height / 2) + 0.5;
        }
        ENDCG
    }
     
    Fallback "Transparent/Cutout/Diffuse"
 }

Turning the object transparent works just fine this way, however the shadow is still being cast, both on the transparent bits of the mesh itself and on the geometry behind it. If I change the color in the inspector directly though, the shadows do get removed. I reckon I’m doing something wrong here, so I’d really appreciate a hand in this matter.

Thanks!

2082955--136180--regular.jpg
2082955--136181--shadows.jpg

You’ll need to add your own shadow caster and receiver passes whose clip value matches your modifications.

The built-in shadow casters don’t know you’re hiding part of the mesh.

1 Like

Oh, that’s it, thanks! Using this post from Aras it was really easy.