Three.js Audio-Reactive Tunnel Flight

Fly through a winding audio-reactive tunnel in Three.js, where each ring of glowing bars freezes the spectrum as you pass it, flight speed and bloom pulse with the bass, and a 128 BPM loop is generated live with Web Audio.

Key topics: audio tunnel, audio reactive, music visualizer, three.js bloom, web audio, tunnel flight

What this code does

- Path: the tunnel centre follows a sum of sines, and the camera sits on it looking 8 units ahead.
- Rings: 60 rings × 32 bars in one InstancedMesh, each oriented by a quaternion that turns +z to the path direction.
- Spectrum Memory: every time the camera passes a ring, the current mirrored log-spectrum is captured into the farthest ring, so the tunnel ahead is a history of the music.
- Reactivity: bass energy scales flight speed and bloom strength, and band levels set bar length and colour.
- Post-Processing: EffectComposer with UnrealBloomPass and OutputPass, resized with the renderer.
- Controls: flight speed, reactivity, twist, palette and bloom.

Continue Learning

JavaScript Implementation

ES6+
// Audio tunnel: rings of bars placed along a winding path; the camera flies down it
const path = (z) => new THREE.Vector3(Math.sin(z * 0.05) * 4, Math.cos(z * 0.04) * 3, -z)
camera.position.copy(path(dist)); camera.lookAt(path(dist + 8))
for (let r = 0; r < rings; r++) for (let k = 0; k < segs; k++) {
  const a = k / segs * Math.PI * 2
  const len = 0.2 + spectrum[r][k] * 3                    // band level when the ring was captured
  bars.setMatrixAt(r * segs + k, new THREE.Matrix4().compose(ringPoint(r, a), inwardRotation(r, a), new THREE.Vector3(1, len, 1)))
}