aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources/shaders/mitosis.glsl
blob: 7d0d3737b54e60dafe27f3baa30c7bb5afafa28e (plain) (blame)
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
#version 430
layout(local_size_x = 1, local_size_y = 1) in;

#include <utils>

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 = true;

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.16, 0.16, 0.21);
  const vec3 color1 = srgb(0.09, 0.57, 0.6);
  const vec3 color2 = srgb(0.31, 0.23, 0.64);
  const vec3 color3 = srgb(0.82, 0.06, 0.22);

  float duration = 10.0;
  float t = mod(seconds, duration) - duration / 2;
  t *= 0.5;

  vec3 color = bg_color;
  vec2 p = uv * 11.6;
  float v = 1 - (sin(p.x * p.x) - sin(p.y * p.y) - sin(t * p.x * p.y));
  color = mix(color, color1, step(v, 1.4));
  color = mix(color, color2, step(v, 1.1));
  color = mix(color, color3, step(v, 0.84));
  color = mix(color, color2, step(v, 0.6));
  color = mix(color, color1, step(v, 0.3));
  color = mix(color, bg_color, step(v, 0.1));

  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));
}