-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathv002.dither2.frag
42 lines (33 loc) · 987 Bytes
/
v002.dither2.frag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Ordered dithering aka Bayer matrix dithering
#version 120
uniform sampler2DRect tex0;
varying vec2 texcoord0;
uniform float greyscale;
uniform float scale;
uniform int dither[4];
const vec4 lumacoeff = vec4(0.2126,0.7152,0.0722, 0.0);
float find_closest(int x, int y, float c0, int thing[4])
{
float limit = 0.0;
if(x < 2)
{
limit = (thing[(x * 2) + y]+1)/64.0;
}
if(c0 < limit)
return 0.0;
return 1.0;
}
void main(void)
{
vec4 rgb = texture2DRect(tex0, texcoord0);
float grayscale = dot(rgb, lumacoeff);
vec2 xy = gl_FragCoord.xy * scale;
int x = int(mod(xy.x, 2));
int y = int(mod(xy.y, 2));
vec3 finalRGB;
finalRGB.r = find_closest(x, y, rgb.r, dither);
finalRGB.g = find_closest(x, y, rgb.g, dither);
finalRGB.b = find_closest(x, y, rgb.b, dither);
float final = find_closest(x, y, grayscale, dither);
gl_FragColor = vec4( mix(finalRGB,vec3(final), greyscale), rgb.a);
}