Shadows go over the Sprite when using Light2D and LightOccluder2D.

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

Hello everyone, I am having an issue when trying to get 2D lights & shadows working. Would love to get some help about this, as I’m out of ideas. I have done a good amount of Googling, and this was asked multiple times both here and in the Godot forums, but there are no answers that help.

##Context

I have a Player node with a Sprite and LightOccluder2D. There is a Light2D on the window.

The Problem

Problem

As you can see, the shadow goes over the Sprite.

What I’ve Tried So Far

  • I’ve put the occluder inside the Sprite (as a child), and set Show Behind Parent as true. Did not do anything.
  • Set the z-index of the occluder to something lower. This only has an effect on the occluder shape in the editor, but not the shadow.
  • I’ve changed the occluder polygon so that it is not closed, and set the Cull Mode to Clockwise:

Open occluder

That sorta helped, but it leaks light:

Leaking light

  • I set the occluders Light Mask to 1, Sprites Light Mask (under Visibility) to 2, and set the Lights Item Cull Mask (under Range) to both 1 and 2 (setting it under Shadow just goes back to the original problem). This worked beautifully, however now the Player sprite is not affected at all by other shadows, it just stays lit, as you can see in this gif.

Would love to hear any ideas on to fix this. Thank you all for your help.

:bust_in_silhouette: Reply From: imaginaryrobots

Range → Item Cull mask controls which things get lit up by the light.
Shadow → Item Cull mask controls which occluders the light will interact with, AND which things it will cast shadows on.

Having the occluder in a separate light layer from the sprite is good, but to avoid self-shadowing on your player sprite, you can’t have the sprite and the shadow in the same Shadowitem_cull_mask.

It looks like godot 4 will make this all easier, but for godot 3, one workaround is to have your window use multiple Light2Ds, one of which will cast shadows from your player occluder, and one of which will cast shadows from everything else (and is allowed to cast them onto your player).