Date: Dec 2025
The goal is to build on the Learn WGPU tutorial and add some new functionalities and explore 🔥.
Here we explore the Stencil buffer commonly found in graphics backend.
The high level description:
The aim is to use the Stencil buffer to mask the area where the mirror is placed and reflect the camera/world.
This is achieved with 4 render pass basically:
- Pass to mask the mirror refletive area.
- Pass to reflect the 3D camera in the mirror
- Pass to render the rest of the world
- Pass to render the mirror surface with texture/tint/blending (optional)
The cool thing about WGPU (WEBGPU) is that the same code works for both desktops and web browsers (WASM). It requires a heavy setup upfront but later on it is almost painless(not 100% though).
I used Rust 1.92 nightly.
Main crates: 📦
- WGPU version 0.30.
- Winit version 27.0.1
Note: I use Caddy to serve the static files with CORS.
Developped on Rocky Linux 10.1 tested on Windows11.
How to run it:
For desktop:
> cargo runFor web browser:
> trunk serve and I use Caddy to serve static files with CORS.
So on Linux:
> sudo caddy run --config Caddyfile --adapter caddyfile Important Note: If you run MSAA (i.e sample = 4), you need to run the code in a browser that supports WEBGPU. For example: Firefox Nightly
