This repository demonstrates a high-performance, audio-reactive visual simulation system built in Unity. The project focuses on implementing complex mathematical algorithms—specifically Flocking behaviors, Cellular Automata, and Physarum simulations—accelerated via GPU Compute Shaders to handle high-density particle counts.
The system transforms real-time audio input into visual data using FFT (Fast Fourier Transform) analysis, driving organic, emergent behaviors in real-time.
- GPU-Accelerated Flocking: Reynolds' Boids algorithm implementation using Compute Shaders for massive swarm simulation.
- Cyclic Cellular Automata (CCA): 2D grid-based state simulations supporting Moore neighborhoods.
- Physarum Trails: Agent-based slime mold simulations using sensory/motor stages and diffuse/decay kernels.
- Audio Analysis Engine: Real-time frequency band separation with logarithmic smoothing.
- Indirect Instancing: Rendering optimization using
Graphics.DrawMeshInstancedIndirect.

The flocking system implements Craig Reynolds' steering behaviors. To maintain high performance with large populations, position and velocity calculations are dispatched to the GPU via BoidsCarrier.cs and FlockingBehaviour.cs.
The Core Forces
The movement vector
-
Separation: Repulsive force inversely proportional to the distance squared between neighbors within a local radius
$r$ . -
Alignment: Steers the agent towards the average heading (
$\vec{forward}$ ) of neighbors. - Cohesion: Steers the agent towards the average position (center of mass) of neighbors.
-
Collision Avoidance: Utilizes raycasting (
RaycastType) to detect terrain. Upon detection, the steering vector is adjusted using the surface normal$\hat{n}$ of the hit point:
The AudioData.cs module utilizes the Fast Fourier Transform (FFT) to convert time-domain audio signals into frequency-domain data.
- Spectrum Analysis: Uses a Blackman-Harris window to minimize spectral leakage.
-
Buffer Smoothing: To prevent visual jitter, a buffering system smooths amplitude spikes. The buffer falls off linearly when the current amplitude is lower than the buffered amplitude:
$$A_{buf}(t) = A_{buf}(t-1) - \Delta_{decay}$$
The project implements multiple forms of discrete grid simulations.
Cyclic Cellular Automata (CCA.cs)

A cyclic system where a cell with state
- Algorithm: Supports both Moore and Von Neumann neighborhoods with adjustable range and threshold parameters.
Edge of Chaos (EOCCCA.cs)

Explores Langton’s Lambda (
-
Compute Indexing: The 3D transition rule table is flattened for the GPU:
$$Index = a \times N^2 + b \times N + c$$
Physarum / Agent Trails (AgentCCA.cs)

Based on Jeff Jones' algorithm for slime mold approximation.
-
Sensory Stage: Agents probe the grid at angles
$\theta$ ,$-\theta$ , and$0$ . - Motor Stage: Agents rotate toward the highest chemical concentration (trail value).
-
Diffusion & Decay: A convolution kernel blurs the texture, and values are multiplied by a decay factor
$\delta < 1.0$ every frame.
To bypass the CPU overhead of GameObject transforms, the system uses ComputeBuffer to pass raw struct data (BoidConductValues) between C# and HLSL.
- Struct Alignment: C# structs are padded to align with HLSL memory rules (16-byte alignment).
- Indirect Instancing:
NoiseGridInstance.csusesDrawMeshInstancedIndirectto render geometry directly from the GPU buffer, eliminating draw-call overhead.
The NoiseAudio.cs and BoidsCarrier.cs scripts bridge the audio data and the rendering pipeline.
- Smoothness Mapping: Maps audio amplitude to material smoothness:
Mathf.Lerp(min, max, amplitudeBuffer). - Scale Modulation: Modulates geometry scale based on specific frequency bands.
- Audio: Attach
AudioDatato a GameObject with anAudioSourceand assign a clip. - Flocking: Add
BoidsCarrierto the scene. Assign theBoidPrefaband link the Compute Shader. - Simulation: For CCA or Physarum, attach
CCAorAgentCCArespectively, ensuring a compatible Material is assigned for output.
- Unity 2021.3+ (URP/HDRP recommended for Compute Shaders)
- C# 8.0+