The Code Therapy

The Pool

It's like a pool, but not so much

Created by marcogomez on Fri, 19 Jan 2024 00:36:02 GMT.


#version 300 es
precision highp float;
uniform sampler2D prgm4Texture;
uniform vec2 resolution;

in vec2 vUv;
out vec4 fragColor;

void main(void) {
  vec4 texture1 = texture(prgm4Texture, vUv);
  fragColor = texture1;
}

#version 300 es
precision highp float;
uniform float time;
uniform vec2 resolution;

in vec2 vUv;
out vec4 fragColor;

const float PI = acos(-1.0);
const float TAU = PI * 2.0;
const int max_iter = 5;
const vec3 wc = vec3(0.1, 0.3, 0.5);

void main(void) {
  float t1 = time * 0.5 + 23.0;
  vec2 uv = vUv;
  vec2 p = mod(uv * TAU, TAU) - 250.0;
  p.x += sin(1.5 * p.y + time) * 0.42;
  p.y += cos(1.5 * p.x + time) * 0.42;
  vec2 i = vec2(p);
  float c = 1.0;
  float inten = 0.0042;
  for (int n = 0; n < max_iter; n++) {
    float t = t1 * (1.0 - (3.5 / float(n + 1)));
    i = p + vec2(
      cos(t - i.x) + sin(t + i.y),
      sin(t - i.y) + cos(t + i.x)
    );
    c += 1.0 / length(
      vec2(
        p.x / (sin(i.x + t) / inten),
        p.y / (cos(i.y + t) / inten)
      )
    );
  }
  c /= float(max_iter);
  c = 1.17 - pow(abs(c), 1.4);
  vec3 col = vec3(pow(abs(c), 8.0));
  col = clamp(col + wc, 0.0, 1.0);
  fragColor = vec4(col * col + wc * 0.3, 1.0);
}

#version 300 es
precision highp float;
uniform sampler2D prgm2Texture;
uniform sampler2D prgm3Texture;
uniform vec2 resolution;
uniform vec2 mouse;
uniform int frame;
uniform float time;

in vec2 vUv;
out vec4 fragColor;

void main(void) {
  vec2 mp = vec2(
    ((mouse.x + 1.0) * 0.5) * resolution.x,
    ((mouse.y + 1.0) * 0.5) * resolution.y
  );
  vec3 e = vec3(vec2(1.0) / resolution.xy, 0.0);
  vec2 q = vUv;
  vec4 c = texture(prgm2Texture, q);
  float p11 = c.x;
  float p10 = texture(prgm3Texture, q - e.zy).x;
  float p01 = texture(prgm3Texture, q - e.xz).x;
  float p21 = texture(prgm3Texture, q + e.xz).x;
  float p12 = texture(prgm3Texture, q + e.zy).x;
  float d = 0.0;
  d = smoothstep(64.0, 0.5, length(mp.xy - gl_FragCoord.xy));
  d += -(p11 - 0.5) * 2.0 + (p10 + p01 + p21 + p12 - 2.0);
  d *= 0.99;
  d *= max(min(1.0, float(frame)), 0.0) * clamp(time - 0.5, 0.0, 1.0);
  d = d * 0.5 + 0.5;
  fragColor = vec4(d, 0.0, 0.0, 1.0);
}

#version 300 es
precision highp float;
uniform sampler2D prgm2Texture;
uniform sampler2D prgm3Texture;
uniform vec2 resolution;
uniform vec2 mouse;
uniform int frame;
uniform float time;

in vec2 vUv;
out vec4 fragColor;

void main(void) {
  vec2 mp = vec2(
    ((mouse.x + 1.0) * 0.5) * resolution.x,
    ((mouse.y + 1.0) * 0.5) * resolution.y
  );
  vec3 e = vec3(vec2(1.0) / resolution.xy, 0.0);
  vec2 q = vUv;
  vec4 c = texture(prgm3Texture, q);
  float p11 = c.x;
  float p10 = texture(prgm2Texture, q - e.zy).x;
  float p01 = texture(prgm2Texture, q - e.xz).x;
  float p21 = texture(prgm2Texture, q + e.xz).x;
  float p12 = texture(prgm2Texture, q + e.zy).x;
  float d = 0.0;
  d = smoothstep(64.0, 0.5, length(mp.xy - gl_FragCoord.xy));
  d += -(p11 - 0.5) * 2.0 + (p10 + p01 + p21 + p12 - 2.0);
  d *= 0.999999;
  d *= max(min(1.0, float(frame)), 0.0) * clamp(time - 0.5, 0.0, 1.0);
  d = d * 0.5 + 0.5;
  fragColor = vec4(d, 0.0, 0.0, 1.0);
}

#version 300 es
precision highp float;
uniform sampler2D prgm3Texture;
uniform sampler2D prgm1Texture;
uniform vec2 resolution;
uniform vec2 mouse;
uniform int frame;

in vec2 vUv;
out vec4 fragColor;

void main(void) {
  float alpha = 1.0;
  vec2 mp = vec2(
    ((mouse.x + 1.0) *  0.5) * resolution.x,
    ((mouse.y + 1.0) * -0.5) * resolution.y
  );
  vec2 q = vUv;
  vec3 e = vec3( vec2( 1.0 ) / resolution.xy, 0.0 );
  float p10 = texture(prgm3Texture, q - e.zy).x;
  float p01 = texture(prgm3Texture, q - e.xz).x;
  float p21 = texture(prgm3Texture, q + e.xz).x;
  float p12 = texture(prgm3Texture, q + e.zy).x;
  vec3 grad = normalize(vec3(p21 - p01, p12 - p10, 1.0));
  vec4 c = texture(prgm1Texture, vUv + grad.xy * 0.35);
  vec3 light = normalize(vec3(0.2, -0.5, 0.7));
  float diffuse = dot(grad, light);
  float spec = pow(abs(max(0.0, -reflect(light, grad).z)), 32.0);
  vec4 col = mix(c, vec4(0.7, 0.8, 1.0, 1.0), 0.25) * max(diffuse, 0.0) + spec;
  float wh = texture(prgm3Texture, q).x;
  float wsh = 1.35 - wh * 2.0;
  vec3 wc = vec3(
    exp(pow(abs(wsh - 0.75), 2.0) * -10.0),
    exp(pow(abs(wsh - 0.50), 2.0) * -20.0),
    exp(pow(abs(wsh - 0.25), 2.0) * -10.0)
  );
  vec4 fc = mix(col, vec4(wc, 1.0), 0.0);
  fragColor = vec4(fc.rgb, 1.0);
}