GPU Boid Simulation: Goldfish Flocking (Niagara + HLSL)

A GPU-based boid simulation built in Unreal Engine's Niagara system, featuring a school of goldfish with emergent flocking behaviour and fully procedural animation driven by custom HLSL.
The neighbour grid is populated via custom HLSL that maps world positions to 3D grid cells for fast neighbour lookup. Rather than checking every particle against every other at O(n²), each fish only queries its 27 surrounding cells, reducing the flocking computation to effectively O(n) and making the simulation scale well beyond 200 particles.
The three classic boid rules are implemented on the GPU. Separation and alignment are computed via custom HLSL using precomputed squared distances and inverse square root for cheap normalisation. Cohesion is handled via point attraction force. Fish also avoid scene geometry using GPU distance field collision.
Fish animation is driven entirely through World Position Offset across three layered movements: yaw rotation, roll rotation, and lateral snake movement, all pivot-based and computed in HLSL. Flap frequency and amplitude scale relative to velocity via a remapped speed value, so faster fish swim with more urgency.
No per-frame Blueprint overhead. Everything runs on the GPU.

Fish mesh and other 3D assets by: Sarah Yandell

200 GPU boid particles exhibiting emergent flocking behaviour with separation, alignment, cohesion, and distance field surface avoidance, all running on the GPU

The school naturally clusters and disperses based on neighbour proximity. No Blueprint logic, pure GPU simulation.

The school naturally clusters and disperses based on neighbour proximity. No Blueprint logic, pure GPU simulation.

Three layered WPO movements: yaw rotation, roll rotation, and lateral snake movement, all pivot-based and velocity-driven.

Exposed animation parameters including RollAmplitude, YawAmplitude, SnakeMovementAmount and OffsetSpeed. Flap frequency scales with particle velocity via a remapped speed value.

Full Niagara system with neighbour grid, boid sim stage covering separation, alignment and cohesion forces, curl noise, point attraction, distance field avoidance, and dynamic material parameter updates.

Full Niagara system with neighbour grid, boid sim stage covering separation, alignment and cohesion forces, curl noise, point attraction, distance field avoidance, and dynamic material parameter updates.

Custom HLSL scratch pad for neighbour grid population. Maps world positions to 3D grid cells and writes particle indices for O(n) neighbour lookup.

Custom HLSL scratch pad for neighbour grid population. Maps world positions to 3D grid cells and writes particle indices for O(n) neighbour lookup.

Custom separation and alignment force computation with 27-cell neighbourhood search, weighted inverse distance separation, and velocity drag limiting.

Custom separation and alignment force computation with 27-cell neighbourhood search, weighted inverse distance separation, and velocity drag limiting.