Skip to content
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

Fix broken 2D light blending, addresses #49922 #66370

Merged
merged 1 commit into from
Sep 27, 2022

Conversation

bitbrain
Copy link
Contributor

@bitbrain bitbrain commented Sep 24, 2022

This pull request aims to address issues raised in #49922 - the problem was that the color was already modified with the modulate color. It was impossible to then rely on the original color for lighting. To fix the issue I made sure to remember the original color for the light processing.

Before this change

before

After this change

after

Bugsquad edit:

@bitbrain bitbrain requested a review from a team as a code owner September 24, 2022 19:22
@YuriSizov YuriSizov added this to the 4.0 milestone Sep 24, 2022
@bitbrain bitbrain changed the title fix broken 2D light blending, addresses #49922 Fix broken 2D light blending, addresses #49922 Sep 24, 2022
@h0lley
Copy link

h0lley commented Sep 25, 2022

Tested it in a project originally built in 3.x and can confirm it looks almost identical now 👍

I say almost because in my test scene here, the light source sprite (to which PointLight2D is a child) still looks different depending on CanvasModulate. this is presumably a different issue though.

image

@bitbrain
Copy link
Contributor Author

@h0lley how does the above scene look in 4.0 without this fix?

@h0lley
Copy link

h0lley commented Sep 25, 2022

@h0lley how does the above scene look in 4.0 without this fix?

image

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

For future reference, the reason this PR is correct is that it multiplies the base color of the sprite with the lights color in calculating the lights contribution before blending. In Godot 3.x lights were each rendered in a separate pass where you would redraw all sprites, calculate their color normally, multiply by the light, then blend using a fixed function blending mode.

To achieve the equivalent in Godot 4.x we need to save the sprite's color and then multiply it by the light color for each light before blending.

@akien-mga akien-mga merged commit 2ad63f6 into godotengine:master Sep 27, 2022
@akien-mga
Copy link
Member

Great work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vulkan: Light2d Blend Modes do not behave correctly
5 participants