Cube burst
glint · Examples · Tutorials · Gallery
Four hundred instanced cubes thrown outwards on every kick, tumbling and slowing with drag, then pulled back in for the next one.
Audio-reactive: it moves with music from a microphone, line-in or a file.

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
in vec4 a_position;
in vec3 a_normal;
uniform mat4 mvp;
uniform mat3 normalMatrix;
uniform float time;
uniform vec3 spectrum;
uniform float beat;
uniform float beatTime;
uniform int beatCount;
uniform sampler2D fft;
float kick() { return beatCount > 0 ? beat : pow(1.0 - fract(time * 2.0), 4.0); }
float sinceKick() { return beatCount > 0 ? beatTime : fract(time * 2.0) / 2.0; }
float kickId() { return beatCount > 0 ? float(beatCount) : floor(time * 2.0); }
bool silent() { return spectrum.x + spectrum.y + spectrum.z < 0.0001; }
float bin(float x) { return silent() ? 0.35 + 0.3 * sin(x * 40.0 - time * 3.0) : texture(fft, vec2(x, 0.25)).r; }
float hash(float n) { return fract(sin(n * 127.1) * 43758.5453); }
out vec3 v_normal;
out vec3 v_color;
mat3 rotate(vec3 axis, float a) {
axis = normalize(axis);
float s = sin(a), c = cos(a), oc = 1.0 - c;
return mat3(oc * axis.x * axis.x + c, oc * axis.x * axis.y + axis.z * s, oc * axis.z * axis.x - axis.y * s,
oc * axis.x * axis.y - axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z + axis.x * s,
oc * axis.z * axis.x + axis.y * s, oc * axis.y * axis.z - axis.x * s, oc * axis.z * axis.z + c);
}
void main() {
float id = float(gl_InstanceID) + kickId() * 0.37;
// A random direction (uniform on the sphere), a speed; out fast and slowing (drag).
float u = hash(id) * 2.0 - 1.0, phi = hash(id + 1.3) * 6.28318;
vec3 dir = vec3(sqrt(1.0 - u * u) * cos(phi), u, sqrt(1.0 - u * u) * sin(phi));
float s = sinceKick();
float dist = (0.6 + 1.6 * hash(id + 2.1)) * (1.0 - exp(-s * 4.0)) * (1.0 + spectrum.x);
mat3 r = rotate(vec3(hash(id + 3.0), hash(id + 4.0), hash(id + 5.0)) - 0.5, s * 6.0 * hash(id + 6.0) + id);
vec3 p = r * (a_position.xyz * 0.08) + dir * dist;
v_normal = normalMatrix * (r * a_normal);
v_color = 0.5 + 0.5 * cos(6.28318 * (hash(id + 7.0) * 0.5 + vec3(0.0, 0.33, 0.67)));
gl_Position = mvp * vec4(p, 1.0);
}fragment shader
#version 300 es
precision highp float;
in vec3 v_normal;
in vec3 v_color;
out vec4 fragColor;
void main() {
vec3 n = normalize(v_normal);
vec3 l = normalize(vec3(0.4, 0.9, 0.5));
float spec = pow(max(dot(reflect(-l, n), vec3(0.0, 0.0, 1.0)), 0.0), 24.0);
fragColor = vec4(v_color * (0.25 + 0.75 * max(dot(n, l), 0.0)) + spec * 0.4, 1.0);
}More Audio-reactive examples
Rising bubbles · Op art · Square tunnel · Waveform ring · Heartbeat · Disco ball · Grid pulses · Feedback mandala