A cross-platform WebGPU graphics demonstration built with Rust, showcasing GPU-accelerated triangle rendering with interactive features.
- Dual shader pipelines: Toggle between two rendering approaches
- Vertex-colored triangle with per-vertex color interpolation
- Procedurally-generated triangle using only vertex indices (no vertex buffer)
- Interactive clear color: Move your cursor to dynamically change the background color
- Cross-platform support: Runs on Windows, macOS, and Linux via Vulkan, Metal, and DX12
- Move cursor - Changes background color based on position
- Press Space - Toggles between the two shader pipelines
- Press Escape - Exits the application
- Rust 1.70+ (recommended: latest stable)
- A GPU with Vulkan, Metal, or DirectX 12 support
# Clone the repository
git clone https://github.com/obox-systems/demo_wgpu_example
cd demo_wgpu_example
# Build and run
cargo run --releasesrc/
├── main.rs # Application entry point
├── lib.rs # Core rendering logic and state management
├── shader.wgsl # Vertex-colored triangle shader
└── challenge.wgsl # Procedural triangle shader (no vertex buffer)
The main shader (shader.wgsl) demonstrates traditional GPU rendering:
- Vertices contain position and color data
- Colors are interpolated across the triangle by the GPU
- Result: A smooth RGB gradient triangle
The challenge shader (challenge.wgsl) generates geometry entirely in the vertex shader:
- No vertex buffer required - positions computed from vertex index
- Colors derived from screen-space position
- Demonstrates GPU compute capabilities in the rendering pipeline
- wgpu - Safe Rust graphics API
- winit - Cross-platform window creation
- bytemuck - Safe byte casting for GPU buffers
MIT