aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fb.c2
-rw-r--r--pass1.frag43
-rw-r--r--pass2.frag6
3 files changed, 38 insertions, 13 deletions
diff --git a/fb.c b/fb.c
index f072ad9..e9ebcdc 100644
--- a/fb.c
+++ b/fb.c
@@ -18,6 +18,8 @@ GLuint init_fb() {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, RES_H, RES_V, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, buffer, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
die("can't initialize framebuffer??\n");
diff --git a/pass1.frag b/pass1.frag
index 8917b61..a6b22e0 100644
--- a/pass1.frag
+++ b/pass1.frag
@@ -9,22 +9,25 @@ 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.04;
+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 = 20.0; // circle radius
-
- vec2 norm = (uv - 0.5) * 2.0;
- norm.x *= float(res.x) / float(res.y); // adjust for aspect ratio
- float offset = time * 7.0;
+ 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 mag = 1.3 + 0.5 * sin(2 * time);
- float size = 0.4 + 0.1 * sin(3 * time);
+ float offset = time * 1.0;
- color = vec4(0.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>
@@ -33,11 +36,27 @@ void main() {
sin(t) + mag * sin(turns * t + offset)
);
f *= size;
- if (length(f - norm) < 0.01) {
- color = vec4(1.0, 1.0, 1.0, 1.0);
+ if (length(f - gc) < r) {
+ color += vec4(white, 1.0);
}
}
- color += texture(buf, ((uv - 0.5) * 0.99) + 0.5) * 0.97;
+ // 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.98;
}
diff --git a/pass2.frag b/pass2.frag
index 3184475..78c1f75 100644
--- a/pass2.frag
+++ b/pass2.frag
@@ -9,8 +9,12 @@ layout(location = U_LOC_TIME) uniform float time;
layout(location = U_LOC_PASS1) uniform sampler2D buf;
layout(location = U_LOC_WINDOW) uniform ivec2 window;
+const vec4 color_a = vec4(0.15, 0.50, 0.90, 1.0);
+const vec4 color_b = vec4(0.90, 1.00, 0.90, 1.0);
+
void main() {
vec2 uv = gl_FragCoord.xy / window.xy;
- color = texture(buf, uv);
+ float val = texture(buf, uv)[0];
+ color = mix(color_a, color_b, val); // map b/w colors to gradient
}