summaryrefslogtreecommitdiffstats
path: root/examples/supersnail.frag
blob: dd0f77c5cae618851cce1ca9f126d26bc915fed7 (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
#version 330

out vec4 fragColor;

uniform vec2 res;
uniform float time;

const float sharpness = 300;

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

float circle(vec2 m, float r, vec2 p) {
	vec2 diff = m - p;
	float d = sqrt(dot(diff, diff));

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

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

	float scene = 0;

	for (int i = 1; i <= 100; i++) {
		float c = circle(vec2(0.5, 0) * rot(time/200/i), 0.1 + 0.002*i, p);
		scene = abs(scene - c);
	}

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