SSAO and Custom Shader transparent edge detection

Hello.
The character has a shirt.
The sleeve of the shirt ends with a transparent texture, not a polygon. If I use my shader with Unity Post-Process SSAO, then I will get a shadow where it should not be.

With standard shader:

With my shader:

Shader source:

Shader "Custom/Specular"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _MainNormal ("Normal", 2D) = "bump" {}
        _MainOcclusion ("Occlusion", 2D) = "white" {}
        _MainSpecular("Specular", 2D) = "black" {}
        _Glossiness ("Smoothness", Range(0.0, 1.0)) = 0.0
        _Cutoff ("Alpha Cutoff", Range(0.0, 1.0)) = 0.55
    }
    SubShader
    {
        Cull Back
        Tags
        {
            "Queue" = "AlphaTest"
            "IgnoreProjector" = "True"
            "RenderType" = "TransparentCutout"
        }
        LOD 100
 
        CGPROGRAM
        #pragma surface surf StandardSpecular alphatest:_Cutoff
        #pragma target 2.0
        sampler2D _MainTex;
        sampler2D _MainNormal;
        sampler2D _MainOcclusion;
        sampler2D _MainSpecular;
        half _Glossiness;
        struct Input
        {
            float2 uv_MainTex;
            float2 uv_MainNormal;
            float2 uv_MainOcclusion;
            float2 uv_MainSpecular;
        };
        void surf(Input IN, inout SurfaceOutputStandardSpecular o)
        {
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
            fixed gray = 0.21 * c.r + 0.7154 * c.g + 0.0721 * c.b;
            o.Albedo = lerp(fixed3(gray, gray, gray), c.rgb, 1.4).rgb;
            o.Specular = tex2D(_MainSpecular, IN.uv_MainSpecular);
            o.Smoothness = _Glossiness;
            o.Normal = UnpackNormal(tex2D(_MainNormal, IN.uv_MainNormal));
            o.Occlusion = tex2D(_MainOcclusion, IN.uv_MainOcclusion);
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

Also if i in material settings set Alpha Cutoff to 1.0 and in shader set a value to o.Alpha smaller than 1.0 (o.Alpha = 0.5;)
i get this:

Add addshadow to the #pragma surface line.

1 Like

So, what if i’m using Scalable Ambient Obscurance? It’s working fine for only Multi Scale Volumentric Obscurance

MSVO only uses the depth buffer, which is why it works.

SAO uses the camera normals texture, which when you’re using the forward renderer is created by using a replacement shader. This means it doesn’t support custom shaders very easily. If you can’t conform your shader to any of the built in shaders, like if you’re modifying the vertex positions or modifying the UVs or alpha values, then you’ll need to use a custom RenderType tag, and then add your own override into the camera depth normals shader with the same tag.