Skip to content

Loethor/boids-gpu

Repository files navigation

GPU Boids Simulation

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

GPU Boids

Overview

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

Features

  • 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

Controls

  • Adjust simulation parameters in the script for different behaviors
  • No interactive UI (for interactive controls, see the CPU version)

Performance Optimizations

  • 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

How It Works

  • Boid positions and velocities are stored in GPU buffers
  • The compute shader updates all boids in parallel each frame
  • Rendering is handled by a MultiMeshInstance2D for efficiency

Requirements

  • Godot 4.0 or newer
  • GPU with compute shader support (WebGL2 compatible for web export)

License

MIT License - See LICENSE for details

References

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published