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

Clamped alpha is preventing certain blending effects #77360

Closed
wareya opened this issue May 22, 2023 · 4 comments
Closed

Clamped alpha is preventing certain blending effects #77360

wareya opened this issue May 22, 2023 · 4 comments

Comments

@wareya
Copy link
Contributor

wareya commented May 22, 2023

Godot version

4.0.3

System information

Windows 10, amd rx 480 gpu

Issue description

Unlike Godot 3, Godot 4 clamps alpha values before blending. I'm not sure where in the rendering pipeline this happens, or if it's even controllable, but it makes it impossible to do certain types of blending trickery that are common in 2d games. For example, in Godot 3, you can render 50% gray with 200% alpha over anything to invert its colors. In Godot 4, this is impossible; 200% alpha acts like 100% alpha.

Godot 3:

Godot_v3 5-stable_win64_2023-05-22_13-46-30

Godot 4:

Godot_v4 0 3-stable_win64_2023-05-22_13-47-12

Steps to reproduce

Add a ColorRect with the following shader:

shader_type canvas_item;

void fragment()
{
    COLOR.rgb = vec3(0.5, 0.5, 0.5);
    COLOR.a = 2.0;
}

Minimal reproduction project

ClampedAlphaRepro.zip

@wareya
Copy link
Contributor Author

wareya commented May 22, 2023

For context on where I ran into this: I'm making a voxel level editing tool, and when configuring some kinds of materials, I have to display a grid over them. In Godot 3 I was rendering that grid with this technique, but it no longer works properly.

image

@Calinou
Copy link
Member

Calinou commented May 22, 2023

This is likely due to the same cause as #62110. The alpha channel is also affected by the reduced precision and dynamic range.

Can you reproduce this in 3D?

@wareya
Copy link
Contributor Author

wareya commented May 22, 2023

Inversion works in 3D:
image
Alpha blending happens before anything is written to the underlying buffer, and this technique is used by a fair number of old games without HDR, so at the very least, having LDR buffers wouldn't prevent this from being fixed. This is a good pointer in the right direction, though.

@clayjohn
Copy link
Member

This was fixed last summer by #80215. The fix is included in version 4.2!

To benefit from it, you just need to enable the rendering/viewport/hdr_2d project setting!

note, the colors won't be the exact same since blending happens in linear space now. But that is an expected difference between 3.x and 4.x
Screenshot from 2024-04-17 21-52-44

@clayjohn clayjohn added this to the 4.2 milestone Apr 18, 2024
@akien-mga akien-mga added the bug label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants