$ show sotrh/learn-wgpu
This repository is a comprehensive, step-by-step tutorial series for learning wgpu, the Rust implementation of WebGPU. It contains over 30 example crates organized into beginner, intermediate, compute, and showcase categories, each demonstrating a specific GPU concept (window creation, pipelines, buffers, textures, uniforms, instancing, depth, lighting, normal mapping, HDR, compute shaders, etc.). The code is production-quality Rust with extensive use of wgpu, winit, cgmath, and bytemuck. A reusable framework crate (`code/showcase/framework`) provides a `Demo` trait, camera, model/texture loading, and pipeline builders, which many showcases implement. The repository also includes a VuePress documentation site with embedded WebAssembly demos, build scripts for WASM deployment, and a demo server. While the tutorials are well-structured and educational, there is significant code duplication across crates (e.g., identical `build.rs` files, repeated initialization boilerplate), and some showcases are stale or excluded from builds. The codebase tracks wgpu API changes closely (news files document migrations from 0.12 to 30.0), but some patterns use deprecated APIs (e.g., `wgpu::Backends::PRIMARY`, `immediate_size` in pipeline layouts). Overall, it is a valuable learning resource with solid engineering practices, though not a production library.
The LLM identified 7 files worth highlighting for reuse:
Provides the `Demo` trait and `run` function that standardizes showcase initialization, update, render, and input handling. Also includes `Display` struct for wgpu device/surface setup. This is a reusable scaffold for any wgpu application, reducing boilerplate across multiple examples.
Implements `Texture::from_bytes` and `Texture::from_image` with support for sRGB, depth, and cube textures. Handles format conversion and mipmap generation. This pattern is reused across many tutorials and can be extracted as a standalone texture utility for wgpu projects.
Defines `ModelVertex`, `Material`, `Mesh`, and the `DrawModel`/`DrawLight` traits for rendering 3D models. Uses `tobj` for OBJ loading and computes tangents/bitangents. The trait-based approach decouples model data from rendering logic, making it reusable for any wgpu renderer.
Contains `Camera`, `Projection`, `CameraUniform`, and `CameraController` structs. Provides a first-person camera with keyboard/mouse controls and a uniform buffer for GPU upload. This is a self-contained, reusable camera system that can be dropped into any wgpu project.
Implements mipmap generation using both a blit render pipeline and a compute shader approach. Demonstrates advanced GPU techniques (storage textures, workgroup dispatch) and is a reusable utility for any wgpu application needing mipmaps.
Implements an HDR pipeline with an offscreen render target and a tonemapping pass (ACES curve). Includes a full-screen quad shader and separate bind groups for HDR textures. This is a self-contained module that can be reused for HDR rendering in any wgpu project.
Provides `BitmapFont`, `FontBinder`, `TextPipeline`, and `TextBuffer` for rendering text using TrueType fonts. Generates a bitmap atlas via `fontdue` and renders with a custom WGSL shader. This is a reusable text rendering solution for wgpu applications.