Source code

Rust WebGPU examples & Tutorials

Interactive Rust, wgpu, and WGSL demos for browser WebAssembly and native rendering, each with a source-guided article.

A neon WebGPU rhythm platform game with a green square jumping over pink spikes, cyan blocks, and a progress bar. WebGPU Geometry Dash-style game One-button rhythm platforming with fixed-step physics, procedural GPU visuals, and touch controls. Claire Redfield standing before the rainy R.P.D. front gate in a WebGPU fixed-camera scene with a small status and model-credit overlay. WebGPU Resident Evil fixed-camera scene GPU-skinned Claire, tank controls, and three persistent fixed-camera views of the rainy R.P.D. approach. Colored indexed triangle screenshot WebGPU triangle A live Rust and wgpu demo with a walkthrough of vertex buffers, WGSL shaders, and the render pipeline. Matching checkerboard surfaces using interleaved and separate WebGPU vertex buffers WebGPU vertex attributes Compare interleaved and separate buffers, with a Rust and WGSL walkthrough of strides, offsets, and shader locations. WebGPU campfire with layered flame and smoke billboards over a textured fireplace WebGPU CPU particle system Simulate 512 fire and smoke particles in Rust, stream their instance data, and render them as camera-facing billboard quads. Rainbow WebGPU compute particles forming flowing bands across a black background WebGPU compute particles Update 262,144 particles in 1,024 compute workgroups, ping-pong two storage buffers, and render the GPU-written state as additive billboards. A checkered WebGPU cloth draped over a sphere beside controls for compute iterations, time step, stiffness, damping, and collision radius. WebGPU compute cloth simulation Spring-connected cloth grid simulated in compute shaders and rendered as a sphere-colliding mesh. A three-dimensional grid of colored sphere LODs rendered after WebGPU compute frustum culling, beside live culling statistics. WebGPU compute culling and LOD Compute shader frustum culling, LOD bucketing, compacted instance buffers, and indirect draws. Thousands of animated Jax rabbit characters rendered in colored WebGPU meshlet LOD bands with a Nanite diagnostics panel. WebGPU Nanite-style mesh rendering Adapter-scaled populations, virtual geometry pages, meshlet LODs, two-pass HZB occlusion, indirect rasterization, and GPU skinning. Crowd of animated Jax characters filling the colorful Sponza atrium in the WebGPU Metropolis renderer, with the live settings panel open. WebGPU Metropolis renderer Forward+ Sponza scene with GPU culling, indirect draws, animated crowds, dynamic shadows, reflections, GI, and post-processing. Luminous colored particle clusters evolving in the WebGPU N-body simulation beside live controls WebGPU N-body simulation Evaluate 151 million pairwise interactions with tiled workgroup memory, then render 12,288 additive billboards with live egui controls. Three glossy spheres reflected across red, green, white, and black walls in a WebGPU compute ray traced room. WebGPU compute shader ray tracing Compute shader software ray tracing into a storage texture, displayed by a fullscreen present pass. Three spheres and three colored boxes casting hard ray-traced shadows across a checkerboard floor between red and green walls. WebGPU ray-traced shadows Primary and secondary shadow rays traced in a compute shader over procedural scene geometry. Reflective chrome sphere, textured spheres, colorful boxes, and a checkerboard floor ray traced inside a red, green, and gray room. WebGPU ray-traced reflections Recursive reflection bounces traced in a compute shader with a sky-gradient miss path. Animated Jax rabbit character ray traced between reflective orange and blue spheres, cyan and yellow boxes, and a checkerboard floor. WebGPU glTF ray tracing Compute ray tracing over a skinned and textured glTF mesh with runtime skinning controls. Animated Jax character walking through the Crytek Sponza atrium under WebGPU ReSTIR direct illumination, with reservoir controls open. WebGPU ReSTIR direct illumination Direct-light reservoirs reused across time and neighboring pixels over Sponza and animated Jax geometry. Animated Jax character crossing the Crytek Sponza atrium with warm WebGPU ReSTIR global illumination and reservoir controls visible. WebGPU ReSTIR global illumination One-bounce path reservoirs with temporal and spatial reuse over the same animated Sponza test scene. A tilted HTML Mesh page with a green Click button and button counter, rendered on a dark 3D plane beside an egui control panel. WebGPU HTML mesh Offline-rasterized HTML surface mapped onto a 3D plane with ray-mapped pointer and keyboard input. Husky image mapped onto a lit quad in the WebGPU texture loading demo WebGPU texture loading Load a PNG in Rust and wgpu, then explore UV coordinates, samplers, bind groups, and WGSL texture sampling. Metal plates repeating along a tunnel with large nearby tiles and fine distant detail WebGPU texture mipmap generation Generate eleven mip levels with GPU render passes, then explore LOD and anisotropic filtering on a rotating tunnel. Reflective sphere and bridge skybox sharing a WebGPU cubemap WebGPU texture cubemap A skybox and reflective sphere, with a Rust and WGSL walkthrough of cubemap face order, cube views, and reflection sampling. Seven stacked quads displaying image, solid color, and procedural layers from a WebGPU texture array WebGPU texture array Seven textured quads in one draw, with Rust and WGSL notes on array layers, instancing, and texture sampling. A colorful cube with GPU and FPS text at the upper left and blue Persian text at the lower right WebGPU text overlay Render FPS and Persian text over a rotating cube, with Rust notes on fonts, glyph atlases, Unicode shaping, and overlay passes. Gold Latin and blue Persian text with extruded outlines and lit side faces WebGPU 3D text mesh Turn Latin and Persian font outlines into extruded geometry, with Rust notes on shaping, curve sampling, indexed meshes, and WGSL lighting. An angled gray cube textured with blue, green, and white Cesium logos WebGPU glTF 2.0 model loading Load the Khronos textured box from a URL, then turn its glTF nodes, mesh attributes, material, sampler, and texture into a wgpu draw. Purple, red, and gold Jax character walking on a black WebGPU canvas WebGPU glTF vertex skinning Animate Jax with a 46-joint glTF skeleton, CPU-sampled keyframes, an uploaded matrix palette, and four-weight WGSL skinning. Thousands of gray, brown, and white instanced asteroids arranged in dense rings WebGPU asteroid instancing Render 2,048 animated asteroids in one indexed draw using a static instance buffer, procedural geometry, and six texture-array layers. Dense WebGPU jungle with palms, red bromeliads, and green ground cover WebGPU indirect draw Render 24,576 plants from 12 indexed indirect commands using instanced glTF submeshes and a KTX texture array. One WebGPU treasure scene shown side by side with glossy Phong shading, banded toon shading, and colored wireframe lines. WebGPU multiple render pipelines Original treasure glTF scene rendered through Phong, toon, and wireframe pipelines. Red, green, and blue toothed 3D gears with lit faces on a black background Procedural WebGPU gears Generate three toothed meshes in Rust, share their GPU buffers, animate per-gear uniforms, and light the moving surfaces in WGSL. Red toon-shaded Venus statue edged with a white stencil buffer outline WebGPU stencil buffer outlines Draw a toon-shaded Venus mesh twice, expand it along its normals, and mask the white silhouette with a depth-stencil attachment. Translucent blue WebGPU occluder hiding a teapot while a green sphere remains partly visible WebGPU occlusion queries Test a teapot and sphere with two native sample-count queries, asynchronous readback, and an explicit browser-safe fallback. Magenta WebGPU glow sphere with soft radial light streaks against a black background WebGPU radial blur Render a glow mask to a 512 × 512 target, sample it 32 times per fragment, and additively composite the streaks over the lit scene. A retro green UFO with cyan lights and a bright yellow beam glowing against a black background WebGPU bloom Render a dedicated glow mesh to 256 × 256, blur it vertically and horizontally with two 9-tap filters, then add it over the lit UFO. Animated rabbit-like Jax character walking across a checkerboard floor under red, yellow, green, blue, and white deferred lights WebGPU deferred shading Write world position, normal, and albedo into three G-buffer targets, then light animated Jax and the floor with six lights in one fullscreen pass. Animated Jax character walking across a checkerboard floor under colored deferred lights rendered with 4x MSAA WebGPU deferred multisampling Store four samples for every position, normal, albedo, and depth G-buffer pixel, then shade and average them manually in one fullscreen pass. Animated Jax character walking across a checkerboard floor under colorful WebGPU spotlights casting multiple shadows WebGPU deferred shadows Render animated Jax into three 1024 × 1024 depth maps, then use up to 27 comparison samples while shading eight spotlights in a fullscreen deferred pass. Animated Jax character on a colorful checkerboard beside WebGPU SSAO controls WebGPU screen-space ambient occlusion Generate a full-resolution AO mask with up to 32 spiral samples, soften it with a weighted 5 × 5 blur, and combine it with deferred shadows. A flat WebGPU plane appearing densely covered with raised rocks through parallax occlusion mapping WebGPU parallax occlusion mapping A two-triangle plane ray-marches 48 height layers from alpha, then lights RGB tangent-space normals to create parallax occlusion. A white and black Voyager space probe with a dish antenna and long lattice boom on a white WebGPU canvas WebGPU 4x MSAA multisampling Render the textured Voyager in three indexed draws into 4x multisampled color and depth, then resolve once into the surface. Dense grove of alpha-textured oak trees rendered with 4x WebGPU MSAA and alpha-to-coverage against a dark blue background. WebGPU alpha-to-coverage foliage Render 25 instanced oak trees in two indexed draws, converting leaf alpha into four-sample coverage before resolving to the surface. A 7 by 7 grid of gold spheres showing metallic and roughness changes under four lights WebGPU PBR Basic Compare metallic and roughness across 49 instanced gold spheres with a compact GGX and Schlick specular shader. An ornate black, brass, and wood Cerberus triple-barrel pistol rendered against a sunlit bridge cubemap beside PBR controls WebGPU PBR textures Render the Cerberus glTF with five material maps, four GGX lights, image-based lighting, and live exposure controls. Ten gold spheres with changing roughness and metallic reflections across a suspension bridge cubemap WebGPU PBR image-based lighting Build diffuse irradiance and a split-sum BRDF LUT on the CPU, then approximate rough reflections with seven box-filtered cubemap mips. A white teapot casting a long dark shadow across a beige floor against a gray background WebGPU shadow mapping Render a teapot into a 1024 × 1024 depth map, then project nine comparison samples onto a procedural floor as the light moves. Five colored teapots receding across a long floor, each casting a directional shadow under four-cascade WebGPU shadow mapping. WebGPU cascaded shadow mapping Four frustum splits rendered into a layered depth texture, with the fragment shader sampling the matching cascade. Four colored teapots inside a three-walled room, lit by a small moving point light and casting shadows in several directions. WebGPU omnidirectional shadow mapping Six cube-map light passes store point-light distance, then the scene shader samples the cube map for omni-directional shadows.