-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CanvasItem light_mask is ignored by LightOccluder2D occluder_light_mask #64939
Comments
In godot3, add a CanvasModulate node, and then a PointLight2d node. Set the CanvasModulate color to black and the light will illuminate things in range, this doesn't work in godot4. The documentation is also not updated and the 2D lights don't seem to be maintained! |
Do you have a background set in your Godot 4 scene? I'm able to use the CanvasModulate node fine. As for documentation, I think that comprehensive Godot 4 docs are still a ways off since the version is still in the early beta phase. |
For anyone interested, I'm working around this by :
|
Has there been any more attention paid to this issue since 4.0 released? The way light occluders now always draw atop the related sprite has rendered occluders practically unusable in almost every common use case I can think of. If a tree can't cast a shadow without that shadow obscuring the tree itself, then there's no way to make shadows at all, as far as I can tell. |
I'm so glad I found h0lley's video on this! Been fighting with the 2D lighting system for a top-down game and could not get it to work the way I expected... Thanks for the workaround wattsUpJazz! |
This comment was marked as off-topic.
This comment was marked as off-topic.
@Persipaani Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead. |
You have to set LightOccluder node's cull mode to counterclockwise/clockwise (depending on where the light should enter) to light faces right under the LightOccluder node. Note: Disabling cull mode turns the node into a closed polygon which is the reason why no light enters into the lightoccluder node's area |
@parthipan51 do you mean this is something that can be done in the Godot UI directly (this ticket is desired behavior and not a bug)? Or is this something that needs to be done in C++ inside Godot source (this ticket is still a bug)? |
Yes, it is a desired behavior theVideoOne.webm |
@parthipan51 cool, although I am not sure that's a solution to this issue.
and in case you want to test with that sprite yourself: |
Here, the renderer is taking into account what I think is the Light2D light_mask and the LightOccluder2D light_mask but I don't see where the Sprite2D / CanvasItem light_mask is.
I am not sure if this is where the bug is even, just guessing. As you can see, if the light_mask does not match, it just skips the rendering stuff. godot/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp Lines 1670 to 1680 in f5696c3
This is the method where the code is.
|
We discussed this last night in our weekly rendering meeting. I think the OP is a bit misleading as it mentions the light_mask and occluder_light_mask, but the problem doesn't really have to do with the occluder. The occluder is already properly culled if its mask doesn't match that of the light (as pointed out by Guilleatm: #64939 (comment)). The issue is with the Light2D's The problem is that in Godot 3.x, CanvasItems additionally took the occluder_light_mask into account. This worked very simply in 3.x because we did a separate draw call for each light for each draw command. We could then easily filter out the shadow at the same time we filtered out the light. In 4.x, we render all lights in the same draw call. Which means if we want to bring back that behaviour, we need to mask out the shadow in the shader |
Is there any timeline for fixing this, or is there a simple modification that could be made to Godot's source code so the fix could be built in user-side? This is pretty much game-halting when trying to design an isometric game that needs light occlusion. |
While waiting for a full fix to this issue, you could merge #93881 locally. It provides a new feature that can be used to work around this problem. |
Thanks... unfortunately that doesn't help me since I'm building in 2D isometric with y-sorting and I cannot change the z-index of individual tiles without breaking draw order. Annoyingly, I also can't use the duplicate light trick outlined above by @wattsUpJaz because I programmatically use all of the existing light mask layers already, as my game generates regional maps with up to 20 potential height layers and those are all used to determine where point lights can cast, like so:
It seems like I'm kind of boned when it comes to using occluders until a fix is provided. |
Alright, I've figured out a way to bring back the It required a bit of a refactor. I just need to carry the same changes over to the Compatibility renderer and then I'll PR it! |
Will this be added to Godot in the near future or is the fix just modify the files myself? |
a fix by clayjohn has been merged into master and will be in the next official build, presumably 4.4.dev6. if you need it earlier you can compile yourself. |
Godot version
v4.0.alpha14.official [106b680]
System information
Ubuntu, Nvidia
Issue description
By setting CanvasItem light_mask to a different layer than LightOccluder2D light_mask, it was possible to have shadows not being drawn on top of sprites. This does no longer work.
Godot 3:
Identical setup in Godot 4:
Especially in topdown games you generally need this to work.
Steps to reproduce
Minimal reproduction project
projects for both godot 3 and 4 to compare:
light-occluder-sprite-bug.zip
The text was updated successfully, but these errors were encountered: