more 'correct' dithering equation

This commit is contained in:
minjaesong
2022-04-12 11:16:58 +09:00
parent 9b2d85c640
commit b92b53352b
3 changed files with 13 additions and 26 deletions

View File

@@ -5,7 +5,7 @@
#version 130
#ifdef GL_ES
precision mediump float;
precision mediump float;
#endif
@@ -26,7 +26,7 @@ uniform ivec2 rnd = ivec2(0,0);
uniform float quant = 255.0; // 64 steps -> 63.0; 256 steps -> 255.0
vec2 boolean = vec2(0.0, 1.0);
vec4 halfvec = vec4(0.5);
vec4 matrixNormaliser = vec4(0.5 / 256.0);
vec2 patternsize = vec2(1.0/512.0, 1.0/512.0);
@@ -46,11 +46,11 @@ mat4 ycocg_to_rgb = mat4(
vec4 nearestColour(vec4 inColor) {
return floor(vec4(quant) * inColor + halfvec) * vec4(1.0 / quant);
return floor(vec4(quant) * inColor) * vec4(1.0 / quant);
}
vec4 getDitherredDot(vec4 inColor) {
vec4 bayerThreshold = vec4(texture2D(u_pattern, (gl_FragCoord.xy + rnd) * patternsize) - 0.5);
vec4 bayerThreshold = vec4(matrixNormaliser + texture2D(u_pattern, (gl_FragCoord.xy + rnd) * patternsize));
return nearestColour(bayerThreshold * vec4(1.0 / quant) + inColor);
}