+2 votes

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.

Godot version 3.3.4
in Engine by (14 points)

1 Answer

0 votes

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 Shadow -> item_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).

by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.