Sound you can see
glint · Examples · Tutorials · Gallery
Audio-reactive visuals: bass, mid and treble, the spectrum and waveform, beats, your own envelopes, motion that follows the music, tempo and bars, cutting on the beat, and an audio tunnel.
A free interactive course of 10 steps in glint, a live shader editor in the browser: each step changes a running shader, and ticks itself when you've done its task.
1. Turn the sound on
Open the Inputs panel (it's open now) and pick an audio source: your microphone, a music file, or on Chrome and Edge a browser tab or the whole system. Play something with a beat. glint listens and hands your shader numbers every frame.
The simplest is spectrum: three levels from 0 to 1. spectrum.x is the bass (below about 250 Hz: kicks, bass lines), .y the mids (voices, most instruments), .z the treble (hi-hats, sparkle).
Here the circle's radius is 0.15 + 0.3 * spectrum.x: silence gives 0.15, a loud bass up to 0.45. Without any audio everything sits still, which is fine: the code is the same.
If the levels look pinned at the top, lower the Gain in Inputs (or press Fit): it scales everything before your shader sees it.
Your turn: Let the mids choose the colour: vec3 c = mix(ORANGE, BLUE, spectrum.y);
2. The whole spectrum
Three numbers are a summary. The fft texture has the whole spectrum: 512 levels from the lowest frequencies on the left (x = 0) to the highest on the right (x = 1), in its first row. Read one with texture(fft, vec2(x, 0.25)).r (0.25 is the middle of row 0).
Here 64 bars each read their slice. Notice almost everything happens on the far left: in music, most of the energy and all the rhythm is in the low frequencies, while the right half is quiet shimmer.
Squaring x before reading (pow(x, 2.0)) spreads the low end across the screen and squeezes the highs, much closer to how we hear (our ears are logarithmic too).
Your turn: Spread out the low end: float x = pow(cell, 2.0);
3. The waveform
The second row of fft (read at y = 0.75) is the sound itself: the waveform, the speaker's position over the last few hundredths of a second. 0.5 is the speaker at rest, above and below is it pushing out and pulling in.
Drawing it is an oscilloscope: for each x, read the wave there and light the pixels near that height. Right now it reads row 0 by mistake (the spectrum), so the line hugs the bottom.
A pure tone looks like a smooth sine, a kick drum like a big slow swell, noise like grass. It's lovely in shaders as a line, a ring (wrap x round a circle), or a displacement.
Your turn: Read the waveform row: change 0.25 to 0.75 in the texture lookup.
4. Beats
Bass levels go up and down smoothly with the music. A beat is a moment: beat jumps to 1 when glint hears a kick (a sudden jump in the bass) and then fades back to 0. That shape, a sharp attack and a fade, is what makes visuals feel like they hit with the drums.
Use it to add, not to replace: a ring that's always there and kicks outwards on each beat reads better than one that only appears on beats.
The fade's shape and length are set per project in Inputs › Audio (exponential, linear, punch…, in seconds or in beats).
Your turn: Kick the ring outwards on each beat: float r = 0.25 + 0.12 * beat;
5. Your own envelope: beatTime
beat has one fade for the whole project. beatTime is the raw ingredient: the seconds since the last beat. From it you can shape any envelope you like, different for each thing on screen.
exp(-beatTime * k) is 1 on the beat and fades; k sets how fast: k = 3 takes about a third of a second to fall to a third, k = 10 is a snap. Worked example: 0.1 s after a beat, k = 3 gives exp(−0.3) ≈ 0.74, while k = 10 gives exp(−1) ≈ 0.37.
Other shapes: smoothstep(0.3, 0.0, beatTime) is a smooth half-second fall; step(beatTime, 0.05) is a 50 ms strobe.
Your turn: Make the squares snap: change the left one's decay from 3.0 to 10.0.
6. Moving with the music
It's tempting to spin something at time * spectrum.x: faster when the bass is loud. Try it and it jerks back and forth, because the angle is the whole elapsed time multiplied by the current level: when the bass drops from 0.5 to 0.4 after a minute, the angle jumps back by 6 radians.
spectrumIntegrated is the fix. It's a running total that adds the level every frame, so it only ever moves forwards, and moves faster when it's loud. Use it anywhere you'd use time but want the music to set the speed.
Worked example: 10 seconds of bass at 0.5 adds 5 to spectrumIntegrated.x; 10 seconds at 0.1 adds only 1. The stripes speed up with the music and never go backwards.
Your turn: Turn with the music, smoothly: float a = spectrumIntegrated.x;
7. In time: tempo and bars
beat only knows when a kick happened. glint also follows the tempo: bpm (beats per minute), beatPhase (0 at each beat, rising smoothly to 1 just before the next) and bar (which beat of the 4 in a bar this is: 0, 1, 2, 3).
Because beatPhase keeps moving between kicks, things driven by it stay in time even through quiet parts and breaks. 1.0 - beatPhase is a sawtooth: jumps up on the beat, falls steadily. At 120 bpm a beat lasts 0.5 s, so it falls from 1 to 0 in half a second.
No beat in the music? Tap one: Alt+T (or the tap button in Inputs › Tempo) on each beat sets it by hand.
Your turn: Pulse the lit square in time: float pulse = 1.0 - beatPhase;
8. Counting: change on the beat
beatCount counts every beat heard. Its remainder after dividing (beatCount % 3 gives 0, 1, 2, 0, 1, 2…) picks one of several things, so the picture changes on each beat: a cut, like a video edit.
Hard cuts on the beat are one of the most effective tricks in music visuals. Use % 4 with bar-length ideas, or (beatCount / 4) % 2 to change every 4 beats instead of every one.
Here k chooses the shape: 0 a circle, 1 a square, 2 a ring.
Your turn: Change shape on every beat: int k = beatCount % 3;
9. Taming the jitter
Raw levels twitch every frame. Two easy ways to make them feel musical: smoothing (Inputs › Audio › Smoothing, higher is calmer), and shaping in the shader.
smoothstep(0.2, 0.8, x) ignores the quiet part below 0.2, uses the full range between 0.2 and 0.8, and saturates above. It turns 'always a bit of bass' into 'nothing, then a clear push'. Worked example: a level of 0.3 becomes about 0.07, a level of 0.6 about 0.74.
pow(x, 2.0) does something similar more gently: quiet stays quieter, loud stands out.
Your turn: Shape the bass: float b = smoothstep(0.2, 0.8, spectrum.x);
10. All together: an audio tunnel
A tunnel is a classic: turn each pixel into an angle (atan) and a depth (1 / r: near the middle is far away). Stripes in depth that move forwards make it rush towards you.
Everything from this course goes in: the forward motion from spectrumIntegrated.x (rushes with the bass, never reverses), the colour from the mids, a flash on each beat, and the walls rippling with the waveform.
Right now it moves with plain time. Hand the speed to the music.
Your turn: Rush with the bass: float z = 1.0 / r + spectrumIntegrated.x * 2.0;
Other courses: Basics · Medium · Advanced · Maths for shaders · Raymarching, step by step · Matrices, from scratch · Noise from scratch · Colour and light · Passes and feedback · Skies and reflections · Vertex shaders, step by step · Raymarching 2: glow, fog and light · Raymarching 3: worlds · Raymarching 4: modelling, materials and motion · Fractals, step by step · Vertex shaders 2: lines, particles and moving meshes · Fractals 2: further in · Vertex shaders 3: living geometry · Post-processing · Surfaces: from vertex to fragment · Blur and glow