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
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.