aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources/shaders/cloak.glsl
blob: c249760b1d62601b68a85ed475e0a38481014324 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#version 430
layout(local_size_x = 1, local_size_y = 1) in;

#include <utils>
#include <noise>

#define PI 3.14159265358979323

const float antialiasing = 0.28;
uniform float seconds = 0;
layout(rgba8) uniform writeonly image2D output_image;

vec3 background = srgb(1, 0.99, 0.91);
vec3 body = srgb(0.15, 0.19, 0.30);
vec3 bodyaccent1 = srgb(0.099, 0.099, 0.16);
vec3 bodyaccent2 = srgb(0.83, 0.69, 0.22);
vec3 bgaccent1 = srgb(0.15, 0.19, 0.30);
vec3 bgaccent2 = srgb(0.4, 0.1, 0.18);
vec3 bgaccent3 = srgb(0.31, 0.78, 0.41);

vec3 image(vec2 uv) {
  vec2 p = uv * 7 - vec2(0, 0);

  vec3 color = background;

  float overhood = 2.4 - p.y - 0.86 * p.x * p.x;
  float bodycut = 0.0 + p.y + 0.12 * p.x * p.x * p.x * p.x;

  float cloak = cos(atan(p.x * p.x + p.y, p.y) * 24 + 8 * p.y) - 0.4;
  float clothtexture = sin(240 * (p.x - 1)) * cos(240 * (p.y - 1)) * (fbm(400 * p) - 0.42);
  vec3 patterncolor = mix(bodyaccent2, bodyaccent1, smoothstep(cloak - 0.01 * fbm(uv * 100), 0.6, 0.594));
  color = mix(color, patterncolor, step(bodycut, 0));
  color = mix(color, mix(mix(body, vec3(0), step(-cloak, 0.34)), mix(body, vec3(0), 0.6), step(clothtexture, 0)), step(cloak, 0));

  float yoff = 2.951;
  float cutshape = abs(cos(0.18 * (p.y + yoff) * (p.y + yoff))) + 1.37;
  float xc = 1.10;
  float overhoodcut = min(cutshape - xc * p.x, cutshape + xc * p.x);
  overhood = min(overhood, max(-cloak, 2.1 - p.y - 1.06 * p.x * p.x));
  overhood = min(overhood, overhoodcut);
  vec2 noisep = p;
  float noisy1 = fbm(8 * noisep * fbm(0.8 * noisep * fbm(2.2 * noisep))) - 0.36;
  float noisy2 = fbm(8 * noisep * fbm(noisep * fbm(2.2 * noisep))) - 0.38;
  float noisy3 = fbm(8 * noisep * fbm(0.8 * noisep * fbm(2.2 * noisep))) - 0.39;
  vec3 bgcolor = background;
  bgcolor = mix(bgcolor, bgaccent3, step(noisy3, 0));
  bgcolor = mix(bgcolor, bgaccent1, step(noisy1, 0));
  bgcolor = mix(bgcolor, bgaccent2, step(noisy2, 0));
  color = mix(color, bgcolor, step(overhood, 0));
  color = mix(color, mix(bgcolor, mix(bgcolor, body, 0.70), step(cloak, 0)), step(overhood, 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 = image(uv);
  vec3 color = antialiased_image(uv);
  imageStore(output_image, ivec2(gl_GlobalInvocationID.xy), vec4(color, 1));
}