A GPU-driven audio visualizer built in Unity that generates a dynamic grid of cubes whose height responds to real-time audio spectrum data. The geometry is entirely computed on the GPU using a compute shader with Perlin noise modulation.
🎥 Tutorial: Watch on YouTube (german)
The system consists of three core components that form a pipeline from audio input to GPU-driven mesh output:
Unity's AudioSource.GetSpectrumData provides 512 raw FFT samples using a Blackman-Harris window. These samples are grouped into 8 frequency bands with exponentially increasing bin sizes:
For each band
where
Raw frequency values are smoothed through a decay buffer to prevent harsh visual flickering. For each band
Bands are then normalized against their observed peak to produce values in
The global amplitude buffer aggregates all bands:
A compute shader dispatched with [numthreads(8, 8, 1)] generates an
Perlin Noise is evaluated per cube using a time-evolving seed:
The cube height
Each cube is defined by 8 vertices and 36 indices (12 triangles), written directly into RWStructuredBuffer objects. The vertex stride is:
storing position and normal per vertex.
| Parameter | Location | Description | Default |
|---|---|---|---|
width / length |
CubeGenerator | Grid dimensions | 10 × 10 |
gap |
CubeGenerator | Spacing between cubes | 0.5 |
seedChangeSpeed |
CubeGenerator | Noise animation speed | 1.0 |
amplitude |
CubeGenerator | Base amplitude scalar | — |
bandCount |
AudioData | Number of frequency bands | 8 |
- Unity Engine and audio pipeline
- HLSL Compute Shader GPU-side cube generation with Perlin noise
- C# Audio FFT analysis, buffer smoothing, and CPU-GPU bridge