A blazingly fast 2D particle simulator written in Rust, capable of handling up to 89,478,485 particles simultaneously on modern GPUs.
- 🚀 High Performance: Leverages GPU compute shaders for massive parallelism
- 🔢 Scale: Handles tens of millions of particles with stable frame rates
- 🖱️ Interactive: Particles respond to mouse movements in real-time
- 🎮 Multiple Modes: Switch between different particle behaviors
- 🔧 Configurable: Easy customization via JSON configuration
- 🦀 Rust 1.70 or newer
- 🖥️ A GPU with WebGPU support (most modern GPUs)
- 🐧 Windows/Linux/macOS
- Clone the repository
git clone https://github.com/Paladynee/hashnet_compute_shader
cd hashnet_compute_shader- Build with Cargo
cargo build --release- Run the application
cargo run --release- Mouse Movement: Particles gravitate toward cursor
- R key: Switch to Roam mode (particles gravitate around the cursor)
- S key: Switch to Shuffle mode (particles are randomly offset)
Customize the simulation by modifying the config.json file:
{
"num_particles": 89478485,
"quad_size": 0.001
}- num_particles: Number of particles to simulate
- quad_size: Size of each particle on screen
Hashnet Compute Shader uses WebGPU through the wgpu Rust library to run highly parallelized compute shaders. The simulation follows these steps:
- Initialization: Particles are created with random positions and velocities
- Compute Phase: GPU updates particle positions and velocities in parallel
- Render Phase: Particles are rendered as small quads with velocity-based coloring
The application dispatches compute workgroups in a 2D grid to overcome the 65535 limit per dimension, allowing it to handle many millions of particles.
- Adjust particle count based on your GPU capabilities
- For integrated GPUs, try starting with 1-5 million particles
- For high-end dedicated GPUs, you can push well beyond 50 million particles
Contributions are welcome! Feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- The wgpu team for their excellent WebGPU implementation
- The Rust community for building an amazing ecosystem for systems programming