PooyaEimandar/webgpu

Rust examples for learning WebGPU

HTML

16

104 commits

updated Oct 5, 2026

See the code

See what people are saying

SourceMessageScoreDate

Rust WebGPU Examples for Native and WASM

1

Oct 15, 2026

README

webgpu

Rust WebGPU examples porting Sascha Willems' Vulkan samples, with WASM and native support, based on the Sib render module.

Demo

Try the WASM demos here

Examples

ExampleDescriptionScreenshot
triangleRenders a colored indexed triangle using vertex and index buffers, WGSL vertex/fragment shaders, a render pipeline, and a depth attachment.Basic indexed triangle
vertexattributesRenders the same indexed mesh through interleaved and separate vertex attribute buffers using matching shader locations for position, normal, UV, and tangent data.Vertex attributes
particlesystemUpdates flame and smoke particles on the CPU, streams them into an instance buffer, and renders billboard sprites over a normal-mapped scene.CPU particle system
computeparticlesUpdates 262,144 particle records in 1,024 compute workgroups using ping-ponged storage buffers, then renders the GPU-written state as additive textured billboards.Rainbow WebGPU compute particles forming flowing bands across a black background
computeclothSimulates a spring-connected cloth grid in compute shaders, ping-pongs storage buffers, collides with a sphere, and renders the GPU-written cloth mesh.Compute cloth
computecullandlodCulls a dense object grid in a compute shader, buckets visible instances by LOD, writes indirect draw commands, and renders the compacted GPU instance buffers.Compute cull and LOD
naniteScales its Jax population to the detected GPU, streams requested geometry pages into a physical cache, selects projected-error meshlet LODs, and performs two-pass HZB occlusion with indirect draws.Nanite-style Jax meshlet rendering
metropolisRenders Sponza with GPU-skinned Jax crowds using clustered Forward+ lighting, compute frustum culling, indirect draws, physics, dynamic shadows, reflections, probe GI, particles, and temporal post-processing.Metropolis GPU-driven renderer
computenbodyEvaluates 150,994,944 ordered particle interactions per frame with tiled workgroup memory, integrates one in-place storage buffer, and renders 12,288 additive billboards with runtime egui controls.Luminous colored particle clusters evolving in the WebGPU N-body simulation beside live controls
computeraytracingRay traces spheres and planes in a compute shader, writing the result to a storage texture that is sampled by a fullscreen present pass.Compute shader ray tracing
raytracingshadowsCasts primary and secondary shadow rays in a compute shader, shading a procedural scene into a storage texture and dimming occluded hits.Ray traced shadows
raytracingreflectionsTraces recursive reflection bounces in a compute shader, treating bright objects as reflectors and falling back to a sky-gradient miss color.Ray tracing reflections
raytracinggltfRay traces a textured skinned glTF character by flattening animated mesh data into compute-friendly geometry buffers with egui skinning controls and joystick camera movement.Ray tracing glTF
restirdiResamples direct-light candidates across time and neighboring pixels, tracing visibility through compact static Sponza and dynamic skinned Jax SAH BVHs.ReSTIR direct illumination
restirgiReuses one-bounce indirect-light path reservoirs across time and space over the same Crytek Sponza scene and animated Jax character.ReSTIR global illumination
htmlmeshRenders a simple inline HTML button page to an RGBA texture, uploads it to WebGPU, maps it onto a plane, and ray-maps pointer input back to the button.HTML mesh
textureRenders a textured indexed quad using a runtime-loaded PNG texture, a sampler, uniform buffer transforms, and fragment shader lighting.Textured indexed quad
texturemipmapgenGenerates a full mip chain from a high-frequency texture using offscreen render passes, then samples the result on a textured tunnel.Texture mipmap generation
texturecubemapRenders a skybox and reflective sphere from six bundled KTX1 faces loaded at runtime, a cube texture view, and a filtering sampler.Runtime-loaded cubemap reflection
texturearrayRenders seven stacked squares sampling separate layers from a runtime-built 2D texture array with two async-loaded images, RGB layers, and procedural layers.Runtime-built texture array
textoverlayRenders glyph atlas text over a 3D scene using an overlay render pass, Unicode shaping, and RTL text.Text overlay
textmeshConverts shaped LTR and RTL font outlines into extruded indexed mesh geometry with vertex colors and lighting.3D text mesh
gltfLoads an official glTF 2.0 textured box from URL, converts buffers and material data to render meshes, and samples its base color texture.glTF textured box
gltfskinningLoads a textured animated glTF 2.0 character, uploads joints and weights, and skins vertices in the WGSL vertex shader.glTF vertex skinning
instancingRenders thousands of asteroid instances from one indexed mesh, using a per-instance vertex buffer for transform data and a 2D texture array for material variation.Instanced asteroid field
indirectdrawRenders many instanced plant submeshes from indexed indirect command buffers, with a skysphere, ground mesh, and per-instance transforms.Indirect draw jungle scene
pipelinesRenders the original treasure glTF scene through Phong, toon, and wireframe render pipelines in separate viewports.Multiple render pipelines
gearsRenders animated procedural toothed gears using indexed mesh buffers, per-gear uniform transforms, depth testing, and fragment shader lighting.Animated procedural gears
stencilbufferRenders a toon-shaded Venus mesh, writes stencil during the first draw, then draws a normal-expanded outline where stencil differs.Stencil buffer outline
occlusionqueryTests teapot and sphere visibility; native builds resolve occlusion-query samples, while WASM uses a browser-safe fallback and shades hidden meshes dark.Occlusion query visibility test
radialblurRenders a glow sphere to an offscreen target, samples it in a fullscreen radial blur pass, and blends the result over the lit scene.Radial blur glow sphere
bloomRenders glowing UFO parts to an offscreen target, runs separable Gaussian blur passes, and additively composites the bloom over the lit scene.Bloom offscreen rendering
deferredFills world-position, normal, and albedo G-buffer attachments with an animated skinned Jax character and checkerboard floor, then evaluates six lights in one fullscreen composition draw.Animated rabbit-like Jax character walking across a checkerboard floor under colored deferred lights
deferredmultisamplingStores four samples per position, normal, albedo, and depth G-buffer pixel, then shades each sample under six lights and averages the result in a single-sample fullscreen pass.Animated Jax character walking across a checkerboard floor under colored deferred lights rendered with 4x MSAA
deferredshadowsRenders animated Jax into three 1024×1024 Depth32Float maps, then evaluates eight spotlights and up to 27 comparison samples in the fullscreen deferred pass.Animated Jax character walking across a checkerboard floor under colorful spotlights casting multiple shadows
ssaoUses up to 32 screen-space spiral samples from the position, normal, and depth G-buffer, blurs the full-resolution AO mask with a weighted 5×5 kernel, and combines it with deferred shadows.Animated Jax character on a colorful checkerboard beside WebGPU SSAO controls
parallaxmappingRay-marches 48 height layers from a combined normal-height map on a flat two-triangle plane, then refines the UV intersection for parallax occlusion mapping.A flat plane appearing densely covered with raised rocks through parallax occlusion mapping
multisamplingRenders the textured Voyager in three indexed draws into 4x multisampled color and depth attachments, then resolves once into the surface.A white and black Voyager space probe with a dish antenna and long lattice boom
multisamplingalphatocoverageRenders instanced alpha-masked oak trees with 4x MSAA and alpha-to-coverage enabled for smoother foliage edges.Multisampling alpha-to-coverage oak trees
pbrRenders a 7x7 grid of procedural spheres with GGX/Schlick PBR shading, varying metallic and roughness per instance.PBR material grid
pbriblSamples irradiance, prefiltered environment mips, and a BRDF integration LUT for image-based PBR lighting.PBR image based lighting
pbrtextureRenders the Cerberus glTF mesh with albedo, normal, AO, metallic, and roughness maps under image-based PBR lighting.Textured PBR Cerberus model
shadowmappingRenders a depth-only light pass into a shadow map, then samples that depth texture in the scene pass for projected shadows with PCF filtering.Projected shadow mapping
shadowmappingcascadeSplits the camera frustum into four cascades, renders each split into a depth texture array layer, and samples the selected layer for directional shadows.Cascade shadow mapping
shadowmappingomniRenders the scene into the six faces of a floating-point cube map, stores point-light distance, and samples it for omni-directional shadows.Omni-directional shadow mapping
geometrydashRuns an original one-button rhythm platformer with fixed-step physics, procedural GPU geometry, obstacle collisions, jump pads, progress tracking, and responsive mouse, keyboard, and touch controls. This game was created at the request of my son, Ryan, who designed the concept and gameplay inspired by the original Geometry Dash game.Geometry dash WebGPU game
residentevil2Runs Claire outside the R.P.D. with GPU skinning, imported glTF idle, forward-running, and backward-walking animations, persistent tank controls, projected contact shadows, and three classic fixed-camera zones.Resident Evil 2 R.P.D. exterior fixed-camera scene

