How a Black Hole Music Visualizer Actually Bends Light
Gravitational lensing, Doppler beaming and a photon ring — rendered live in a browser and driven by your spectrum. Here is what the code is doing, and where it cheats.
Not a picture of a black hole
The easy way to make a black hole visual is a dark circle with a glowing ring sprite behind it. It looks fine in a thumbnail and wrong in motion, because the one thing a black hole actually does — bend the light around it — never happens.
The honest version is a ray march. For every pixel on screen you follow a ray outward, and at each step you bend it toward the singularity by an amount that falls off with distance. Light from the far side of the accretion disk curves over and under the horizon and arrives at your eye, so the disk appears to wrap above and below the black sphere. That is the image everyone recognises, and it falls out of the maths rather than being drawn.
What the music drives
The interesting question for a visualizer is what the audio is allowed to touch. The mapping used in Galaxy:
- Brightness of the disk by angle is the spectrum. A bright arc on one side is a real peak in the mix, not decoration.
- The kick flares the inner edge, closest to the horizon.
- The snare sends a single ripple travelling outward across the disk.
- The hats sparkle only on the outer rim.
- A build drags the outer radius inward and thickens the disk — the whole thing tenses.
- A drop fires bipolar jets along the axis and blooms the disk back out.
Giving each drum its own radius is what keeps it readable. If every hit lit the whole disk, you would be back to a flashing circle.
The physics it keeps
Two effects are worth implementing because they are visible and cheap. Doppler beaming: the side of the disk rotating toward you is brighter and bluer, the receding side dimmer and redder. Gravitational redshift: the inner edge dims as it approaches the horizon. Together they break the symmetry of the ring, which is most of what sells the image.
There is also a photon ring — rays that graze the photon sphere and loop before escaping pick up a hot rim right at the shadow's edge.
Where it cheats
It is a Newtonian approximation of the geodesics, tuned to look right, not a general-relativity solver. The step size adapts with distance so the march is cheap far away and careful near the horizon. Neither of those would survive a physics review, and neither is pretending to.
Two bugs worth knowing about
Ray marching has failure modes that look like art bugs.
- Speckle inside the shadow. A per-pixel random offset to each ray's start is the standard trick for hiding step banding. But near the photon sphere the trajectories are chaotic, so a large jitter makes neighbouring pixels land on opposite fates — captured or escaped — and the shadow fills with noise. The jitter has to stay small.
- Sparkle where the shadow should be solid. Foreground particles drawn on top of the marched layer will happily render in front of the black hole even when they are behind it. They have to be hidden when they fall inside the shadow along the view line.
Making it run anywhere
The march is rendered to a lower-resolution offscreen buffer and composited back, with the step count scaled by a quality tier. That is what lets the same scene run on integrated graphics and on a discrete GPU without changing the code — and why it stays usable on a phone.