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 #51436

Merged
merged 1 commit into from
Aug 10, 2021
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
10 changes: 4 additions & 6 deletions servers/rendering/renderer_rd/shaders/tonemap.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,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 (white * color + color) / (color * white + white);
}

Expand All @@ -211,7 +207,7 @@ vec3 apply_tonemapping(vec3 color, float white) { // inputs are LINEAR, always o
return tonemap_reinhard(color, white);
} else if (params.tonemapper == TONEMAPPER_FILMIC) {
return tonemap_filmic(color, white);
} else { //aces
} else { // TONEMAPPER_ACES
return tonemap_aces(color, white);
}
}
Expand Down Expand Up @@ -405,7 +401,9 @@ void main() {
color += screen_space_dither(gl_FragCoord.xy);
}

color = apply_tonemapping(color, params.white);
// Ensure color values passed to tonemappers 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), params.white);

color = linear_to_srgb(color); // regular linear -> SRGB conversion

Expand Down