| pkg | ||
| src | ||
| tutorial-website | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| compute_shader.wgsl | ||
| draw_shader.wgsl | ||
| en.subject.md | ||
| en.subject.pdf | ||
| index.html | ||
| logs | ||
| logs.txt | ||
| Makefile | ||
| re | ||
| README.md | ||
| run | ||
| tmp | ||
Unreal Majid - Particle System
A high-performance GPU particle simulation written in Rust using wgpu. This project demonstrates the power of Compute Shaders to handle physics calculations for millions of particles in real-time, rendering them efficiently on both native desktop platforms and the web via WebAssembly.
Live Demo
Note: You need a desktop and a browser that support WebGPU. Mobile devices are not supported.
Features
- GPU Compute Shaders: Physics calculations (position, velocity, acceleration) are offloaded to the GPU for massive parallelism.
- Cross-Platform: Runs natively on Windows/Linux/macOS and in modern web browsers supporting WebGPU.
- Interactive Camera: Fly-cam style movement with mouse-look controls.
- Dynamic Simulation:
- Gravity Control: Toggle gravity on/off.
- Mouse Attraction: Make gravity pull particles towards the mouse cursor.
- Shape Resets: instantly arrange particles into Sphere or Cube formations.
Controls
| Key | Action |
|---|---|
| W | Move Camera Forward |
| S | Move Camera Backward |
| A | Move Camera Left |
| D | Move Camera Right |
| Space / Q | Move Camera Up |
| Left Shift / E | Move Camera Down |
| R | Reset particles to Sphere shape |
| T | Reset particles to Cube shape |
| G | Toggle Gravity |
| F | Toggle Gravity Follows Mouse |
| Esc | Exit Application |
Mouse: Click and hold Left Mouse Button + Drag to rotate the camera.
Building and Running
Prerequisites
- Rust Toolchain (cargo, rustc)
- wasm-pack (for Web builds)
Native (Desktop)
To run the simulation natively on your machine:
-
Run with Cargo:
cargo run --releaseNote: The
--releaseflag is highly recommended for performance, especially with many particles. -
Using Makefile:
make ./target/release/particle-system
Web (WebAssembly)
To build and view the project in a browser:
-
Build:
wasm-pack build --release --target web --out-name Unreal_Majid -
Serve: Due to browser security restrictions (CORS), you must serve the files via a local web server.
# Using Python 3 python3 -m http.server -
View: Open your browser to
http://localhost:8000. Ensure your browser supports WebGPU.
Project Structure
src/main.rs: Entry point for native desktop execution.src/lib.rs: Entry point for WASM/Web execution.src/core/renderer.rs: Handles WGPU context, pipeline setup, and the main render loop.src/core/window.rs: Manages the application window and input events usingwinit.compute_shader.wgsl: WGSL shader responsible for particle physics updates.draw_shader.wgsl: WGSL shader responsible for drawing the particles.