summaryrefslogtreecommitdiffstats
path: root/video/out/gl_video_shaders.glsl
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-05-26 01:48:39 +0200
committerwm4 <wm4@nowhere>2013-05-26 16:44:20 +0200
commit58a7d81dc55835fb0f5cc6a3f14288d722f83c91 (patch)
tree2f7cce21b79b6685348aca207938512cb2917814 /video/out/gl_video_shaders.glsl
parent39225ed19676aa054aa36eb1e09b72ec712ae368 (diff)
downloadmpv-58a7d81dc55835fb0f5cc6a3f14288d722f83c91.tar.bz2
mpv-58a7d81dc55835fb0f5cc6a3f14288d722f83c91.tar.xz
gl_video: improve dithering
Use a different algorithm to generate the dithering matrix. This looks much better than the previous ordered dither matrix with its cross-hatch artifacts. The matrix generation algorithm as well as its implementation was contributed by Wessel Dankers aka Fruit. The code in dither.c is his implementation, reformatted and with static global variables removed by me. The new matrix is uploaded as float texture - before this commit, it was a normal integer fixed point matrix. This means dithering will be disabled on systems without float textures. The size of the dithering matrix can be configured, as the matrix is generated at runtime. The generation of the matrix can take rather long, and is already unacceptable with size 8. The default is at 6, which takes about 100 ms on a Core2 Duo system with dither.c compiled at -O2, which I consider just about acceptable. The old ordered dithering is still available and can be selected by putting the dither=ordered sub-option. The ordered dither matrix generation code was moved to dither.c. This function was originally written by Uoti Urpala.
Diffstat (limited to 'video/out/gl_video_shaders.glsl')
-rw-r--r--video/out/gl_video_shaders.glsl7
1 files changed, 6 insertions, 1 deletions
diff --git a/video/out/gl_video_shaders.glsl b/video/out/gl_video_shaders.glsl
index b968cb2c87..c19a19fbee 100644
--- a/video/out/gl_video_shaders.glsl
+++ b/video/out/gl_video_shaders.glsl
@@ -121,6 +121,7 @@ uniform sampler2D lut_l_2d;
uniform sampler3D lut_3d;
uniform sampler2D dither;
uniform mat4x3 colormatrix;
+uniform mat2 dither_trafo;
uniform vec3 inv_gamma;
uniform float input_gamma;
uniform float conv_gamma;
@@ -376,7 +377,11 @@ void main() {
color.rgb = srgb_compand(color.rgb);
#endif
#ifdef USE_DITHER
- float dither_value = texture(dither, gl_FragCoord.xy / dither_size).r;
+ vec2 dither_pos = gl_FragCoord.xy / dither_size;
+#ifdef USE_TEMPORAL_DITHER
+ dither_pos = dither_trafo * dither_pos;
+#endif
+ float dither_value = texture(dither, dither_pos).r;
color = floor(color * dither_multiply + dither_value ) / dither_quantization;
#endif
#ifdef USE_ALPHA