Shadow catcher doesn't catch shadows

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sygi

I’m trying to have a shadow catcher in godot: a material which is generally transparent, except it should shows the shadows cast onto it.

As per this thread this shader should do the job:

void fragment() {
  ALBEDO = texture(SCREEN_TEXTURE, SCREEN_UV).rgb;
}

However, when I try to use it:

  1. the material is not transparent (it’s tinted blue)
  2. it doesn’t actually catch the shadows: you can see the shadow of the mug/hand can be seen twice:

What am I doing wrong? How do I get a working shadow catcher?

:bust_in_silhouette: Reply From: sygi

I managed to solve the first problem (lack of transparency) by hacking with shadow_to_opacity:

render_mode shadow_to_opacity;

void fragment() {
  vec3 g = texture(SCREEN_TEXTURE, SCREEN_UV).rgb;
  float mean = (g[0] + g[1] + g[2])/12.;
  ALBEDO = vec3(mean, mean, mean);
}

I still don’t know how to make the material to prevent the shadow to passing through, though.

can’t You try it in higher scope - Geometry Instance (meshinstance) ? Try to reach in editor and flag off shadow casting. It will still be able to receive shadows

Inces | 2021-12-22 20:52

The problem is, I do want the mesh (the cup) to cast shadow: I just want this shadow to fall only on the plane (table), but not on the ground. If you mean to turn off shadow casting in the table, it’s already turned off, but it has no effect as the shadow comes from the cup (although I agree it’s weird).

sygi | 2021-12-22 21:11