Trying three.js's WebGPU renderer
three.
three.js has had a WebGPU renderer for a while, but using it together with the addons meant import-map or bundler aliases, because the WebGPU build carried its own copy of the three.js core. Since r171 at the end of last year, both builds share one core file, and it’s an ordinary import. I’ve been trying it on r177, and the renderer itself is the easy part. The real change is how you write materials and shaders.
The switch
import * as THREE from 'three/webgpu';
const renderer = new THREE.WebGPURenderer({ antialias: true });
renderer.setPixelRatio(devicePixelRatio);
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(50, innerWidth / innerHeight, 0.1, 100);
camera.position.z = 4;
const mesh = new THREE.Mesh(
new THREE.TorusKnotGeometry(1, 0.3, 200, 32),
new THREE.MeshStandardMaterial({ color: 0x2194ce }),
);
scene.add(mesh, new THREE.HemisphereLight(0xffffff, 0x444444, 3));
renderer.setAnimationLoop(() => {
mesh.rotation.y += 0.01;
renderer.render(scene, camera);
});
That looks almost exactly like WebGL code, and that’s the point. Two things are different underneath.
Initialisation is async. Getting a WebGPU device returns a promise. setAnimationLoop waits for it for you. If you call renderer.render() yourself straight after creating the renderer, you get a warning instead of a frame: “.render() called before the backend is initialized. Try using .renderAsync() instead.” Either use setAnimationLoop, or await renderer.init() first.
It falls back to WebGL 2. If the browser has no WebGPU, the same renderer runs on a WebGL 2 backend and logs “WebGPU is not available, running under WebGL2 backend.” You don’t need two code paths. To test the fallback on a machine that does have WebGPU, pass forceWebGL: true.
The built-in materials (MeshStandardMaterial, MeshBasicMaterial, MeshPhysicalMaterial and the rest) are converted to their node-based versions automatically, so most scenes render unchanged.
What doesn’t carry over: GLSL
Here’s the catch. ShaderMaterial, RawShaderMaterial and onBeforeCompile all rely on GLSL strings, and the WebGPU renderer doesn’t use them. If your project has custom shaders, those are what you’ll be rewriting.
The replacement is TSL, the three.js Shading Language. It’s not a new text language. It’s JavaScript functions that build a shader graph, which three.js compiles to WGSL for WebGPU or GLSL for the WebGL fallback:
import * as THREE from 'three/webgpu';
import { color, mix, uv, uniform, positionLocal, sin, time, vec3 } from 'three/tsl';
const tint = uniform(new THREE.Color('#ff6a00'));
const material = new THREE.MeshStandardNodeMaterial();
// colour: blend from blue at the bottom to the tint at the top
material.colorNode = mix(color('#0b3d91'), tint, uv().y);
// shape: a gentle wave that moves over time
material.positionNode = positionLocal.add(
vec3(0, sin(time.add(positionLocal.x)).mul(0.1), 0),
);
// later, from normal JavaScript:
tint.value.set('#22c55e');
What I like about it, coming from GLSL:
- It’s the same material. You keep lighting, shadows and fog from MeshStandardNodeMaterial, and only replace the parts you want (colorNode, positionNode, normalNode and others). With ShaderMaterial you started from nothing, or patched strings with onBeforeCompile.
- Uniforms are just objects. Change tint.value and the next frame uses it. No material.uniforms.uTint.value and no name strings to keep in sync.
- Editor support. It’s JavaScript, so autocomplete, imports and refactoring all work.
What takes getting used to is method chaining instead of operators: a.add(b).mul(c) instead of (a + b) * c. And when something goes wrong, the error is in generated WGSL you didn’t write, which can take a moment to map back to your code.
Post-processing changed too
EffectComposer and its passes are WebGL-only. The WebGPU renderer has its own PostProcessing class, built from the same TSL nodes:
import { pass } from 'three/tsl';
import { bloom } from 'three/addons/tsl/display/BloomNode.js';
const postProcessing = new THREE.PostProcessing(renderer);
const scenePass = pass(scene, camera);
const sceneColor = scenePass.getTextureNode('output');
postProcessing.outputNode = sceneColor.add(bloom(sceneColor, 0.8, 0.2, 0.9));
renderer.setAnimationLoop(() => postProcessing.render());
The effect chain is an expression rather than a list of passes, which makes combining effects feel more natural.
Should you switch?
It depends on what’s in your project.
- Built-in materials, no custom shaders: switching is mostly an import change, and the WebGL fallback means you don’t lose any users. It’s a low-risk way to try it.
- Lots of custom GLSL: budget real time. Every shader becomes TSL, and every EffectComposer pass needs a replacement. Do one shader first to see how it goes.
- Heavy GPU work, like particles or simulations: this is where WebGPU’s compute shaders, also written in TSL, make the move most worthwhile.
The classic WebGLRenderer isn’t going away, and the two builds share the same core, so nothing forces your hand. But new features are landing on the WebGPU side, and TSL works with both backends. If you start a new project in 2025, I’d start it there.