From c7c8cc399c5b2fb4245bb72203799478c6a14388 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Fri, 23 Sep 2022 23:48:59 +0200 Subject: [PATCH] Fix debanding strength being affected by environment adjustments (cherry picked from commit 6d0d9037cd26a4cbfbf81bd2953e8a47ab082119) --- drivers/gles3/shaders/tonemap.glsl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gles3/shaders/tonemap.glsl b/drivers/gles3/shaders/tonemap.glsl index e4c1b11a316..faede84d6eb 100644 --- a/drivers/gles3/shaders/tonemap.glsl +++ b/drivers/gles3/shaders/tonemap.glsl @@ -467,12 +467,6 @@ void main() { color.rgb = apply_cas(color.rgb, full_exposure, uv_interp, sharpen_intensity); #endif -#ifdef USE_DEBANDING - // For best results, debanding should be done before tonemapping. - // Otherwise, we're adding noise to an already-quantized image. - color.rgb += screen_space_dither(gl_FragCoord.xy); -#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.rgb = apply_tonemapping(color.rgb, white); @@ -507,6 +501,12 @@ void main() { color.rgb = apply_color_correction(color.rgb, color_correction); #endif +#ifdef USE_DEBANDING + // Debanding should be done at the end of tonemapping, but before writing to the LDR buffer. + // Otherwise, we're adding noise to an already-quantized image. + color.rgb += screen_space_dither(gl_FragCoord.xy); +#endif + frag_color = color; #ifdef DISABLE_ALPHA