From 5217b5090c6d3a81c9346693318eb30349558459 Mon Sep 17 00:00:00 2001 From: Imbris Date: Wed, 22 Sep 2021 21:58:36 -0400 Subject: [PATCH] Avoided black hexagons when bloom is enabled by suppressing NaN/Inf pixels during the first bloom blur pass --- CHANGELOG.md | 1 + .../shaders/dual-downsample-filtered-frag.glsl | 18 +++++++++++------- voxygen/src/render/renderer/drawer.rs | 6 +++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c542ab699..ea33f6c140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The menu map now properly handles dragging the map, zooming, and setting the waypoint when hovering icons - Falling through an airship in flight should no longer be possible (although many issues with airship physics remain) +- Avoided black hexagons when bloom is enabled by suppressing NaN/Inf pixels during the first bloom blur pass ## [0.11.0] - 2021-09-11 diff --git a/assets/voxygen/shaders/dual-downsample-filtered-frag.glsl b/assets/voxygen/shaders/dual-downsample-filtered-frag.glsl index 9ce06098ae..a2116364f3 100644 --- a/assets/voxygen/shaders/dual-downsample-filtered-frag.glsl +++ b/assets/voxygen/shaders/dual-downsample-filtered-frag.glsl @@ -68,17 +68,21 @@ vec4 filteredDownsample(vec2 uv, vec2 halfpixel) { return sum / 32.0; } -vec4 simplesample(vec2 uv) { - return textureLod(sampler2D(t_src_color, s_src_color), uv, 0); +vec4 naninf_filter_sample(vec2 uv) { + vec4 color = textureLod(sampler2D(t_src_color, s_src_color), uv, 0); + // TODO: ensure NaNs/Infs are not produced in the first place + bvec4 nan = isnan(color); + bvec4 inf = isinf(color); + return mix(mix(color, vec4(0.0), nan), vec4(100.0), inf); } // From: https://community.arm.com/cfs-file/__key/communityserver-blogs-components-weblogfiles/00-00-00-20-66/siggraph2015_2D00_mmg_2D00_marius_2D00_notes.pdf vec4 downsample(vec2 uv, vec2 halfpixel) { - vec4 sum = simplesample(uv) * 4.0; - sum += simplesample(uv - halfpixel.xy); - sum += simplesample(uv + halfpixel.xy); - sum += simplesample(uv + vec2(halfpixel.x, -halfpixel.y)); - sum += simplesample(uv - vec2(halfpixel.x, -halfpixel.y)); + vec4 sum = naninf_filter_sample(uv) * 4.0; + sum += naninf_filter_sample(uv - halfpixel.xy); + sum += naninf_filter_sample(uv + halfpixel.xy); + sum += naninf_filter_sample(uv + vec2(halfpixel.x, -halfpixel.y)); + sum += naninf_filter_sample(uv - vec2(halfpixel.x, -halfpixel.y)); return sum / 8.0; } diff --git a/voxygen/src/render/renderer/drawer.rs b/voxygen/src/render/renderer/drawer.rs index 16f67b76f2..2a22eda9a1 100644 --- a/voxygen/src/render/renderer/drawer.rs +++ b/voxygen/src/render/renderer/drawer.rs @@ -286,7 +286,11 @@ impl<'frame> Drawer<'frame> { (0..bloom::NUM_SIZES - 1).for_each(|index| { let bind = &bloom_binds[index].bind_group; let view = &bloom_tgts[index + 1]; - // Do filtering out of non-bright things during the first downsample + // Do filtering during the first downsample + // NOTE: We currently blur all things without filtering by brightness. + // This is left in for those that might want to experminent with filtering by + // brightness, and it is used to filter out NaNs/Infs that would infect all the + // pixels they are blurred with. let (label, pipeline) = if index == 0 { ( format!("downsample filtered {}", index + 1),