WebGPU renders by building a pipeline — a fixed description of how data flows from your buffers through shaders to the screen.
Compute pipelines skip all of this — they just run a shader on arbitrary data.
WebGPU uses WGSL (WebGPU Shading Language) — a Rust-like language that runs on the GPU.
@vertex fn
@fragment fn
@compute fn
vec2f, vec3f, vec4f
mat4x4f
Click </> Shaders above the canvas to view each experiment's WGSL source.
GPU memory is managed through buffers:
Buffers are connected to shader bindings via bind groups — the @group(0) @binding(0) annotations in WGSL.
@group(0) @binding(0)
Compute shaders run massively parallel — thousands of invocations at once.
@workgroup_size(64)
@workgroup_size(8,8)
dispatchWorkgroups(n)
The Particle System, Game of Life, Fluid Sim, and Reaction-Diffusion experiments all use compute shaders.
Many simulations read from one buffer and write to another, then swap. This avoids reading data you just wrote in the same frame.
On even frames: read A, write B.On odd frames: read B, write A.
Used in Particle System, Game of Life, Fluid Sim, and Reaction-Diffusion.
Raymarching renders 3D scenes without any geometry — just a fragment shader.
For each pixel, march a ray forward. At each step, a signed distance function (SDF) tells you how far you are from the nearest surface.
sdSphere(p, r)
sdBox(p, b)
smin(a, b, k)
WebGPU can sample image data via textures and samplers:
texture_2d<f32>
sampler
textureSample(tex, samp, uv)
A texture atlas packs many images into one texture. Each tile maps to a UV sub-region. Combined with LOD (level of detail), this enables efficient rendering of large zoomable maps.
The Tile Map experiment demonstrates atlas generation, viewport culling, and LOD switching.
vertex_index
instance_index
performance.now()