A real-time flocking simulation using a compute shader in Godot 4, based on Craig Reynolds' classic Boids algorithm from the 1987 paper "Flocks, Herds, and Schools: A Distributed Behavioral Model".
This project demonstrates emergent flocking behavior on the GPU, leveraging compute shaders for high performance. The simulation is capable of handling 10,000+ boids in real time.
The three core rules of flocking are implemented:
- Separation: Avoid crowding neighbors
- Alignment: Steer towards the average heading of neighbors
- Cohesion: Steer towards the average position of neighbors
- GPU-accelerated boid simulation using Godot 4's compute shaders
- Real-time performance with large numbers of boids (10,000+)
- Efficient batch rendering with
MultiMeshInstance2D - Simple, clean Godot project structure
- Adjust simulation parameters in the script for different behaviors
- No interactive UI (for interactive controls, see the CPU version)
- All boid logic runs on the GPU via a compute shader
- Minimal data transfer between CPU and GPU
- Single draw call for all boids
- Designed for smooth performance even with very large flocks
- Boid positions and velocities are stored in GPU buffers
- The compute shader updates all boids in parallel each frame
- Rendering is handled by a
MultiMeshInstance2Dfor efficiency
- Godot 4.0 or newer
- GPU with compute shader support (WebGL2 compatible for web export)
MIT License - See LICENSE for details
