godot icon indicating copy to clipboard operation
godot copied to clipboard

Light2D additive blending mode is broken

Open olegdudkin opened this issue 1 year ago • 11 comments

Godot version

3.4.4.stable

System information

Win10

Issue description

LightVSSprite

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:

image

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 avatar Jul 27 '22 00:07 olegdudkin

@olegdudkin Please upload a minimal reproduction project to make this easier to troubleshoot.

Calinou avatar Jul 27 '22 01:07 Calinou

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.

Untitled-1

Example: Normal, Overlay, Add, from left to right.

TheDuriel avatar Jul 27 '22 14:07 TheDuriel

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..

rafaelgonzalez avatar Aug 03 '22 08:08 rafaelgonzalez

@Calinou I would be keen know of an ETA if you are able to provide any.

rafaelgonzalez avatar Aug 06 '22 08:08 rafaelgonzalez

@rafaelgonzalez No ETAs in Godot project unfortunately - contributors do stuff case-by-case

Zireael07 avatar Aug 06 '22 08:08 Zireael07

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.

Calinou avatar Aug 06 '22 09:08 Calinou

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) :

Screen Shot 2022-08-06 at 20 23 19

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.

rafaelgonzalez avatar Aug 06 '22 10:08 rafaelgonzalez

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 avatar Aug 06 '22 11:08 Calinou

@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.

TheDuriel avatar Aug 06 '22 11:08 TheDuriel

@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

olegdudkin avatar Aug 06 '22 13:08 olegdudkin

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?

rafaelgonzalez avatar Aug 06 '22 23:08 rafaelgonzalez

Same in 3.5

rpahut avatar Aug 17 '23 18:08 rpahut

Can confirm this is still happening in 4.0 and 4.1.

rafaelgonzalez avatar Sep 16 '23 13:09 rafaelgonzalez

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.

Forum Link

Icewheel12 avatar Jan 01 '24 02:01 Icewheel12