The example shader in the docs, “Slices via World Space Position” (scroll down to find it), is supposed to clip pixels in horizontal stripes:

However! When I use the exact same code, the object is receiving shadows in the clipped regions but applying the shadow darkening to whatever is behind the object:

You can see that the other distant shadows on the ground are erased, and new shadows are visible through the holes of the sphere where we should only see the ground. Turning off the light’s shadows makes the darkened regions go away.
Is this fixable (using clip() on an opaque object, in a Surface Shader)? If I need to use alpha cutout instead of opaque, what are the right tags, pragmas, etc?
I want the object’s cast shadow on the ground to be affected by the whole object as if it was not clipped, but I want to see through the object’s clipped holes. My real goal is to clip some pixels around the rim of the object to give it a more irregular silhouette.
EDIT: I found that putting “addshadow” in the pragma solves the shadows-in-the-holes problem, but it also causes the cast shadow to show the stripes instead of being a solid circle.
Here is the shader code from the doc example.
Shader "Example/Slices" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_BumpMap ("Bumpmap", 2D) = "bump" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
Cull Off
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float3 worldPos;
};
sampler2D _MainTex;
sampler2D _BumpMap;
void surf (Input IN, inout SurfaceOutput o) {
clip (frac((IN.worldPos.y+IN.worldPos.z*0.1) * 5) - 0.5);
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
Fallback "Diffuse"
}
