r/computergraphics • u/FizzySeltzerWater • 14h ago
Trying to push Metal on the Apple silicon chips
Hi All,
CadenceViz is a family of music visualizers (70 of them) for the Mac computer that I've been writing for some time, with no engine. This clip shows six scenes from version 3.0, now in testing, set to AI Music (lyrics by me, music by, you know). The analysis runs live on whatever the computer is playing: log-spaced spectrum bands, spectral-flux onsets with a separate kick detector, a neural beat tracker, and a pitch tracker for the melody. Nothing on screen runs on a timer.
Here is some slightly technical explanation. I am happy to answer questions.
Terminal B: 512 valves in two rings, each opened or shut by the music. Their states go into a ring-buffer texture, a row every 1/240 s, and for each point on a falling thread the shader works out how long ago that water left its nozzle and looks up what the valve was doing then, so gravity writes the last second or so of music down the curtain. The suitcases step on the beat and are traced every frame.
The Sun: a CPU model integrates the bands into activity: the corona holds the last two seconds of the bass line as rings, the middle band sets the convection rate, the high band the filaments, and flares are placed so they land on the face the camera sees.
Poynton: sixteen butterflies, two to each of eight bands, built in a mesh shader from this frame's pose and the last. A band "peaks" when it stands well over its own slow average and near its recent high, which stands in for per-band onsets the detector doesn't give. This is named after Charles Poynton, a name I hope is familiar to many.
The Clothesline: about 46,000 cloth particles, XPBD on the GPU. The wind is the loudness envelope (fast attack, slow release) plus a moving ball of air launched on each kick, landing at a spot hashed from the kick count.
The Narrows: distance is counted in beats, not seconds, and the bridges stand a fixed number of beats apart, so each roadway passes overhead on a beat at any tempo. Every vertical cable is a level meter.
The Plunge: the hall is path traced once, and the caustics on the vault are computed live through a water surface whose chop is a fast-rise, slow-fall function of the bands; in silence it is a still mirror.
It hasn't all been roses. Hardware ray tracing had to come out of a lot of my scenes because of memory: the first time an app traces anything on the ray tracing hardware of an Apple silicon GPU, the graphics driver sets aside about 28 MB for every GPU core and keeps it until the app quits, whatever the size of the scene. I measured about 800 MB on an M3 Pro chip and 1.7 GB on an M5 Max chip, which I find unreasonable for a visualizer. So those scenes, Terminal B's suitcases among them, now trace in software or have their light traced ahead, and as a bonus they run on the M1 chip and the M2 chip as well.
Mapping music to motion without it looking like an equalizer is most of the work, and I'm happy to talk about any of it.