The residentevil2 example uses Claire Redfield - The Darkside Chronicles by many-bees under CC BY 4.0.

Running

Native:

cargo run --example triangle

WASM:

scripts/build-wasm.sh --release
cargo run --bin serve

Then open http://127.0.0.1:8080.

rust
webgpu
webgpu-engine
webgpu-step-by-step
webgpu-tutorial

PooyaEimandar/webgpu

Rust examples for learning WebGPU

HTML

16

104 commits

updated Oct 5, 2026

See the code

See what people are saying

SourceMessageScoreDate

Rust WebGPU Examples for Native and WASM

1

Oct 15, 2026

README

webgpu

Rust WebGPU examples porting Sascha Willems' Vulkan samples, with WASM and native support, based on the Sib render module.

Demo

Try the WASM demos here

Examples

ExampleDescriptionScreenshot
triangleRenders a colored indexed triangle using vertex and index buffers, WGSL vertex/fragment shaders, a render pipeline, and a depth attachment.Basic indexed triangle
vertexattributesRenders the same indexed mesh through interleaved and separate vertex attribute buffers using matching shader locations for position, normal, UV, and tangent data.Vertex attributes
particlesystemUpdates flame and smoke particles on the CPU, streams them into an instance buffer, and renders billboard sprites over a normal-mapped scene.CPU particle system
computeparticlesUpdates 262,144 particle records in 1,024 compute workgroups using ping-ponged storage buffers, then renders the GPU-written state as additive textured billboards.Rainbow WebGPU compute particles forming flowing bands across a black background
computeclothSimulates a spring-connected cloth grid in compute shaders, ping-pongs storage buffers, collides with a sphere, and renders the GPU-written cloth mesh.Compute cloth
computecullandlodCulls a dense object grid in a compute shader, buckets visible instances by LOD, writes indirect draw commands, and renders the compacted GPU instance buffers.Compute cull and LOD
naniteScales its Jax population to the detected GPU, streams requested geometry pages into a physical cache, selects projected-error meshlet LODs, and performs two-pass HZB occlusion with indirect draws.Nanite-style Jax meshlet rendering
metropolisRenders Sponza with GPU-skinned Jax crowds using clustered Forward+ lighting, compute frustum culling, indirect draws, physics, dynamic shadows, reflections, probe GI, particles, and temporal post-processing.Metropolis GPU-driven renderer
computenbodyEvaluates 150,994,944 ordered particle interactions per frame with tiled workgroup memory, integrates one in-place storage buffer, and renders 12,288 additive billboards with runtime egui controls.Luminous colored particle clusters evolving in the WebGPU N-body simulation beside live controls
computeraytracingRay traces spheres and planes in a compute shader, writing the result to a storage texture that is sampled by a fullscreen present pass.Compute shader ray tracing
raytracingshadowsCasts primary and secondary shadow rays in a compute shader, shading a procedural scene into a storage texture and dimming occluded hits.Ray traced shadows
raytracingreflectionsTraces recursive reflection bounces in a compute shader, treating bright objects as reflectors and falling back to a sky-gradient miss color.Ray tracing reflections
raytracinggltfRay traces a textured skinned glTF character by flattening animated mesh data into compute-friendly geometry buffers with egui skinning controls and joystick camera movement.Ray tracing glTF
restirdiResamples direct-light candidates across time and neighboring pixels, tracing visibility through compact static Sponza and dynamic skinned Jax SAH BVHs.ReSTIR direct illumination
restirgiReuses one-bounce indirect-light path reservoirs across time and space over the same Crytek Sponza scene and animated Jax character.ReSTIR global illumination
htmlmeshRenders a simple inline HTML button page to an RGBA texture, uploads it to WebGPU, maps it onto a plane, and ray-maps pointer input back to the button.HTML mesh
textureRenders a textured indexed quad using a runtime-loaded PNG texture, a sampler, uniform buffer transforms, and fragment shader lighting.Textured indexed quad
texturemipmapgenGenerates a full mip chain from a high-frequency texture using offscreen render passes, then samples the result on a textured tunnel.Texture mipmap generation
texturecubemapRenders a skybox and reflective sphere from six bundled KTX1 faces loaded at runtime, a cube texture view, and a filtering sampler.Runtime-loaded cubemap reflection
texturearrayRenders seven stacked squares sampling separate layers from a runtime-built 2D texture array with two async-loaded images, RGB layers, and procedural layers.Runtime-built texture array
textoverlayRenders glyph atlas text over a 3D scene using an overlay render pass, Unicode shaping, and RTL text.Text overlay
textmeshConverts shaped LTR and RTL font outlines into extruded indexed mesh geometry with vertex colors and lighting.3D text mesh
gltfLoads an official glTF 2.0 textured box from URL, converts buffers and material data to render meshes, and samples its base color texture.glTF textured box
gltfskinningLoads a textured animated glTF 2.0 character, uploads joints and weights, and skins vertices in the WGSL vertex shader.glTF vertex skinning
instancingRenders thousands of asteroid instances from one indexed mesh, using a per-instance vertex buffer for transform data and a 2D texture array for material variation.Instanced asteroid field
indirectdrawRenders many instanced plant submeshes from indexed indirect command buffers, with a skysphere, ground mesh, and per-instance transforms.Indirect draw jungle scene
pipelinesRenders the original treasure glTF scene through Phong, toon, and wireframe render pipelines in separate viewports.Multiple render pipelines
gearsRenders animated procedural toothed gears using indexed mesh buffers, per-gear uniform transforms, depth testing, and fragment shader lighting.Animated procedural gears
stencilbufferRenders a toon-shaded Venus mesh, writes stencil during the first draw, then draws a normal-expanded outline where stencil differs.Stencil buffer outline
occlusionqueryTests teapot and sphere visibility; native builds resolve occlusion-query samples, while WASM uses a browser-safe fallback and shades hidden meshes dark.Occlusion query visibility test
radialblurRenders a glow sphere to an offscreen target, samples it in a fullscreen radial blur pass, and blends the result over the lit scene.Radial blur glow sphere
bloomRenders glowing UFO parts to an offscreen target, runs separable Gaussian blur passes, and additively composites the bloom over the lit scene.Bloom offscreen rendering
deferredFills world-position, normal, and albedo G-buffer attachments with an animated skinned Jax character and checkerboard floor, then evaluates six lights in one fullscreen composition draw.Animated rabbit-like Jax character walking across a checkerboard floor under colored deferred lights
deferredmultisamplingStores four samples per position, normal, albedo, and depth G-buffer pixel, then shades each sample under six lights and averages the result in a single-sample fullscreen pass.Animated Jax character walking across a checkerboard floor under colored deferred lights rendered with 4x MSAA
deferredshadowsRenders animated Jax into three 1024×1024 Depth32Float maps, then evaluates eight spotlights and up to 27 comparison samples in the fullscreen deferred pass.Animated Jax character walking across a checkerboard floor under colorful spotlights casting multiple shadows
ssaoUses up to 32 screen-space spiral samples from the position, normal, and depth G-buffer, blurs the full-resolution AO mask with a weighted 5×5 kernel, and combines it with deferred shadows.Animated Jax character on a colorful checkerboard beside WebGPU SSAO controls
parallaxmappingRay-marches 48 height layers from a combined normal-height map on a flat two-triangle plane, then refines the UV intersection for parallax occlusion mapping.A flat plane appearing densely covered with raised rocks through parallax occlusion mapping
multisamplingRenders the textured Voyager in three indexed draws into 4x multisampled color and depth attachments, then resolves once into the surface.A white and black Voyager space probe with a dish antenna and long lattice boom
multisamplingalphatocoverageRenders instanced alpha-masked oak trees with 4x MSAA and alpha-to-coverage enabled for smoother foliage edges.Multisampling alpha-to-coverage oak trees
pbrRenders a 7x7 grid of procedural spheres with GGX/Schlick PBR shading, varying metallic and roughness per instance.PBR material grid
pbriblSamples irradiance, prefiltered environment mips, and a BRDF integration LUT for image-based PBR lighting.PBR image based lighting
pbrtextureRenders the Cerberus glTF mesh with albedo, normal, AO, metallic, and roughness maps under image-based PBR lighting.Textured PBR Cerberus model
shadowmappingRenders a depth-only light pass into a shadow map, then samples that depth texture in the scene pass for projected shadows with PCF filtering.Projected shadow mapping
shadowmappingcascadeSplits the camera frustum into four cascades, renders each split into a depth texture array layer, and samples the selected layer for directional shadows.Cascade shadow mapping
shadowmappingomniRenders the scene into the six faces of a floating-point cube map, stores point-light distance, and samples it for omni-directional shadows.Omni-directional shadow mapping
geometrydashRuns an original one-button rhythm platformer with fixed-step physics, procedural GPU geometry, obstacle collisions, jump pads, progress tracking, and responsive mouse, keyboard, and touch controls. This game was created at the request of my son, Ryan, who designed the concept and gameplay inspired by the original Geometry Dash game.Geometry dash WebGPU game
residentevil2Runs Claire outside the R.P.D. with GPU skinning, imported glTF idle, forward-running, and backward-walking animations, persistent tank controls, projected contact shadows, and three classic fixed-camera zones.Resident Evil 2 R.P.D. exterior fixed-camera scene

The residentevil2 example uses Claire Redfield - The Darkside Chronicles by many-bees under CC BY 4.0.

Running

Native:

cargo run --example triangle

WASM:

scripts/build-wasm.sh --release
cargo run --bin serve

Then open http://127.0.0.1:8080.

rust
webgpu
webgpu-engine
webgpu-step-by-step
webgpu-tutorial