Skip to content

Commit

Permalink
Don't let the standard lighting shader write nan/infs to the output
Browse files Browse the repository at this point in the history
In rare cases, lighting calculations can go haywire and produce bad 
numbers. Writing these into the color buffer will then cause downstream 
filters to go nuts - especially anything blur-based like `!bloom`, which 
produces big ugly squares of badness around the initial bad picel.
  • Loading branch information
jonathanhogg committed Sep 1, 2024
1 parent 97cdb61 commit 3371e2a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/flitter/render/window/glsl/standard_lighting.frag
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,10 @@ void main() {
if (monochrome) {
final_color = vec3(srgb_luminance(final_color.rgb));
}
fragment_color = vec4(final_color * tint, opacity);
final_color *= tint;
if (any(isinf(final_color)) || any(isnan(final_color))) {
fragment_color = vec4(0.0);
} else {
fragment_color = vec4(final_color * tint, opacity);
}
}

0 comments on commit 3371e2a

Please sign in to comment.