aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources/shaders/flow.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/resources/shaders/flow.glsl')
-rw-r--r--src/main/resources/shaders/flow.glsl68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/main/resources/shaders/flow.glsl b/src/main/resources/shaders/flow.glsl
new file mode 100644
index 0000000..fe0aaad
--- /dev/null
+++ b/src/main/resources/shaders/flow.glsl
@@ -0,0 +1,68 @@
+#version 430
+layout(local_size_x = 1, local_size_y = 1) in;
+
+#include <utils>
+#include <noise>
+
+uniform float seconds = 0;
+layout(rgba8) uniform readonly image2D noise_texture;
+layout(rgba8) uniform writeonly image2D output_image;
+
+uniform float antialiasing = 0.28;
+uniform bool enable_antialiasing = false;
+
+float sample_noise(in vec2 p) {
+ vec4 noise = imageLoad(noise_texture, ivec2(p * imageSize(noise_texture)));
+ return noise.x;
+}
+
+vec3 image(vec2 uv) {
+ const vec3 bg_color = srgb(0.10, 0.10, 0.14);
+ const vec3 line1_color = srgb(0.2, 0.25, 0.4);
+ const vec3 line2_color = srgb(0.8, 0.3, 0.4);
+
+ vec3 color = bg_color;
+
+ float line_thickness = 0.04;
+ vec2 p = (vec2(uv.y, uv.x)) * 50;
+ int max = 40;
+ float t = mod(seconds, 12) * 0.7;
+
+ vec3 l1c = line1_color;
+ vec3 l2c = line2_color;
+
+ for (int i = 0; i < max; i++) {
+ float a = i * PI * (1 + t / 10) / 62;
+ float r = 5 * sin(a + t / 6) * sin(a + t / 6);
+ vec2 off = r * vec2(cos(a), sin(a)) + (1 + t / 1000.) * i * 0.2;
+ vec2 pos = (p + off) * mat2x2(cos(a), -sin(a), sin(a), cos(a));
+ float line = abs(sin(pos.x * (0.7 + 0.3 * fbm(p / 10)) + t * 2) / 3 - pos.y) - line_thickness;
+ vec3 line_color = mix(l1c, l2c, smoothstep(0, 1, float(i - 1) / (2. * max)));
+ color = mix(color, line_color, step(line, 0));
+ }
+
+ // color = mix(color, vec3(1), step(mixer, 0));
+
+ return color;
+}
+
+vec3 antialiased_image(vec2 uv) {
+ vec2 resolution = vec2(imageSize(output_image).xy);
+ float s = antialiasing / max(resolution.x, resolution.y);
+ vec3 sum = vec3(0);
+ int count = 0;
+ for (int i = -2; i < 2; i++)
+ for (int j = -2; j < 2; j++, count++)
+ sum += image(uv + vec2(i, j) * s);
+ return sum / count;
+}
+
+void main() {
+ vec2 resolution = vec2(imageSize(output_image).xy);
+ float aspect_ratio = resolution.y / resolution.x;
+ vec2 uv = (gl_GlobalInvocationID.xy - resolution / 2) * vec2(1.0, aspect_ratio) / resolution;
+
+ vec3 color = enable_antialiasing ? antialiased_image(uv) : image(uv);
+
+ imageStore(output_image, ivec2(gl_GlobalInvocationID.xy), vec4(color, 1));
+}