Part of the cinematic pipeline: entry point creative-studio
WebGPU and WGSL
Use for browser GPU work: shaders, compute, large particle or data scenes, post-processing. Facts dated 2026-10 come from MDN, W3C WebGPU/WGSL specs, webgpufundamentals.org, three.js docs; re-verify on caniuse/MDN before a production commitment.
Related skills (link, do not repeat)
- Rendering theory (PBR, IBL, shadows, color, engine choice):
graphics-rendering - Motion principles, CSS/WAAPI/GSAP/Lottie/Rive choice, reduced motion:
motion-animation - Design baseline and when 3D is worth it:
modern-web-design-standards - Generative 2D art in code:
anthropic-skills:algorithmic-art; React animation patterns:framer-motion-skill - Frame-perfect video from code:
motion-reel,hyperframes*,remotion-* - Browser verification of a canvas:
browser-testing-with-devtools(real Chrome; screenshots can lie about motion)
Decision gate (do this first)
- Does the effect need GPU at all? Gradient, blur, parallax, scroll reveal: use CSS. Read
modern-web-design-standards. - Scene graph, loaders, PBR, shadows needed: use three.js (
references/threejs-tsl.md), not raw WebGPU. - Custom compute (particles 100k+, sim, filters, data-viz of 1M points) or one bespoke shader: raw WebGPU.
- Need to reach everyone: three.js WebGPURenderer with automatic WebGL2 fallback, or raw WebGPU plus a WebGL2 path.
- Heavy native-class scenes: Unreal or Godot export (see
graphics-rendering/references/engine-choice.md).
Workflow
- Feature-detect:
if (!navigator.gpu) -> fallback; thenawait navigator.gpu.requestAdapter(); null means no adapter, fallback. - Request only features you need (
adapter.features.has(...)); request raised limits explicitly, defaults are low. - Configure canvas context with
navigator.gpu.getPreferredCanvasFormat(),alphaMode: "opaque"unless compositing. - Build pipelines once, bind groups once, reuse. Per frame: write uniforms, encode, submit.
- Size canvas to
clientWidth * devicePixelRatio(clamp DPR to 2 on mobile), resize via ResizeObserver, never in rAF. - Wrap creation in error scopes during development; listen to
device.lostanduncapturederror. - Respect
prefers-reduced-motion; provide a static or paused frame and a keyboard/pause control. - Verify in real Chrome plus one non-Chromium browser; measure with timestamp queries, not guesses.
Hard rules and pitfalls
- Uniform struct layout:
vec3faligns to 16 bytes, so pack af32after it; mirror layout in JS with oneFloat32Arrayand named offsets. Seereferences/wgsl-reference.md. bytesPerRowfor texture-to-buffer copies must be a multiple of 256. Dynamic uniform offsets must be multiples ofminUniformBufferOffsetAlignment(256 default).- Read-write storage buffers are not usable in vertex stage; read-only storage is.
textureSampleneeds uniform control flow; usetextureSampleLevelortextureLoadinside branches or loops.- Presenting: get
context.getCurrentTexture()each frame, never cache it across frames. - Destroy buffers and textures you no longer need (
.destroy()), otherwise memory leaks until GC. - Color: render HDR in
rgba16float, tonemap once at the end, output format sRGB-encoded (-srgbview or manual encode). Never tonemap twice. - Pipeline compile stalls: use
createRenderPipelineAsyncand warm up pipelines before the first visible frame. - Do not read GPU results back per frame (
mapAsyncstalls); keep data on GPU, use indirect draws. ShaderMaterial,RawShaderMaterial,onBeforeCompiledo not work in three.js WebGPURenderer; use TSL.
Reference map (open only what the task needs)
| Need | File |
|---|---|
| Setup, buffers, textures, bind groups, pipelines, loop, resize, errors, fallback | references/webgpu-core.md |
| WGSL syntax, types, address spaces, alignment, builtins, pitfalls | references/wgsl-reference.md |
| Fullscreen shader, instancing, compute particles, GPU-driven animation | references/recipes-basic.md |
| Post chain (bloom, tonemap, FXAA, TAA), SDF raymarch, image filters, GPU chart | references/recipes-advanced.md |
| three.js WebGPURenderer, TSL, compute in three | references/threejs-tsl.md |
| Profiling, timestamp queries, debugging, mobile limits, a11y, support matrix | references/perf-debug-a11y-support.md |
| Tiny verified shader | templates/fullscreen.wgsl, templates/fullscreen.html |
Learning sources (paraphrased, not copied)
W3C WebGPU and WGSL specs; MDN WebGPU API; webgpufundamentals.org; Chrome developer docs and Dawn; three.js WebGPURenderer manual and TSL wiki; Babylon.js WebGPU docs; wgpu (Rust, same API shape); Inigo Quilez articles (SDF, raymarching); The Book of Shaders; GPU Gems; Learn OpenGL.
Output contract
Deliver runnable code (single HTML or module), the fallback path, the reduced-motion behavior, the support note with date, and the measured frame cost if a browser was available. State which parts are unverified.