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

Clamp negative colors regardless of the tonemapper to avoid artifacts #51439

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions drivers/gles3/shaders/tonemap.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ vec3 tonemap_aces(vec3 color, float white) {
}

vec3 tonemap_reinhard(vec3 color, float white) {
// Ensure color values are positive.
// They can be negative in the case of negative lights, which leads to undesired behavior.
color = max(vec3(0.0), color);

return clamp((white * color + color) / (color * white + white), vec3(0.0f), vec3(1.0f));
}

Expand Down Expand Up @@ -347,8 +343,9 @@ void main() {
#endif

// Early Tonemap & SRGB Conversion; note that Linear tonemapping does not clamp to [0, 1]; some operations below expect a [0, 1] range and will clamp

color = apply_tonemapping(color, white);
// Ensure color values are positive.
// They can be negative in the case of negative lights, which leads to undesired behavior.
color = apply_tonemapping(max(vec3(0.0), color), white);

#ifdef KEEP_3D_LINEAR
// leave color as is (-> don't convert to SRGB)
Expand Down