-
Notifications
You must be signed in to change notification settings - Fork 6
/
color_dither.frag
48 lines (36 loc) · 1.21 KB
/
color_dither.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
43
44
45
46
47
48
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_noise;
uniform vec2 u_noiseResolution;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
// #define PLATFORM_WEBGL
// #define BLUENOISE_TEXTURE u_noise
// #define DITHER_PRECISION 4
// #define DITHER_CHROMA
// #define DITHER_TIME u_time
// #define DITHER_FNC ditherShift
// #define DITHER_FNC ditherVlachos
// #define DITHER_FNC ditherBlueNoise
// #define DITHER_FNC ditherTriangleNoise
// #define DITHER_FNC ditherInterleavedGradientNoise
// #define DITHER_FNC ditherBayer
#include "lygia/color/dither.glsl"
#include "lygia/math/mirror.glsl"
void main(void) {
vec4 color = vec4(vec3(0.0), 1.0);
vec2 pixel = 1.0/u_resolution.xy;
vec2 st = gl_FragCoord.xy * pixel;
float time = u_time;
// compress
const float c0 = 32.0;
vec2 its = mix( vec2(0.0), vec2(1.0) / c0, st );
color.rgb = mix(vec3(its.x), vec3(its.xy, 0.0), mirror(time * 0.025));
color.rgb = mix(color.rgb, dither(color.rgb), vec3(step(mirror(time * 0.13), (st.y + st.x) * 0.5)) );
// compress
color.rgb = floor( color.rgb * 255.0 ) / 255.0;
color.rgb *= c0;
gl_FragColor = color;
}