From 88ee2edc41d536c7057424df185fc6b49f993896 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 25 Jan 2014 13:57:41 +0100 Subject: [PATCH] Don't dither alpha. For alpha, correct rounding is more important to us than overall spectral properties, simply because 255 -> 255 is such an important case. --- dither_effect.frag | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dither_effect.frag b/dither_effect.frag index f9c6ad1..6994e84 100644 --- a/dither_effect.frag +++ b/dither_effect.frag @@ -3,10 +3,13 @@ uniform vec2 PREFIX(tc_scale); uniform float PREFIX(round_fac), PREFIX(inv_round_fac); vec4 FUNCNAME(vec2 tc) { - // We also choose to dither alpha, just in case. - // Maybe it should in theory have a separate dither, - // but I doubt it matters much. - vec4 result = INPUT(tc) + texture2D(PREFIX(dither_tex), tc * PREFIX(tc_scale)).xxxx; + vec4 result = INPUT(tc); + + // Don't dither alpha; the case of alpha=255 (1.0) is very important to us, + // and if there's any inaccuracy earlier in the chain so that it becomes e.g. + // 254.8, it's better to just get it rounded off than to dither and have it + // possibly get down to 254. This is not the case for the color components. + result.rgb += texture2D(PREFIX(dither_tex), tc * PREFIX(tc_scale)).xxx; // NEED_EXPLICIT_ROUND will be #defined to 1 if the GPU has inaccurate // fp32 -> int8 framebuffer rounding, and 0 otherwise. -- 2.39.2