Receive shadows, but don't cast any

I need a shader that receives shadows, but don’t cast any itself. Basically mimic the behavior you get when you disable shadow casting on a mesh renderer, but on a shader level instead.

Been trying to write this shader, but so far I either get both or no shadows at all.

Any help would be greatly appreciated.

What type of shader are you writing? Surface?

To do this from the shader only you’ll need to detect if your shadowcaster pass is rendering during the shadow pass or the depth pass:

The main directional light shadows work by casting against the camera’s depth texture, which is rendered with the same shadowcaster pass as shadows, at least as of Unity 5.

You basically want to add this line to your shadowcaster fragment shader.

if (unity_LightShadowBias.z != 0.0) discard;

If you’re using a surface shader you can add addshadow to the #pragma surface line and then add this to your surface function.

#ifdef UNITY_PASS_SHADOWCASTER
if (unity_LightShadowBias.z != 0.0) discard;
#endif

1 Like

Doesn’t really matter, as long as I can get this effect.

Wow, this was pretty much exactly what I was looking for and it’s working great. Thank you so much for sharing!

As an additional note that “hack” is also what Unity uses to differentiate the two cases. It happens to fail if your light doesn’t have a normal bias (that’s what that value is). That thread was me attempting to find another value that is consistently different between the passes that wouldn’t fail in the case of normal bias being disabled.