Boids · Cyclic Cellular Automata · Edge of Chaos · Physarum
GPU-accelerated particle simulations — flocking, cellular automata, and physarum — driven by real-time FFT audio analysis to produce emergent, organic visual behaviours on mobile hardware.
Build a high-performance system that transforms real-time audio input into complex visual simulations. Three distinct algorithms (Reynolds' Boids, Cyclic Cellular Automata, Physarum slime mold) are implemented entirely on the GPU via Compute Shaders, with FFT frequency-band data driving simulation parameters. The result is a set of audio-reactive visual systems capable of rendering tens of thousands of agents at interactive frame rates.
Implementation of Craig Reynolds' steering behaviours. Position and velocity calculations are dispatched to the GPU via BoidsCarrier.cs and FlockingBehaviour.cs.
The movement vector for each agent is the weighted sum of four steering forces:
| Force | Behaviour |
|---|---|
| Separation | Repulsive force inversely proportional to distance² within local radius |
| Alignment | Steers toward the average heading of neighbours |
| Cohesion | Steers toward the centre of mass of neighbours |
| Avoidance | Raycast-based terrain detection; steering adjusted via surface normal |
Collision avoidance computes the adjusted steering vector as:
A discrete grid simulation where a cell with state
Explores Langton's Lambda (
Based on Jeff Jones' algorithm for slime mold approximation. The simulation runs in three stages:
| Stage | Operation |
|---|---|
| Sensory | Agents probe the grid at angles |
| Motor | Agents rotate toward the highest chemical concentration (trail value) |
| Diffusion & Decay | Convolution kernel blurs the texture; values decay by factor |
The AudioData.cs module converts time-domain audio signals into frequency-domain data via FFT (Blackman-Harris window to minimise spectral leakage). A buffering system smooths amplitude spikes to prevent visual jitter:
Frequency bands are mapped to simulation parameters:
| Mapping | Target |
|---|---|
| Amplitude → Material Smoothness | Mathf.Lerp(min, max, amplitudeBuffer) |
| Frequency Bands → Geometry Scale | Per-band modulation of agent/cell size |
| Technique | Purpose |
|---|---|
ComputeBuffer |
Raw struct data transfer between C# and HLSL, bypassing GameObject overhead |
| Struct Alignment | C# structs padded to 16-byte HLSL alignment rules |
DrawMeshInstancedIndirect |
Geometry rendered directly from GPU buffer, eliminating per-instance draw calls |
| Audio-Reactive Materials | Smoothness, scale, and colour driven by FFT frequency band data |
git clone https://github.com/maybebool/Audioresponsive-Shaders.git- Open the project in Unity 2021.3+ (URP or HDRP recommended for Compute Shader support).
- Attach
AudioDatato a GameObject with anAudioSourceand assign an audio clip. - For Flocking: add
BoidsCarrierto the scene, assign theBoidPrefab, and link the Compute Shader. - For CCA / Physarum: attach
CCAorAgentCCArespectively and assign a compatible output material.
Prerequisites: Unity 2021.3+, C# 8.0+, GPU with Compute Shader support.
| Category | Technology |
|---|---|
| Engine | Unity 2021.3+ (URP/HDRP) |
| Language | C# 8.0+ |
| GPU Compute | HLSL Compute Shaders — flocking, CCA, physarum kernels |
| Audio | Unity AudioSource FFT with Blackman-Harris windowing |
| Rendering | Graphics.DrawMeshInstancedIndirect, ComputeBuffer struct pipeline |
The current system demonstrates audio-reactive emergent simulations on GPU. Possible extensions include:
- 3D volumetric cellular automata (extending CCA from 2D grid to 3D voxel space)
- Multi-species physarum with inter-species trail interaction
- MIDI / OSC input as an alternative to microphone FFT for live performance control
- Reaction-diffusion systems (Gray-Scott, Belousov-Zhabotinsky) as additional simulation modes
- VR integration for immersive audio-visual experiences on Meta Quest
- Temporal persistence with trail history visualisation across simulation frames



