summaryrefslogtreecommitdiffstats
path: root/examples/symmetry.frag
blob: 26f46510983b32b70af7d28f00bf24cbd9c547f4 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#version 330

out vec4 fragColor;

uniform vec2 res;
uniform float time;

uniform int param0;
uniform int param1;
uniform int param2;

const float sharpness = 300;

const float PI = 3.14159265358979323846;


mat3 rot(float a) {
	return mat3(
		cos(a), -sin(a), 0,
		sin(a), cos(a), 0,
		0, 0, 1
	);
}

mat3 scale(float s) {
	return mat3(
		s, 0, 0,
		0, s, 0,
		0, 0, 1
	);
}

mat3 trans(float x, float y) {
	return mat3(
		1, 0, x,
		0, 1, y,
		0, 0, 1
	);
}

float square(vec3 p) {
	float d = max(abs(p.x), abs(p.y));

	return clamp((1 - d)*sharpness, 0.0, 1.0);
}


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

	float scene = 0;

	int n = param0 + 32;
	float k = param1;

	for (int i = 0; i < n; i++) {
		mat3 t = scale(0.3 + 0.02 * param2)
		       * rot(-PI/2*(k*i/n + time/1500))
		       * trans(0.5, 0.0)
		       * rot(2*PI*i/n)
		       * scale(1 / (1 + 0.03 * param2));

		float c = square(p * inverse(t));
		scene = abs(scene - c);
	}

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