Unity Compute Shader: Boids Simulation
About The Project
This is a personal learning project focused on understanding and implementing Unity's compute shaders. As a prototype, the primary goal was to build a functional Boids simulation, with a focus on implementation rather than exhaustive optimization.
The goal was to build a classic Boids flocking simulation from the ground up, moving the heavy calculations from the CPU to the GPU to achieve a massive performance increase. The result is a real-time technical demo that allows you to witness the beautiful, emergent behavior of thousands of boids. I have exposed a wide range of settings for you to play with, allowing you to see how different parameters affect the flock's behavior.
Features & Settings
You have full control over the simulation. Feel free to experiment with the following settings:
- General: Control the number of boids (
Spawn Count
), theirSpeed
, and reload the simulation. - Boid (Flocking): Adjust the core Boids algorithm parameters:
Alignment
,Coherence
,Separation
, and how far they can see (Vision Range
). - Obstacle Settings: Toggle obstacle avoidance on or off and adjust the
Weight
(how strongly they avoid) andDistance
(how far they look ahead). - Attraction Settings: Enable a target attractor and control its
Weight
(how much the boids want to follow it) and theRadius
of its influence.
Technical Details
This project is a technical showcase for GPU acceleration within the Unity Engine.
- GPU Accelerated: The simulation's core logic is powered by a Compute Shader (written in HLSL) that processes the entire Boids algorithm on the GPU. This allows for a massive number of agents at a consistently high framerate.
- CPU Fallback for Web: To ensure maximum accessibility, this live WebGL demo intelligently detects hardware support. It uses a robust C# CPU fallback if WebGL 2.0 compute is unavailable, guaranteeing the simulation runs smoothly for all users.
- Definitive Experience: For the full, uncompromised version, please download the standalone Windows build. This version exclusively uses the GPU path, unleashing the simulation's true potential for a truly massive and fluid swarm.
Note: The downloadable Windows version uses GPU acceleration for the best performance. A dedicated graphics card is recommended to experience the simulation with a high number of boids.
Credits
This project was developed as a learning exercise and is heavily based on the excellent "Coding Adventure: Boids" tutorial by Sebastian Lague.
Published | 2 hours ago |
Status | Prototype |
Platforms | HTML5, Windows |
Author | cheesam-dev |
Genre | Simulation |
Made with | Unity |
Tags | 2D, Prototype, Shaders, Unity |
Download
Install instructions
Follow these simple steps to run the high-performance standalone version of the simulation:
- Download the File Click the "Download" button on this page to get the
.zip
file. - Extract the Files The downloaded file is a compressed
.zip
folder. You must extract it before running the application.- Find the file in your Downloads folder.
- Right-click on the
.zip
file and select "Extract All...". - Choose a location for the folder (your Desktop is a good choice) and click "Extract".
- Run the Simulation
- Open the new folder that was created.
- Inside, find and double-click the application file (it will be named something like
Boid2DSimulation.exe
and have a unique icon).
A Note on Security
Because this is an indie project, Windows may show a security pop-up. If you see a "Windows protected your PC" screen, simply click "More info" and then "Run anyway".
Leave a comment
Log in with itch.io to leave a comment.