aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--consts.h3
-rw-r--r--fb.c4
-rw-r--r--pass1.frag31
3 files changed, 30 insertions, 8 deletions
diff --git a/consts.h b/consts.h
index ea4dbbe..6acab4c 100644
--- a/consts.h
+++ b/consts.h
@@ -8,4 +8,7 @@
#define U_LOC_PASS1 2
#define U_LOC_WINDOW 3
+#define PI 3.141592653589793
+#define PI_2 6.283185307179586
+
#endif
diff --git a/fb.c b/fb.c
index 479808c..f072ad9 100644
--- a/fb.c
+++ b/fb.c
@@ -16,8 +16,8 @@ GLuint init_fb() {
glGenTextures(1, &buffer);
glBindTexture(GL_TEXTURE_2D, buffer);
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_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
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 784a9a2..8917b61 100644
--- a/pass1.frag
+++ b/pass1.frag
@@ -9,16 +9,35 @@ 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 turns = 9.0;
+
void main() {
- vec2 point = vec2(sin(time), cos(time)) * 0.7;
- point.x *= float(res.y) / float(res.x); // adjust for aspect ratio
- point = ((point + 1.0) / 2.0) * res.xy; // convert to screen coords
+ 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 mag = 1.3 + 0.5 * sin(2 * time);
+ float size = 0.4 + 0.1 * sin(3 * time);
color = vec4(0.0);
- if (length(gl_FragCoord.xy - point) < r)
- color = vec4(1.0);
- color += texture(buf, gl_FragCoord.xy / res.xy) * 0.95;
+ 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 - norm) < 0.01) {
+ color = vec4(1.0, 1.0, 1.0, 1.0);
+ }
+ }
+
+ color += texture(buf, ((uv - 0.5) * 0.99) + 0.5) * 0.97;
}