November 3, 2026 · 4 min read
My WebGL2 music visualizer: rebuilding three scenes with real fluids and volumes
Three scenes of my music visualizer looked bad. The diagnosis: they were 2D noise. I rebuilt them with a real fluid solver and volumetric ray marching, and learned to measure whether a scene is on the beat.
In this post
Visualizer is my music visualizer: it turns whatever is playing into animations (the scenes) that move with the beat and take the colors of the album art. It started with four scenes and had seven a few days later. Not all of them came out right the first time. Fluid, Nebula and Aurora went through several rounds of “it’s erratic”, “it looks like a badly made loop” and “it has no colors”, until the verdict was blunt: they look bad.
This post is about why they looked bad and what changed when I stopped tweaking numbers.
The diagnosis: flat 2D noise
All three had the same underlying problem. They were layers of 2D noise (fbm) drifting over time and changing brightness with the music. You can tweak that forever: faster, slower, another color. But it will never look like ink in water, a cloud of gas or an aurora, because those things have volume and physics.
On top of that, noise that moves with time is reversible: Fluid “went forward and back”, because the function behind it had no memory of what had happened before.
The way out was to look up how those things are really done, and rebuild them.

Fluid: a real solver
The new Fluid is a stable fluids simulation adapted from Pavel Dobryakov’s WebGL Fluid Simulation, which is MIT licensed and credited in the README. Velocity is simulated on a 128-pixel texture, ink on a 720-pixel one, and pressure is solved with 20 iterations per frame.
The music comes in through three nozzles: the bass pours the primary color, the mids the secondary and the highs the accent. Every beat fires a burst.
The first version was “weird, too fast and off the beat”. I cut the life of the velocity a lot (dissipation went from 0.25 to 2.6) so motion dies quickly, and let only the beats push. The nozzles now just pour ink.
How do you know it’s “on the beat” without trusting your gut? I recorded frames of the scene and measured how much each one changed from the previous one. If the scene follows the music, that curve peaks on every beat and calms down between hits. That’s what I saw.
Nebula and Aurora: ray marching
A cloud of gas isn’t an image: it’s light going through a volume. To draw it, each pixel casts a ray and steps through the cloud, adding the light the gas emits and removing what the dust absorbs. That’s volumetric ray marching.
- Nebula: 48 steps per pixel inside a sphere, glowing gas, dark dust that blocks it, a star in the middle and a camera slowly orbiting.
- Aurora: 48 layers of curtains whose outline comes from noise, colored by height, over a lake with mountains. Every 4 beats a wave of light passes through.
The problem with ray marching is cost: 48 steps per pixel, and several 3D noise samples per step. Computing that noise with math functions at every step didn’t reach 60 frames per second. The trick, from Inigo Quilez, is to store random noise in a small texture and read it with interpolation. One texture fetch brings two z-slices at once, and the GPU interpolates for free. With that, everything ran at 50–60 frames per second on a GPU.

Galaxy: stateless particles
The Galaxy has 120,000 particles and none of them stores its position. Each one is computed in the vertex shader from its index and the time. That way there’s no buffer to update every frame.
This had a catch. I gave it differential rotation, like a real galaxy (the center spins faster than the edge), and over time the arms wound up into a ball of light. The fix was rigid rotation with a bounded sway. It now also changes shape every 25 seconds: a spiral with 2 to 6 arms, barred, ring or elliptical.
A licensing rule
Shadertoy is full of amazing cloud and aurora examples, but its default license is CC BY-NC-SA: non-commercial and share-alike. My code is MIT, so I took techniques from there, not code.
What I learned
- If you’ve spent several rounds tweaking parameters and it still looks bad, the problem is the technique, not the numbers.
- For natural effects (fluids, gas, light), imitating the physics beats imitating the look.
- “On the beat” can be measured: frame differences against the beats say it better than my impression.
- A well-used noise texture is worth more than any optimization of the noise function.