-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path4x4.glsl
39 lines (33 loc) · 1.07 KB
/
4x4.glsl
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
#pragma glslify: luma = require(glsl-luma)
float dither4x4(vec2 position, float brightness) {
int x = int(mod(position.x, 4.0));
int y = int(mod(position.y, 4.0));
int index = x + y * 4;
float limit = 0.0;
if (x < 8) {
if (index == 0) limit = 0.0625;
if (index == 1) limit = 0.5625;
if (index == 2) limit = 0.1875;
if (index == 3) limit = 0.6875;
if (index == 4) limit = 0.8125;
if (index == 5) limit = 0.3125;
if (index == 6) limit = 0.9375;
if (index == 7) limit = 0.4375;
if (index == 8) limit = 0.25;
if (index == 9) limit = 0.75;
if (index == 10) limit = 0.125;
if (index == 11) limit = 0.625;
if (index == 12) limit = 1.0;
if (index == 13) limit = 0.5;
if (index == 14) limit = 0.875;
if (index == 15) limit = 0.375;
}
return brightness < limit ? 0.0 : 1.0;
}
vec3 dither4x4(vec2 position, vec3 color) {
return color * dither4x4(position, luma(color));
}
vec4 dither4x4(vec2 position, vec4 color) {
return vec4(color.rgb * dither4x4(position, luma(color)), 1.0);
}
#pragma glslify: export(dither4x4)