Source code

Rust WebGPU examples

WASM and native wgpu ports of Sascha Willems' Vulkan rendering samples.

Colored indexed triangle screenshot triangle Colored indexed triangle with vertex and index buffers. Vertex attributes screenshot vertex attributes Interleaved and separate vertex attribute buffers using the same shader locations. CPU particle system screenshot CPU particle system CPU-updated fire and smoke particles rendered as instanced billboard quads. Compute particles screenshot compute particles Storage-buffer particles updated by a compute shader and rendered as textured billboards. N-body simulation screenshot N-body simulation Compute shader particle attraction with tiled workgroup memory and runtime egui controls. Compute shader ray tracing screenshot compute shader ray tracing Compute shader software ray tracing into a storage texture, displayed by a fullscreen present pass. Ray traced shadows screenshot ray traced shadows Primary and secondary shadow rays traced in a compute shader over procedural scene geometry. Ray tracing reflections screenshot ray tracing reflections Recursive reflection bounces traced in a compute shader with a sky-gradient miss path. Ray tracing glTF screenshot ray tracing glTF Compute ray tracing over a skinned and textured glTF mesh with runtime skinning controls. HTML mesh screenshot HTML mesh Offline-rasterized HTML surface mapped onto a 3D plane with ray-mapped pointer and keyboard input. Textured indexed quad screenshot texture Textured indexed quad with a runtime-loaded PNG texture and sampler. Texture mipmap generation screenshot texture mipmap generation GPU-generated mip chain sampled on a high-frequency textured tunnel. Runtime-loaded cubemap reflection screenshot texture cubemap Skybox and reflective sphere from six runtime-loaded cubemap faces. Runtime-built texture array screenshot texture array Seven stacked squares sampling separate layers from a runtime-built texture array. Text overlay screenshot text overlay Glyph atlas text rendered over a 3D scene with Unicode shaping and RTL text. 3D text mesh screenshot text mesh Shaped LTR and RTL font outlines converted into indexed 3D mesh geometry. glTF textured box screenshot glTF Official glTF 2.0 textured box loaded from URL and converted to mesh data. glTF vertex skinning screenshot glTF vertex skinning Animated glTF 2.0 character with joint indices, weights, and shader skinning. Instanced asteroid field screenshot instancing Thousands of asteroid instances sharing one indexed mesh and sampling texture-array layers. Indirect draw jungle scene screenshot indirect draw Instanced plant submeshes rendered from indexed indirect command data. Multiple render pipelines screenshot pipelines Original treasure glTF scene rendered through Phong, toon, and wireframe pipelines. Animated procedural gears screenshot gears Animated procedural toothed gears with per-gear transforms, depth, and lighting. Stencil buffer outline screenshot stencil buffer Toon-shaded Venus mesh with a normal-expanded outline masked by stencil operations. Occlusion query screenshot occlusion queries Teapot and sphere visibility test with native occlusion-query readback and a browser-safe WASM fallback. Radial blur glow sphere screenshot radial blur Offscreen glow color pass composited back with an additive fullscreen radial blur. Bloom offscreen rendering screenshot bloom Offscreen glow color pass blurred vertically and horizontally, then additively composited over the lit scene. Deferred shading G-buffer composition screenshot deferred shading Position, normal, and albedo attachments filled in an MRT pass, then composed with six animated lights. Multi sampled deferred shading screenshot multi sampled deferred shading 4x MSAA G-buffer attachments manually resolved in the fullscreen deferred lighting pass. Deferred shadows screenshot deferred shadows Three shadow-map layers rendered with vertex-only depth passes and sampled during deferred composition. Screen space ambient occlusion screenshot screen space ambient occlusion Deferred depth and normals generate a blurred ambient occlusion mask for shadowed composition. Parallax occlusion mapping screenshot parallax mapping Normal mapping and parallax occlusion mapping using a combined normal-height texture. Multisampled Voyager glTF model screenshot multisampling Voyager glTF rendered into 4x MSAA color and depth targets, then resolved into the swapchain. Multisampling alpha-to-coverage oak trees screenshot multisampling alpha to coverage Instanced alpha-masked oak trees rendered with 4x MSAA and alpha-to-coverage foliage edges. PBR material grid screenshot PBR basic GGX/Schlick material grid with metallic and roughness varied per sphere instance. PBR image based lighting screenshot PBR image based lighting Irradiance, prefiltered environment mips, and BRDF LUT sampling for image-based PBR. Textured PBR Cerberus model screenshot PBR texture Cerberus glTF rendered with albedo, normal, AO, metallic, and roughness texture maps. Projected shadow mapping screenshot shadow mapping Depth-only light pass sampled as a projected shadow map with PCF filtering. Cascade shadow mapping screenshot shadow mapping cascade Four frustum splits rendered into a layered depth texture, with the fragment shader sampling the matching cascade. Omni-directional shadow mapping screenshot omni directional shadow mapping Six cube-map light passes store point-light distance, then the scene shader samples the cube map for omni-directional shadows.