Help... Surface Cutout shader not displaying alpha correctly with shadows

Hey there, hope anyone can help… Ive written this surface shader to give my trees some movement and I thought creating a cutout shader would be simple enough however I’m getting a really weird issue which I know has something to do with shadowcaster and the way I’m using it but I’m stump at how to move forwards.

This is the shader:

Shader "Nature/FoliageMovement" {
    Properties {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness("Smoothness", Range(0,1)) = 0.5
        _Metallic("Metallic", Range(0,1)) = 0.0
        _Speed("Speed",float) = 50
        _Offset("Offset",vector) = (0,0,0,0)
        _CutOff("CutOff", float) = 1
    }
        SubShader{
            Tags
        {
            "IgnoreProjector" = "True"
            "Queue" = "AlphaTest"
            "RenderType" = "TransparentCutout"
             "LightMode" = "ShadowCaster"
        }
            LOD 200
            Cull Off
       
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows vertex:vert alphatest:_CutOff
        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
        float _Speed;
        float4 _Offset;

        struct Input {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        void vert (inout appdata_full v)
        {

                _Offset = fixed4(clamp(_Offset.x,-0.25, 0.25)/100, _Offset.y/100, clamp(_Offset.z,-0.25, 0.25)/100,_Offset.w/100);

                //Top
                v.vertex.x  += v.color.g * sin(_Time * _Speed) * _Offset.x;
                v.vertex.z += v.color.g * sin(_Time * _Speed) * _Offset.z;
                //Base
                v.vertex.x += v.color.r * 0;
                v.vertex.z += v.color.r * 0;
                v.vertex.y += v.color.r * 0;
                v.vertex.w += v.color.r * 0;

                v.vertex.y += (v.color.g * sin(_Time *  _Speed)* mul(unity_WorldToObject, v.vertex)*_Offset.y);
                float bounce = v.color.g * sin(_Time * _Speed) *_Offset.w;
                v.vertex.y += bounce;

                }

        void surf (Input IN, inout SurfaceOutputStandard o) {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Transparent/Cutout/Diffuse"
}

The is what I’m seeing in editor2941693--217719--Alpha Problem.jpg

But weirdly by selecting the model I get the desired result however this is only temporary and doesn’t show in a build :frowning:2941693--217720--DesiredResult.jpg

Any help would be greatly appreciated and thanks in advance :slight_smile:

Okay so something strange is happening, I have rewritten it again because I cant think what else to do, and this time it no longer does the above issue. Instead I just get a slight ghosting now, does anyone know why this happens and how to eliminate it?


As said really not sure why this script now works over the other one but here it is anyways.

 Shader "Nature/FoliageMovement" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
         _Glossiness("Smoothness", Range(0,1)) = 0.5
         _Metallic("Metallic", Range(0,1)) = 0.0
         _Speed("Speed",float) = 50
         _Offset("Offset",vector) = (0,0,0,0)
     }
     SubShader {
         Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout"  "LightMode" = "ShadowCaster"}
         LOD 200
         Cull Off
       
         CGPROGRAM      
         #pragma surface surf Standard fullforwardshadows alphatest:_Cutoff vertex:vert
               
         #pragma target 3.0
         sampler2D _MainTex;
         sampler2D _DetailTex;      
         float _Speed;
         float4 _Offset;
         half _Glossiness;
         half _Metallic;
         struct Input {
             float2 uv_MainTex;
         };

         void vert (inout appdata_full v)
        {

                _Offset = fixed4(clamp(_Offset.x,-0.25, 0.25)/100, _Offset.y/100, clamp(_Offset.z,-0.25, 0.25)/100,_Offset.w/100);

                //Top
                v.vertex.x  += v.color.g * sin(_Time * _Speed) * _Offset.x;
                v.vertex.z += v.color.g * sin(_Time * _Speed) * _Offset.z;
                //Base
                v.vertex.x += v.color.r * 0;
                v.vertex.z += v.color.r * 0;
                v.vertex.y += v.color.r * 0;
                v.vertex.w += v.color.r * 0;

                v.vertex.y += (v.color.g * sin(_Time *  _Speed)* mul(unity_WorldToObject, v.vertex)*_Offset.y);
                float bounce = v.color.g * sin(_Time * _Speed) *_Offset.w;
                v.vertex.y += bounce;

                }
         void surf (Input IN, inout SurfaceOutputStandard o) {          
             fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
             o.Albedo = c.rgb;
             o.Alpha = c.a;
             // Metallic and smoothness come from slider variables
             o.Metallic = _Metallic;
             o.Smoothness = _Glossiness;
         }
         ENDCG
     }
     FallBack "Transparent/Cutout/Diffuse"
}

Thanks again.