A high-performance 3D particle simulation using WebGPU for massive parallel computations. The project demonstrates advanced GPU programming techniques including spatial partitioning, instanced rendering, and parallel physics calculations.
- Real-time simulation of millions of particles using Verlet integration
- Spatial grid-based collision detection for optimal performance
- Multiple gravity modes:
- No gravity
- Center gravity
- Shell gravity
- Cylindrical gravity
- GPU-accelerated particle rendering using billboards
- Dynamic lighting and depth-correct sphere rendering
- Interactive camera controls
- A WebGPU-compatible browser (Chrome Canary, Edge Canary, or other browsers with WebGPU flags enabled)
- Node.js and npm for building the project
- Clone the repository
- Install dependencies:
npm install
- Build the project:
npm run build
For development with hot reloading: npm run dev
The simulation uses multiple compute and render passes:
- Movement Computation: Updates particle positions using Verlet integration
- Spatial Partitioning: Organizes particles into a 3D grid for efficient collision detection
- Collision Resolution: Processes particle collisions using the spatial grid
- Rendering: Uses billboard technique with correct depth sorting and lighting
The simulation is optimized for handling large numbers of particles by:
- Using uniform grid spatial partitioning
- Implementing efficient GPU-based collision detection
- Not using CPU-GPU data transfers
- Using instanced rendering for particles
- WebGPU - Next-generation graphics API for the web
- WGSL - WebGPU Shading Language for GPU computations
- gl-matrix - High-performance matrix and vector operations
- WebPack - Module bundler
- ts-loader - TypeScript loader for WebPack
- webpack-cli - Command line interface for WebPack
- @webgpu/types - TypeScript types for WebGPU
- npm v11 - Package management
- Node.js v23 - Runtime environment
- Live Server - Development server (or just run the index.html file)
- WASD: Camera movement
- Mouse: Look around
- P: pause/play
- Number keys 1-4: Switch gravity modes
- SharedData.loadDefaultScene(numSpheres): Load a default scene with the specified number of spheres.
- 0.1M for low end computers
- 0.5M for mid range computers
- 1M-2M for high end computers.
- 5M (max) for very high end computers.
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.