threejs-impl-webgpu
EXPERIMENTAL — The WebGPU renderer and TSL are under active development.
API surfaces may change between Three.js releases. Pin your Three.js version.
Quick Reference
WebGPURenderer Setup
import * as THREE from 'three/webgpu';
const renderer = new THREE.WebGPURenderer({ antialias: true });
await renderer.init(); // MUST await before first render
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setAnimationLoop(animate);
document.body.appendChild(renderer.domElement);
ALWAYS call await renderer.init() before the first renderer.render() call.
ALWAYS use renderer.setAnimationLoop(callback) instead of requestAnimationFrame.
NEVER call renderer.render() before init() resolves — this throws a runtime error.
Browser Support
| Browser |
Version |
Status |
| Chrome |
113+ |
Full support |
| Edge |
113+ |
Full support |
| Safari |
18+ |
Supported |
| Firefox |
Experimental |
Behind flag (dom.webgpu.enabled) |
Feature Detection and Fallback
import { WebGPU } from 'three/webgpu';
if (WebGPU.isAvailable()) {
const renderer = new THREE.WebGPURenderer({ antialias: true });
await renderer.init();
} else {
const renderer = new THREE.WebGLRenderer({ antialias: true });
}
ALWAYS check WebGPU.isAvailable() before creating a WebGPURenderer.
ALWAYS provide a WebGLRenderer fallback for unsupported browsers.
Critical Warnings
NEVER write raw GLSL or WGSL strings — ALWAYS use TSL functions. WebGPU compiles TSL to WGSL automatically. GLSL is NOT supported by the WebGPU backend.
NEVER use ShaderMaterial with WebGPURenderer — use NodeMaterial with TSL instead.
NEVER use requestAnimationFrame with WebGPURenderer — ALWAYS use renderer.setAnimationLoop().
NEVER use EffectComposer (three/examples) with WebGPURenderer — use the PostProcessing class with TSL nodes instead.
Node Materials
Every classic Three.js material has a node-based equivalent. Classic materials auto-convert when used with WebGPURenderer, but node materials provide full TSL customization.
Material Mapping
| Classic Material |
Node Material |
MeshBasicMaterial |
MeshBasicNodeMaterial |
MeshStandardMaterial |
MeshStandardNodeMaterial |
MeshPhysicalMaterial |
MeshPhysicalNodeMaterial |
MeshPhongMaterial |
MeshPhongNodeMaterial |
MeshLambertMaterial |
MeshLambertNodeMaterial |
LineBasicMaterial |
LineBasicNodeMaterial |
LineDashedMaterial |
LineDashedNodeMaterial |
PointsMaterial |
PointsNodeMaterial |
SpriteMaterial |
SpriteNodeMaterial |
ALWAYS import node materials from 'three/webgpu', not from 'three'.
NodeMaterial Input Properties
All properties accept TSL node values. All are optional and override defaults.
Common inputs (all node materials):
| Property |
TSL Type |
Purpose |
.colorNode |
vec4 |
Base color |
.opacityNode |
float |
Opacity |
.normalNode |
vec3 |
Normal map replacement |
.emissiveNode |
color |
Emissive output |
.positionNode |
vec3 |
Vertex displacement |
.fragmentNode |
vec4 |
Full fragment shader replacement |
.vertexNode |
vec4 |
Full vertex shader replacement |
.outputNode |
vec4 |
Final output override |
.aoNode |
float |
Ambient occlusion |
.alphaTestNode |
float |
Alpha test threshold |
.depthNode |
float |
Custom depth |
.castShadowNode |
vec4 |
Shadow casting override |
Standard/Physical inputs:
| Property |
TSL Type |
Purpose |
.metalnessNode |
float |
Metalness |
.roughnessNode |
float |
Roughness |
.envNode |
color |
Environment map |
.lightsNode |
— |
Lighting model override |
Physical-only inputs: .clearcoatNode, .clearcoatRoughnessNode, .clearcoatNormalNode, .sheenNode, .iridescenceNode, .iridescenceIORNode, .iridescenceThicknessNode, .specularIntensityNode, .specularColorNode, .iorNode, .transmissionNode, .thicknessNode, .attenuationDistanceNode, .attenuationColorNode, .dispersionNode, .anisotropyNode.
TSL (Three Shading Language)
TSL is a JavaScript-based node graph system that compiles to GLSL (WebGL2) and WGSL (WebGPU). It replaces raw shader strings entirely.
Type System
| Category |
Functions |
| Scalars |
float(), int(), uint(), bool() |
| Vectors |
vec2(), vec3(), vec4(), ivec2(), ivec3(), ivec4(), uvec2(), uvec3(), uvec4() |
| Matrices |
mat2(), mat3(), mat4() |
| Color |
color() |
| Conversion |
.toFloat(), .toVec3(), .toColor() |
Variables and Uniforms
| Function |
Purpose |
uniform(value) |
GPU-side dynamic value |
toVar(node) |
Reusable shader variable |
toConst(node) |
Inline constant |
varying(node) |
Vertex-to-fragment interpolation |
vertexStage(node) |
Force computation in vertex shader |
attribute(name, type) |
Access buffer attributes |
Uniforms support callbacks: .onRenderUpdate(fn), .onFrameUpdate(fn), .onObjectUpdate(fn).
Operators
All operators are chainable on TSL nodes:
- Arithmetic:
.add(), .sub(), .mul(), .div(), .mod()
- Comparison:
.equal(), .notEqual(), .lessThan(), .greaterThan(), .lessThanEqual(), .greaterThanEqual()
- Logical:
.and(), .or(), .not(), .xor()
- Assignment:
.assign(), .addAssign(), .subAssign(), .mulAssign(), .divAssign()
- Bitwise:
.bitAnd(), .bitOr(), .bitXor(), .shiftLeft(), .shiftRight()
Geometry Nodes
| Category |
Nodes |
| Position |
positionGeometry, positionLocal, positionWorld, positionView, positionWorldDirection, positionViewDirection |
| Normal |
normalGeometry, normalLocal, normalView, normalWorld |
| Tangent |
tangentGeometry, tangentLocal, tangentView, tangentWorld |
| UV |
uv(index) |
| Screen |
screenUV, screenCoordinate, screenSize |
| Viewport |
viewportUV, viewportCoordinate, viewportSize |
Camera and Model Nodes
- Camera:
cameraNear, cameraFar, cameraPosition, cameraProjectionMatrix, cameraViewMatrix, cameraWorldMatrix, cameraNormalMatrix
- Model:
modelViewMatrix, modelNormalMatrix, modelWorldMatrix, modelPosition, modelScale, modelDirection
Animation Nodes
| Node |
Purpose |
time |
Elapsed seconds since start |
deltaTime |
Frame delta in seconds |
oscSine(timer) |
Sine oscillator (0-1) |
oscSquare(timer) |
Square wave oscillator |
oscTriangle(timer) |
Triangle wave oscillator |
oscSawtooth(timer) |
Sawtooth oscillator |
Texture Operations
| Function |
Purpose |
texture(tex, uv, level) |
Sample with interpolation |
textureLoad(tex, uv, level) |
Sample without interpolation |
textureStore(tex, uv, value) |
Write to storage texture |
textureSize(tex, level) |
Get texture dimensions |
cubeTexture(tex, uvw, level) |
Sample cube map |
triplanarTexture(texX, texY, texZ, scale, position, normal) |
Triplanar mapping |
Control Flow
ALWAYS use capital If — lowercase if is JavaScript, not TSL.
If(condition, () => {
// true branch
}).ElseIf(otherCondition, () => {
// else-if branch
}).Else(() => {
// false branch
});
select(condition, trueVal, falseVal) — ternary operator
Loop(count, ({ i }) => { }) — GPU loop, supports Break(), Continue()
Switch(value).Case(val, fn).Default(fn) — no fallthrough
Discard() — discard fragment
Return() — early return
Function Definition
const myFn = Fn(([param1, param2]) => {
return param1.add(param2);
});
// Call: myFn(nodeA, nodeB)
Compute Shaders
WebGPU enables general-purpose GPU compute via TSL. Compute shaders are NOT available in WebGL fallback mode.
Setup
import { compute, storage } from 'three/webgpu';
const computeNode = compute(shaderFn, count, workgroupSize);
await renderer.computeAsync(computeNode);
ALWAYS use await renderer.computeAsync() — compute dispatch is asynchronous.
Storage and Atomics
- Storage:
storage(attribute, type, count), storageTexture(texture)
- Atomics:
atomicAdd(), atomicSub(), atomicMax(), atomicMin(), atomicAnd(), atomicOr(), atomicXor(), atomicStore(), atomicLoad()
- Barriers:
workgroupBarrier(), storageBarrier(), textureBarrier()
- Built-in IDs:
workgroupId, localId, globalId, numWorkgroups, subgroupSize
WebGPU Post-Processing
NEVER use the WebGL EffectComposer with WebGPURenderer. Use the PostProcessing class instead.
import { PostProcessing } from 'three/webgpu';
import { bloom, renderOutput } from 'three/tsl';
const postProcessing = new PostProcessing(renderer);
const scenePass = renderOutput(scene, camera);
postProcessing.outputNode = bloom(scenePass);
Available Post-Processing Nodes
bloom(), dof(), fxaa(), smaa(), gaussianBlur(), ssr(), ssgi(), ao(), chromaticAberration(), film(), dotScreen(), sobel(), afterImage(), anamorphic(), denoise(), lut3D(), motionBlur(), outline(), rgbShift(), transition(), traa(), renderOutput()
Color Operations
luminance(), saturation(), vibrance(), hue(), posterize(), grayscale(), sepia()
Blend Modes
blendBurn(), blendDodge(), blendOverlay(), blendScreen(), blendColor()
WebGL to WebGPU Migration
| Step |
Action |
| 1 |
Replace import * as THREE from 'three' with import * as THREE from 'three/webgpu' |
| 2 |
Replace new WebGLRenderer() with new WebGPURenderer() and add await renderer.init() |
| 3 |
Replace classic materials with NodeMaterial equivalents (or keep classic — they auto-convert) |
| 4 |
Replace EffectComposer with PostProcessing class and TSL post-processing nodes |
| 5 |
Replace raw GLSL ShaderMaterial with TSL-based NodeMaterial |
| 6 |
Replace requestAnimationFrame with renderer.setAnimationLoop() |
ALWAYS make the entry point async when using WebGPURenderer — renderer.init() returns a Promise.
Reference Links
- references/methods.md — API signatures for WebGPURenderer, NodeMaterial, TSL, compute
- references/examples.md — Working code examples for WebGPU scenes
- references/anti-patterns.md — Common mistakes and how to avoid them
Official Sources
1---2name: threejs-impl-webgpu3description: Use when using the Three.js WebGPU renderer, node-based materials, TSL (Three Shading Language), or compute shaders. Prevents the common mistake of not checking browser support, missing async init, or using GLSL with WebGPU. Covers WebGPURenderer, node materials, TSL, compute shaders, WebGL fallback, migration guide. Keywords: WebGPU, WebGPURenderer, TSL, Three Shading Language, node material, compute shader, WGSL, MeshStandardNodeMaterial, next-gen rendering, modern GPU, WebGPU setup.4license: MIT5---67# threejs-impl-webgpu89> **EXPERIMENTAL** — The WebGPU renderer and TSL are under active development.10> API surfaces may change between Three.js releases. Pin your Three.js version.1112## Quick Reference1314### WebGPURenderer Setup1516```javascript17import * as THREE from 'three/webgpu';1819const renderer = new THREE.WebGPURenderer({ antialias: true });20await renderer.init(); // MUST await before first render21renderer.setSize(window.innerWidth, window.innerHeight);22renderer.setAnimationLoop(animate);23document.body.appendChild(renderer.domElement);24```2526**ALWAYS** call `await renderer.init()` before the first `renderer.render()` call.27**ALWAYS** use `renderer.setAnimationLoop(callback)` instead of `requestAnimationFrame`.28**NEVER** call `renderer.render()` before `init()` resolves — this throws a runtime error.2930### Browser Support3132| Browser | Version | Status |33|---------|---------|--------|34| Chrome | 113+ | Full support |35| Edge | 113+ | Full support |36| Safari | 18+ | Supported |37| Firefox | Experimental | Behind flag (`dom.webgpu.enabled`) |3839### Feature Detection and Fallback4041```javascript42import { WebGPU } from 'three/webgpu';4344if (WebGPU.isAvailable()) {45 const renderer = new THREE.WebGPURenderer({ antialias: true });46 await renderer.init();47} else {48 const renderer = new THREE.WebGLRenderer({ antialias: true });49}50```5152**ALWAYS** check `WebGPU.isAvailable()` before creating a WebGPURenderer.53**ALWAYS** provide a WebGLRenderer fallback for unsupported browsers.5455### Critical Warnings5657**NEVER** write raw GLSL or WGSL strings — ALWAYS use TSL functions. WebGPU compiles TSL to WGSL automatically. GLSL is NOT supported by the WebGPU backend.5859**NEVER** use `ShaderMaterial` with WebGPURenderer — use `NodeMaterial` with TSL instead.6061**NEVER** use `requestAnimationFrame` with WebGPURenderer — ALWAYS use `renderer.setAnimationLoop()`.6263**NEVER** use `EffectComposer` (three/examples) with WebGPURenderer — use the `PostProcessing` class with TSL nodes instead.6465---6667## Node Materials6869Every classic Three.js material has a node-based equivalent. Classic materials auto-convert when used with WebGPURenderer, but node materials provide full TSL customization.7071### Material Mapping7273| Classic Material | Node Material |74|-----------------|---------------|75| `MeshBasicMaterial` | `MeshBasicNodeMaterial` |76| `MeshStandardMaterial` | `MeshStandardNodeMaterial` |77| `MeshPhysicalMaterial` | `MeshPhysicalNodeMaterial` |78| `MeshPhongMaterial` | `MeshPhongNodeMaterial` |79| `MeshLambertMaterial` | `MeshLambertNodeMaterial` |80| `LineBasicMaterial` | `LineBasicNodeMaterial` |81| `LineDashedMaterial` | `LineDashedNodeMaterial` |82| `PointsMaterial` | `PointsNodeMaterial` |83| `SpriteMaterial` | `SpriteNodeMaterial` |8485**ALWAYS** import node materials from `'three/webgpu'`, not from `'three'`.8687### NodeMaterial Input Properties8889All properties accept TSL node values. All are optional and override defaults.9091**Common inputs (all node materials):**9293| Property | TSL Type | Purpose |94|----------|----------|---------|95| `.colorNode` | `vec4` | Base color |96| `.opacityNode` | `float` | Opacity |97| `.normalNode` | `vec3` | Normal map replacement |98| `.emissiveNode` | `color` | Emissive output |99| `.positionNode` | `vec3` | Vertex displacement |100| `.fragmentNode` | `vec4` | Full fragment shader replacement |101| `.vertexNode` | `vec4` | Full vertex shader replacement |102| `.outputNode` | `vec4` | Final output override |103| `.aoNode` | `float` | Ambient occlusion |104| `.alphaTestNode` | `float` | Alpha test threshold |105| `.depthNode` | `float` | Custom depth |106| `.castShadowNode` | `vec4` | Shadow casting override |107108**Standard/Physical inputs:**109110| Property | TSL Type | Purpose |111|----------|----------|---------|112| `.metalnessNode` | `float` | Metalness |113| `.roughnessNode` | `float` | Roughness |114| `.envNode` | `color` | Environment map |115| `.lightsNode` | — | Lighting model override |116117**Physical-only inputs:** `.clearcoatNode`, `.clearcoatRoughnessNode`, `.clearcoatNormalNode`, `.sheenNode`, `.iridescenceNode`, `.iridescenceIORNode`, `.iridescenceThicknessNode`, `.specularIntensityNode`, `.specularColorNode`, `.iorNode`, `.transmissionNode`, `.thicknessNode`, `.attenuationDistanceNode`, `.attenuationColorNode`, `.dispersionNode`, `.anisotropyNode`.118119---120121## TSL (Three Shading Language)122123TSL is a JavaScript-based node graph system that compiles to GLSL (WebGL2) and WGSL (WebGPU). It replaces raw shader strings entirely.124125### Type System126127| Category | Functions |128|----------|-----------|129| Scalars | `float()`, `int()`, `uint()`, `bool()` |130| Vectors | `vec2()`, `vec3()`, `vec4()`, `ivec2()`, `ivec3()`, `ivec4()`, `uvec2()`, `uvec3()`, `uvec4()` |131| Matrices | `mat2()`, `mat3()`, `mat4()` |132| Color | `color()` |133| Conversion | `.toFloat()`, `.toVec3()`, `.toColor()` |134135### Variables and Uniforms136137| Function | Purpose |138|----------|---------|139| `uniform(value)` | GPU-side dynamic value |140| `toVar(node)` | Reusable shader variable |141| `toConst(node)` | Inline constant |142| `varying(node)` | Vertex-to-fragment interpolation |143| `vertexStage(node)` | Force computation in vertex shader |144| `attribute(name, type)` | Access buffer attributes |145146Uniforms support callbacks: `.onRenderUpdate(fn)`, `.onFrameUpdate(fn)`, `.onObjectUpdate(fn)`.147148### Operators149150All operators are chainable on TSL nodes:151152- **Arithmetic:** `.add()`, `.sub()`, `.mul()`, `.div()`, `.mod()`153- **Comparison:** `.equal()`, `.notEqual()`, `.lessThan()`, `.greaterThan()`, `.lessThanEqual()`, `.greaterThanEqual()`154- **Logical:** `.and()`, `.or()`, `.not()`, `.xor()`155- **Assignment:** `.assign()`, `.addAssign()`, `.subAssign()`, `.mulAssign()`, `.divAssign()`156- **Bitwise:** `.bitAnd()`, `.bitOr()`, `.bitXor()`, `.shiftLeft()`, `.shiftRight()`157158### Geometry Nodes159160| Category | Nodes |161|----------|-------|162| Position | `positionGeometry`, `positionLocal`, `positionWorld`, `positionView`, `positionWorldDirection`, `positionViewDirection` |163| Normal | `normalGeometry`, `normalLocal`, `normalView`, `normalWorld` |164| Tangent | `tangentGeometry`, `tangentLocal`, `tangentView`, `tangentWorld` |165| UV | `uv(index)` |166| Screen | `screenUV`, `screenCoordinate`, `screenSize` |167| Viewport | `viewportUV`, `viewportCoordinate`, `viewportSize` |168169### Camera and Model Nodes170171- **Camera:** `cameraNear`, `cameraFar`, `cameraPosition`, `cameraProjectionMatrix`, `cameraViewMatrix`, `cameraWorldMatrix`, `cameraNormalMatrix`172- **Model:** `modelViewMatrix`, `modelNormalMatrix`, `modelWorldMatrix`, `modelPosition`, `modelScale`, `modelDirection`173174### Animation Nodes175176| Node | Purpose |177|------|---------|178| `time` | Elapsed seconds since start |179| `deltaTime` | Frame delta in seconds |180| `oscSine(timer)` | Sine oscillator (0-1) |181| `oscSquare(timer)` | Square wave oscillator |182| `oscTriangle(timer)` | Triangle wave oscillator |183| `oscSawtooth(timer)` | Sawtooth oscillator |184185### Texture Operations186187| Function | Purpose |188|----------|---------|189| `texture(tex, uv, level)` | Sample with interpolation |190| `textureLoad(tex, uv, level)` | Sample without interpolation |191| `textureStore(tex, uv, value)` | Write to storage texture |192| `textureSize(tex, level)` | Get texture dimensions |193| `cubeTexture(tex, uvw, level)` | Sample cube map |194| `triplanarTexture(texX, texY, texZ, scale, position, normal)` | Triplanar mapping |195196### Control Flow197198**ALWAYS** use capital `If` — lowercase `if` is JavaScript, not TSL.199200```javascript201If(condition, () => {202 // true branch203}).ElseIf(otherCondition, () => {204 // else-if branch205}).Else(() => {206 // false branch207});208```209210- `select(condition, trueVal, falseVal)` — ternary operator211- `Loop(count, ({ i }) => { })` — GPU loop, supports `Break()`, `Continue()`212- `Switch(value).Case(val, fn).Default(fn)` — no fallthrough213- `Discard()` — discard fragment214- `Return()` — early return215216### Function Definition217218```javascript219const myFn = Fn(([param1, param2]) => {220 return param1.add(param2);221});222// Call: myFn(nodeA, nodeB)223```224225---226227## Compute Shaders228229WebGPU enables general-purpose GPU compute via TSL. Compute shaders are NOT available in WebGL fallback mode.230231### Setup232233```javascript234import { compute, storage } from 'three/webgpu';235236const computeNode = compute(shaderFn, count, workgroupSize);237await renderer.computeAsync(computeNode);238```239240**ALWAYS** use `await renderer.computeAsync()` — compute dispatch is asynchronous.241242### Storage and Atomics243244- **Storage:** `storage(attribute, type, count)`, `storageTexture(texture)`245- **Atomics:** `atomicAdd()`, `atomicSub()`, `atomicMax()`, `atomicMin()`, `atomicAnd()`, `atomicOr()`, `atomicXor()`, `atomicStore()`, `atomicLoad()`246- **Barriers:** `workgroupBarrier()`, `storageBarrier()`, `textureBarrier()`247- **Built-in IDs:** `workgroupId`, `localId`, `globalId`, `numWorkgroups`, `subgroupSize`248249---250251## WebGPU Post-Processing252253**NEVER** use the WebGL `EffectComposer` with WebGPURenderer. Use the `PostProcessing` class instead.254255```javascript256import { PostProcessing } from 'three/webgpu';257import { bloom, renderOutput } from 'three/tsl';258259const postProcessing = new PostProcessing(renderer);260const scenePass = renderOutput(scene, camera);261postProcessing.outputNode = bloom(scenePass);262```263264### Available Post-Processing Nodes265266`bloom()`, `dof()`, `fxaa()`, `smaa()`, `gaussianBlur()`, `ssr()`, `ssgi()`, `ao()`, `chromaticAberration()`, `film()`, `dotScreen()`, `sobel()`, `afterImage()`, `anamorphic()`, `denoise()`, `lut3D()`, `motionBlur()`, `outline()`, `rgbShift()`, `transition()`, `traa()`, `renderOutput()`267268### Color Operations269270`luminance()`, `saturation()`, `vibrance()`, `hue()`, `posterize()`, `grayscale()`, `sepia()`271272### Blend Modes273274`blendBurn()`, `blendDodge()`, `blendOverlay()`, `blendScreen()`, `blendColor()`275276---277278## WebGL to WebGPU Migration279280| Step | Action |281|------|--------|282| 1 | Replace `import * as THREE from 'three'` with `import * as THREE from 'three/webgpu'` |283| 2 | Replace `new WebGLRenderer()` with `new WebGPURenderer()` and add `await renderer.init()` |284| 3 | Replace classic materials with NodeMaterial equivalents (or keep classic — they auto-convert) |285| 4 | Replace `EffectComposer` with `PostProcessing` class and TSL post-processing nodes |286| 5 | Replace raw GLSL `ShaderMaterial` with TSL-based `NodeMaterial` |287| 6 | Replace `requestAnimationFrame` with `renderer.setAnimationLoop()` |288289**ALWAYS** make the entry point `async` when using WebGPURenderer — `renderer.init()` returns a Promise.290291---292293## Reference Links294295- [references/methods.md](references/methods.md) — API signatures for WebGPURenderer, NodeMaterial, TSL, compute296- [references/examples.md](references/examples.md) — Working code examples for WebGPU scenes297- [references/anti-patterns.md](references/anti-patterns.md) — Common mistakes and how to avoid them298299### Official Sources300301- https://threejs.org/docs/302- https://github.com/mrdoob/three.js/wiki/Three.js-Shading-Language303- https://threejs.org/examples/?q=webgpu