Metaballs

glint · Examples · Tutorials · Gallery

Liquid blobs, one per frequency band, merging and swelling with the music.

Audio-reactive: it moves with music from a microphone, line-in or a file.

Metaballs: an audio-reactive GLSL shader

An example in glint, a free live shader editor in the browser: the GLSL code floats over the running picture and recompiles as you type.

The code

One pass, in GLSL.

fragment shader

#version 300 es
precision highp float;

uniform float time;
uniform vec2 resolution;
uniform vec3 spectrum;
uniform vec3 spectrumIntegrated;
uniform float beat;
uniform int beatCount;
uniform sampler2D fft;

in vec2 v_texcoord;
out vec4 fragColor;

void main() {
    vec2 uv = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y;
    float field = 0.0;
    vec3 tint = vec3(0.0);
    for (int i = 0; i < 8; i++) {
        float fi = float(i);
        float level = texture(fft, vec2(0.01 + fi * 0.05, 0.25)).r;
        vec2 c = 0.45 * vec2(sin(time * (0.3 + fi * 0.07) + fi * 2.0), cos(time * (0.4 + fi * 0.05) + fi));
        float r = 0.06 + 0.1 * level + 0.03 * beat;
        float k = r * r / dot(uv - c, uv - c);
        field += k;
        tint += k * (0.5 + 0.5 * cos(6.28318 * (fi / 8.0 + vec3(0.0, 0.33, 0.67))));
    }
    tint /= field;
    float inside = smoothstep(0.9, 1.1, field);
    float rim = smoothstep(0.15, 0.0, abs(field - 1.0));
    vec3 col = tint * inside * (0.6 + 0.4 * spectrum.x) + rim * vec3(1.0) * 0.6;
    col += vec3(0.02, 0.0, 0.05) * (1.0 - inside);
    fragColor = vec4(col, 1.0);
}

More Starters examples

Radial spectrum · Ridgelines · Kaleido pulse · Laser show · Oscilloscope trails · Hyperspace · Strobe grid