diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-13 13:58:37 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-13 13:58:37 +0200 |
commit | 57155f2c36b3a4069d3f27b27e4caf4420a76315 (patch) | |
tree | 83d4f0cadc90b3e2753a31e76ae89504fe1d33c5 | |
parent | 8f5e37a68ca9f8dc2e2451b243005246625ffc35 (diff) |
effect kinda working
-rw-r--r-- | consts.h | 3 | ||||
-rw-r--r-- | fb.c | 4 | ||||
-rw-r--r-- | pass1.frag | 31 |
3 files changed, 30 insertions, 8 deletions
@@ -8,4 +8,7 @@ #define U_LOC_PASS1 2 #define U_LOC_WINDOW 3 +#define PI 3.141592653589793 +#define PI_2 6.283185307179586 + #endif @@ -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"); @@ -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; } |