summaryrefslogtreecommitdiff
path: root/servers/rendering/renderer_rd/shaders
diff options
context:
space:
mode:
authorclayjohn <claynjohn@gmail.com>2021-10-29 21:41:57 -0700
committerclayjohn <claynjohn@gmail.com>2021-10-29 21:41:57 -0700
commit4d1d2b3900b8773565eebcd55c9246c4c5528056 (patch)
tree53ad3a6199d9c51dd39b4677d372f492ee52aa68 /servers/rendering/renderer_rd/shaders
parentd046817536a21358f9c51bf5b932d0a6615ee76a (diff)
Weight glow samples to reduce fireflies
Diffstat (limited to 'servers/rendering/renderer_rd/shaders')
-rw-r--r--servers/rendering/renderer_rd/shaders/copy.glsl14
1 files changed, 13 insertions, 1 deletions
diff --git a/servers/rendering/renderer_rd/shaders/copy.glsl b/servers/rendering/renderer_rd/shaders/copy.glsl
index 4110a95ddb..75ee4c55f7 100644
--- a/servers/rendering/renderer_rd/shaders/copy.glsl
+++ b/servers/rendering/renderer_rd/shaders/copy.glsl
@@ -132,6 +132,13 @@ void main() {
local_cache[dest_index + 16] = textureLod(source_color, quad_center_uv + vec2(0.0, 1.0 / params.section.w), 0);
local_cache[dest_index + 16 + 1] = textureLod(source_color, quad_center_uv + vec2(1.0 / params.section.zw), 0);
}
+ if (bool(params.flags & FLAG_GLOW_FIRST_PASS)) {
+ // Tonemap initial samples to reduce weight of fireflies: https://graphicrants.blogspot.com/2013/12/tone-mapping.html
+ local_cache[dest_index] /= 1.0 + dot(local_cache[dest_index].rgb, vec3(0.299, 0.587, 0.114));
+ local_cache[dest_index + 1] /= 1.0 + dot(local_cache[dest_index + 1].rgb, vec3(0.299, 0.587, 0.114));
+ local_cache[dest_index + 16] /= 1.0 + dot(local_cache[dest_index + 16].rgb, vec3(0.299, 0.587, 0.114));
+ local_cache[dest_index + 16 + 1] /= 1.0 + dot(local_cache[dest_index + 16 + 1].rgb, vec3(0.299, 0.587, 0.114));
+ }
memoryBarrierShared();
barrier();
@@ -177,6 +184,11 @@ void main() {
color += temp_cache[index - 2] * 0.140367;
color += temp_cache[index - 3] * 0.106595;
+ if (bool(params.flags & FLAG_GLOW_FIRST_PASS)) {
+ // Undo tonemap to restore range: https://graphicrants.blogspot.com/2013/12/tone-mapping.html
+ color /= 1.0 - dot(color.rgb, vec3(0.299, 0.587, 0.114));
+ }
+
color *= params.glow_strength;
if (bool(params.flags & FLAG_GLOW_FIRST_PASS)) {
@@ -186,7 +198,7 @@ void main() {
#endif
color *= params.glow_exposure;
- float luminance = max(color.r, max(color.g, color.b));
+ float luminance = dot(color.rgb, vec3(0.299, 0.587, 0.114));
float feedback = max(smoothstep(params.glow_hdr_threshold, params.glow_hdr_threshold + params.glow_hdr_scale, luminance), params.glow_bloom);
color = min(color * feedback, vec4(params.glow_luminance_cap));