godot
godot copied to clipboard
Light2D additive blending mode is broken
Godot version
3.4.4.stable
System information
Win10
Issue description
Both images are the same texture with the same blending mode "ADD". Left one is Light2D, right one is Sprite2D It seems like it acts weird and there is some hard cutoff for background lightness:
This is a light with maximum energy - 16. I expect to see white circle.
Steps to reproduce
Add Light2D over black background. Use Add / Mix mode Light is completely invisible
Minimal reproduction project
No response
@olegdudkin Please upload a minimal reproduction project to make this easier to troubleshoot.
Expected output according to photoshop and the corresponding GLSL code https://github.com/jamieowen/glsl-blend :
The behavior shown by OP on the left, (Light2D node set to add) appears consistent with the "Overlay" operation, rather than the "Linear Dodge" aka. "Add" operation.
Example: Normal, Overlay, Add, from left to right.
I have the same issue. When using a Sprite with a gray texture as background, the light works as expected. However, using a black texture on the background Sprite makes the light disappear completely.
@Calinou I've opened up my repository and added a ZIP on a GitHub release to illustrate the issue. If you open up the project, you will see the light working as intended on the gray background. Simply replace the texture on the background with the black.png
file and you should be able to replicate the issue..
@Calinou I would be keen know of an ETA if you are able to provide any.
@rafaelgonzalez No ETAs in Godot project unfortunately - contributors do stuff case-by-case
Isn't this expected? If you light up a black surface in real life, it'll still be black.[^1] Additive sprites do not care about the background color, which makes them much faster to render but it's also not physically accurate. (For instance, texture detail is lost when a dark area is "lit" by an additive Sprite.)
In short, light is multiplying the existing color values rather than adding to them.
[^1]: I'm intentionally putting aside the intricacies of physically-based rendering here, but in 2D, this is how lighting is expected to behave.
If you want areas to be dark when there is no light, use a CanvasModulate node. See the 2D Lights and Shadows for an example of this.
Isn't this expected? If you light up a black surface in real life, it'll still be black.1 Additive sprites do not care about the background color, which makes them much faster to render but it's also not physically accurate. (For instance, texture detail is lost when a dark area is "lit" by an additive Sprite.)
In short, light is multiplying the existing color values rather than adding to them.
I suppose, but then I think the "Add" mode name is a bit misleading here. I would expect the light's colour to be added to the background's colour, not multiplied by it. @TheDuriel's picture and comment makes sense to me, "Overlay" feels descriptive of the current behaviour, e.g. multiplying.
If anything, another light mode that actually adds the light to the background be would be great. Otherwise, I am not sure how to achieve the below with a black background (instead of grey) :
If you want areas to be dark when there is no light, use a CanvasModulate node. See the 2D Lights and Shadows for an example of this.
Thanks for sharing. I've used the 2D Light tutorial and saw CanvasModulate as a potential solution, but it alters the whole canvas instead of specific areas/nodes.
I've used the 2D Light tutorial and saw CanvasModulate as a potential solution, but it alters the whole canvas instead of specific areas/nodes.
You can use multiple CanvasLayer nodes to avoid this, as CanvasModulate will only affect the CanvasLayer it's a child of.
@Calinou This isn't exactly viable, as physics do not behave correctly in CanvasLayers. Meaning you need to make a big effort to separate the tree structure in regards to game logic and their different visual layers. On top, layers are a massive performance hog on some mobile platforms.
All in all though: This issue is mainly about a misnomer in the blending modes of Lights. (They're not additive, they're multiplicative / similar to this: https://github.com/jamieowen/glsl-blend/blob/master/overlay.glsl) We can correct the name of the blending mode, then look into functionality and how to achieve certain effects and looks.
@rafaelgonzalez I've ended up adding custom shader on top of already lit scene. It turns out that if you use 50% grey background and then do COLOR.rgb = COLOR.rgb * 2.0 - 1.0;
you get exactly the right colors
Hi @olegdudkin, thanks for the suggestion. Would you be able to elaborate a bit more? What node did you add your shader to? The background itself, or something else?
Same in 3.5
Can confirm this is still happening in 4.0 and 4.1.
Couldn't find an opened issue any closer to the one I'm having than this so I'll put this here. Not only do the Light blend modes not work, the TextRect blend modes don't either. I have a link attached below that will take you to forum question that I posted awhile ago. It explains the exact issue that's occuring in my situation, but I'm curious as to why blending modes as a whole don't seem to currently work at all.