#version 330 uniform sampler2D texture0; in vec2 fragTexCoord; out vec4 finalColor; const float neareight = 255.0; vec3 dither(vec3 col, uvec2 fc) { const int mat[16] = int[16] ( -4, 0, -3, 1, 2, -2, 3, -1, -3, 1, -4, 0, 3, -1, 2, -2 ); ivec3 uncol = ivec3(col * neareight) + mat[(fc.y & uint(3)) * uint(4) + (fc.x & uint(3))]; return vec3(uncol) / neareight; } vec3 band_color(vec3 lol) { ivec3 res = ivec3(clamp(lol, 0.0, 1.0) * neareight) & ivec3(0xFF); ivec3 ires = res >> 3; ivec3 dres = (ires >> 2) & ivec3(7); res = (ires << 3) | dres; return vec3(res) / neareight; } void main() { vec4 texelColor = texture(texture0, fragTexCoord); texelColor.rgb = band_color(dither(texelColor.rgb, uvec2(gl_FragCoord.xy))); finalColor = texelColor; }