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>2018-04-21 17:45:47 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-04-21 17:49:38 +0300
commitc23f33ac9e94d98cc1f593653f0e3abb031ecae0 (patch)
tree67bd11c5d6d226dde92d4a84e26bb812d079fe7e /source/blender/gpu/shaders
parent28a24db68aa6c69af07aabc2a8fde0373bd7ab33 (diff)
View3D: Atenuate banding artifacts on background gradient.
Dithering the output color for 8bit precision framebuffer with bayer matrix. On my tests the bayer matrux patterns are not noticeable at all. Note that it also does that in opengl rendered mode which can be in a much higher bitdepth. We can fix that if that's a problem in the future but I doubt it will.
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl20
1 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl
new file mode 100644
index 00000000000..145ed16248a
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl
@@ -0,0 +1,20 @@
+
+noperspective in vec4 finalColor;
+out vec4 fragColor;
+
+/* 4x4 bayer matrix prepared for 8bit UNORM precision error. */
+#define P(x) (((x + 0.5) * (1.0 / 16.0) - 0.5) * (1.0 / 255.0))
+const vec4 dither_mat4x4[4] = vec4[4](
+ vec4( P(0.0), P(8.0), P(2.0), P(10.0)),
+ vec4(P(12.0), P(4.0), P(14.0), P(6.0)),
+ vec4( P(3.0), P(11.0), P(1.0), P(9.0)),
+ vec4(P(15.0), P(7.0), P(13.0), P(5.0))
+);
+
+void main()
+{
+ ivec2 tx1 = ivec2(gl_FragCoord.xy) % 4;
+ ivec2 tx2 = ivec2(gl_FragCoord.xy) % 2;
+ float dither_noise = dither_mat4x4[tx1.x][tx1.y];
+ fragColor = finalColor + dither_noise;
+}