No shadows when looking through a cutout shader

I’m trying to have a custom cutout shader cast shadows (blue arrow), and allow shadows to be seen through the cutout (red arrow). As you can see, none of that is happening right now.

77070-noshadow.png

(Its a cube with the cutout shader intersecting a default cube below, viewed from the top with an orthographic camera)

I need a custom shader because the border cutout detail is stored in a separate detail texture. My shader code is below:

Shader "Custom/TerrainShader" {
	Properties {
		_Color ("Color", Color) = (1,1,1,1)
		_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
		_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
		_DetailTex ("Detail (RGB)", 2D) = "white" {}
	}
	SubShader {
		Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" }
		LOD 200
		
		CGPROGRAM		
		#pragma surface surf Standard fullforwardshadows alphatest:_Cutoff
				
		#pragma target 3.0

		sampler2D _MainTex;
		sampler2D _DetailTex;		
		fixed4 _Color;

		struct Input {
			float2 uv_MainTex;
			float2 uv2_DetailTex;
		};

		void surf (Input IN, inout SurfaceOutputStandard o) {			
			fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color * tex2D(_DetailTex, IN.uv2_DetailTex);
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		ENDCG
	}
	FallBack "Transparent/Cutout/Diffuse"
}

It is based on the old Transparent/Cutout/Diffuse shaders, but also samples the detail texture I described.

If I change the Queue to Overlay, it draws on top of the shadow casting and I can see shadows through the cutout (red arrow), but obviously it doesn’t cast its own shadows then. I think I have to alter the shadow pass to make it discard the alpha pixels in the detail texture, but that wouldn’t solve the problem pointed at by the red arrow, I think.

Any ideas?

Add the “addshadow” keyword to the surface declaration.

User bgolus on UnityForums nailed the solution with his post.

Basically I needed to add addshadow to my pragma line, since that makes Unity generate a custom shadow caster pass for my surface shader, which takes my custom _DetailTex into account. If I don’t do that, it will use the shadow caster pass of my Fallback shader (Transparent/Cutout/Diffuse) instead, which doesn’t know about my _DetailTex.

It now looks exactly as you would expect:

77092-after.png