summaryrefslogtreecommitdiffstats
path: root/examples/checkers.frag
blob: 2e427041b4b88f803886003e1e8c70ab4f19f331 (plain)
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
#version 130

out vec4 fragColor;

uniform vec2 res;
uniform float time;

const float sharpness = 300;

const float PI = 3.14159265358979323846;


mat2 rot(float a) {
	return mat2(
		cos(a), -sin(a),
		sin(a), cos(a)
	);
}

void main(void) {
	vec2 m = res/2;
	float s = min(m.x, m.y);
	vec2 p = (gl_FragCoord.xy - m) / s;

	float repeat = 8.0;
	float time_mod = mod(time / 300, repeat);
	float w = 20 * pow(2, time_mod);

	float f = time_mod / repeat;
	vec2 pr = p * rot(f * PI/2);

	float tp = mod(floor(log2(abs(pr.x/w)) + floor(log2(abs(pr.y/w)))), 2);

	float darken = min(min(abs(pr.x), abs(pr.y)) / 0.01, 1.0);

	float scene = tp * darken;

	fragColor = vec4(vec3(1, 1, 1) * scene, 1);
}