0.00
60.0 fps

Slime Vectors

An attempt at a demo effect

Log in to post a comment.

#version 300 es
precision highp float;

uniform float iTime;
uniform vec2  iResolution;
out vec4 fragColor;

// 2×2 rotation matrix
mat2 rot(float a) {
    float c = cos(a), s = sin(a);
    return mat2(c, -s, s, c);
}

// Metaball contribution: radius ÷ distance
float metaball(vec2 p, vec2 c, float r) {
    return r / length(p - c);
}

// Simple HSV→RGB palette cycling
vec3 palette(float t) {
    return vec3(
        0.5 + 0.5 * cos(6.2831*(t + 0.00)),
        0.5 + 0.5 * cos(6.2831*(t + 0.33)),
        0.5 + 0.5 * cos(6.2831*(t + 0.67))
    );
}

void main() {
    // normalize coords to [-1,+1], preserve aspect
    vec2 uv = (gl_FragCoord.xy / iResolution.xy) * 2.0 - 1.0;
    uv.x *= iResolution.x / iResolution.y;

    float t = iTime * 0.6;

    // generate 5 orbiting blob centers
    vec2 centers[5];
    for (int i = 0; i < 5; i++) {
        float ang = t * (1.0 + float(i)*0.3) + float(i)*1.2;
        centers[i] = rot(ang) * vec2(0.5, 0.0);
    }

    // accumulate metaball field
    float field = 0.0;
    for (int i = 0; i < 5; i++) {
        field += metaball(uv, centers[i], 0.3);
    }

    // smooth threshold to get a soft outline
    float iso = smoothstep(1.8, 2.0, field);

    // drive colour by field + time
    float cpos = fract(field * 0.2 - t*0.1);
    vec3 col = palette(cpos);

    fragColor = vec4(col * iso, 1.0);
}