Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-02-17 16:14:30 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-02-17 17:47:17 +0300
commit852cdd476b5572b56418d377e379c07253363eff (patch)
tree14467e0c649819e95f4de6913dfc0ac7edf4d8b8 /source/blender/blenlib
parent5231d06d4cd4a613b0493965893ae17df43c0f22 (diff)
ColorManagement: Dithering Improvement
- Unlock property range. - Use triangular noise to keep perceptual noise error more uniform. Remap range to preserve perceptual intensity. - Center noise distribution around 0 for GPU implementation because of rounding. - Do dithering after merging overlays. Effect of using triangular noise is not really noticeable if you don't use really low bitdepth. But doing a test in the shader were we artificially reduce the bitdepth (`col = (col * 16) / 16;`) reveals the real difference. Reviewed By: brecht Differential Revision: https://developer.blender.org/D6850
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/intern/math_color_inline.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c
index f5aaddc0ea3..52ca229fe27 100644
--- a/source/blender/blenlib/intern/math_color_inline.c
+++ b/source/blender/blenlib/intern/math_color_inline.c
@@ -317,19 +317,27 @@ MINLINE int compare_rgb_uchar(const unsigned char col_a[3],
return 0;
}
+/* Using a triangle distribution which gives a more final uniform noise.
+ * See Banding in Games:A Noisy Rant(revision 5) Mikkel Gjøl, Playdead (slide 27) */
+/* Return triangle noise in [-0.5..1.5[ range */
MINLINE float dither_random_value(float s, float t)
{
- static float vec[2] = {12.9898f, 78.233f};
- float value;
-
- value = sinf(s * vec[0] + t * vec[1]) * 43758.5453f;
- return value - floorf(value);
+ /* Original code from https://www.shadertoy.com/view/4t2SDh */
+ /* The nois reshaping technique does not work on CPU.
+ * We generate and merge two distribution instead */
+ /* Uniform noise in [0..1[ range */
+ float nrnd0 = sinf(s * 12.9898f + t * 78.233f) * 43758.5453f;
+ float nrnd1 = sinf(s * 19.9898f + t * 119.233f) * 43798.5453f;
+ nrnd0 -= floorf(nrnd0);
+ nrnd1 -= floorf(nrnd1);
+ /* Convert uniform distribution into triangle-shaped distribution. */
+ return nrnd0 + nrnd1 - 0.5f;
}
MINLINE void float_to_byte_dither_v3(
unsigned char b[3], const float f[3], float dither, float s, float t)
{
- float dither_value = dither_random_value(s, t) * 0.005f * dither;
+ float dither_value = dither_random_value(s, t) * 0.0033f * dither;
b[0] = unit_float_to_uchar_clamp(dither_value + f[0]);
b[1] = unit_float_to_uchar_clamp(dither_value + f[1]);