aboutsummaryrefslogtreecommitdiff
path: root/pass1.frag
blob: f00cdcf3fb2e06e6d17af791509d294211ade2e4 (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
#version 460 core

#include "consts.h"

layout(location = 0) out vec4 color;
in vec4 gl_FragCoord;

layout(location = U_LOC_TIME) uniform float time;
layout(location = U_LOC_PASS1) uniform sampler2D buf;
ivec2 res = ivec2(RES_H, RES_V);

const float step = 0.03;
const float turns = 9.0;

const vec3 white = vec3(1.0, 1.0, 1.0);
const vec3 black = vec3(0.0, 0.0, 0.0);

void main() {
	color = vec4(black, 0.0);
	vec2 uv = gl_FragCoord.xy / res.xy;

	float r = 0.007; // circle radius
	
	vec2 gc = (uv - 0.5) * 2.0; // graph coordinates (-1,-1) to (1,1)
	gc.x *= float(res.x) / float(res.y); // adjust circle aspect ratio

	float offset = time * 1.0;

	float mag = 1.3 + 0.5 * sin(2 * time); // braid ratio
	float size = 0.4 + 0.1 * sin(3 * time); // total size

	for (float t = 0.0; t < PI_2; t += step) {
		// <https://www.desmos.com/calculator/e0kq6z1ndd>
		vec2 f = vec2(
			cos(t) + mag * cos(turns * t + offset),
			sin(t) + mag * sin(turns * t + offset)
		);
		f *= size;
		if (length(f - gc) < r) {
			color += vec4(white, 1.0);
		}
	}

	// create border
	if (uv.x < 0.002) color += vec4(white * 0.7, 1.0);
	if (uv.y < 0.002) color += vec4(white * 0.7, 1.0);
	if (uv.x > 0.998) color += vec4(white * 0.7, 1.0);
	if (uv.y > 0.998) color += vec4(white * 0.7, 1.0);
	
	vec2 fbuv = uv; // framebuffer transformed uv

	const float sway = 0.1;
	fbuv -= 0.5; // center at (0,0)
	const float angle = 0.04 * sin(sway * time);
	fbuv *= mat2(cos(angle), -sin(angle), sin(angle), cos(angle)); // rotate
	fbuv *= 1.0 + 0.02 * sin(2 * sway * time); // zoom out
	fbuv += 0.5; // restore center

	// add transformed version of previous frame on top
	color += texture(buf, fbuv) * 0.99;
}