Particle fountain

glint · Examples · Tutorials · Gallery

Twenty thousand points with no mesh and no state: each one works out where it is from gl_VertexID and time (launch, gravity, fade) in the vertex shader. It surges with the bass.

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

Particle fountain: 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.

vertex shader

#version 300 es
uniform mat4 mvp;
uniform float time;
uniform vec3 spectrum;
uniform float beat;
uniform int beatCount;

out vec3 v_color;
out float v_fade;

float hash(float n) { return fract(sin(n * 127.1) * 43758.5453); }

void main() {
    float id = float(gl_VertexID);
    float life = 3.0;
    // Each particle is born at its own moment and relaunched every 3 s.
    float age = mod(time + hash(id) * life, life);
    float a = hash(id + 0.5) * 6.28318, spread = 0.7 * sqrt(hash(id + 0.7));
    float kick = beatCount > 0 ? beat : pow(1.0 - fract(time * 2.0), 4.0);
    float up = 3.0 + hash(id + 0.9) * 0.6 + spectrum.x * 1.5 + kick * 0.4;
    vec3 v = vec3(cos(a) * spread, up, sin(a) * spread);
    vec3 p = v * age + vec3(0.0, -1.6, 0.0) * age * age;       // gravity
    p.y -= 1.2;
    gl_Position = mvp * vec4(p, 1.0);
    gl_PointSize = max(1.5, 12.0 / gl_Position.w);
    v_fade = (1.0 - age / life) * step(-1.3, p.y);
    v_color = 0.5 + 0.5 * cos(6.28318 * (age * 0.2 + vec3(0.55, 0.65, 0.75)));
}

fragment shader

#version 300 es
precision highp float;

in vec3 v_color;
in float v_fade;
out vec4 fragColor;

void main() {
    vec2 c = gl_PointCoord - 0.5;
    float soft = smoothstep(0.25, 0.0, dot(c, c));
    fragColor = vec4(v_color * soft * v_fade * 0.8, 1.0);
}

More Audio-reactive examples

Shockwave · Pendulum wave · Beat cells · Spectrum tree · VU meters · Ring tunnel · Light curtain · Halftone spectrum