three.js WebGPURenderer and TSL

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

WebGPURenderer is the renderer of three.js that targets WebGPU and, when WebGPU is not available, falls back to a WebGL 2 backend with the same scene API. Materials are no longer written as GLSL strings: they are built from small JavaScript objects called nodes, using the Three.js Shading Language (TSL), and the library turns the graph into WGSL for WebGPU or GLSL ES 3.00 for WebGL 2. This page explains how to switch the Bookshelf from WebGLRenderer to WebGPURenderer, how TSL works, how to give the book titles a glowing material, how compute and post-processing change, and what to check when migrating an older code base.

The general concepts behind this page are in Shading Languages Landscape.

The facts were checked in November 2026 against three.js r187 (npm three@0.187.0, published 2026-10-30), the three.js API documentation, the TSL wiki page and the Migration Guide. WebGPU and WGSL are W3C Candidate Recommendation Drafts and WebGPU is not yet Baseline on MDN; it needs a secure context (HTTPS or localhost). Browser support moves quickly, so use the table on WebGPU Overview and Comparison and test navigator.gpu at run time instead of trusting version numbers. The code runs in any current evergreen browser because of the WebGL 2 fallback, and it is built with Vite like the rest of the three.js track (see three.js Getting Started).

This page is the last step of the Bookshelf three.js track: the GLB shelf from bookshelf.glb has been loaded (Loading Models with glTF), lit with PBR, orbited, clicked and played with, and given bloom with the WebGL path of Post-processing. Here the same scene moves to WebGPURenderer, the cover material gets a TSL "glowing title" and bloom is rebuilt with RenderPipeline. For GLSL-based customisation on WebGLRenderer see Custom Shaders in GLSL.

Two renderers, one scene API

Flow from new WebGPURenderer to await init, then a check for an adapter and forceWebGL leading to the WebGPU backend using WGSL or the WebGL 2 backend using GLSL, both feeding the same scene and node materials
Figure 1. How WebGPURenderer picks a backend

Scene, Object3D, cameras, geometries, textures, AnimationMixer and the glTF loaders are shared. What differs is the renderer class and what can be attached to it:

Topic WebGLRenderer (entry point three) WebGPURenderer (entry point three/webgpu)

Backends

WebGL 2 only (WebGL 1 was dropped in r163)

WebGPU, with an automatic WebGL 2 fallback; forceWebGL: true always selects WebGL 2

Initialisation

Synchronous constructor, ready at once

Asynchronous: await renderer.init(), or let setAnimationLoop initialise it

Custom shaders

ShaderMaterial, RawShaderMaterial, onBeforeCompile, GLSL chunks

Node materials and TSL; ShaderMaterial and onBeforeCompile are not supported

Post-processing

EffectComposer with passes

RenderPipeline (named PostProcessing until r182) with TSL nodes

Compute

none

compute nodes through renderer.compute(), full capability on the WebGPU backend

Shadow filter

PCFShadowMap; PCFSoftShadowMap deprecated since r182

PCFShadowMap (soft); PCFSoftShadowMap removed in r186

The two renderers live in different entry points. Importing everything from three/webgpu gives a build that contains the node materials and WebGPURenderer; TSL functions come from three/tsl; ready-made effects such as bloom are in three/addons/tsl/display/. Mixing the three and three/webgpu entry points in one bundle is a classic source of "two copies of three.js" problems, so pick one entry point per application. A bundler such as Vite resolves both from node_modules/three, see Bundling and Publishing and JavaScript Modules.

Creating the renderer

Table 1. Constructor options of WebGPURenderer
Option Default Meaning

antialias

false

MSAA on the default framebuffer; 4 samples unless samples says otherwise

samples

0

Overrides the sample count when antialias is true

alpha

true

Whether the canvas is transparent

depth, stencil

true, false

Depth and stencil buffers of the default framebuffer

forceWebGL

false

Use the WebGL 2 backend even when WebGPU is available (useful for testing the fallback)

logarithmicDepthBuffer

false

Logarithmic depth; ignored when reversedDepthBuffer is used

reversedDepthBuffer

false

Reversed depth range for better precision at distance

outputBufferType

HalfFloatType

Type of the internal output buffers; UnsignedByteType saves memory and bandwidth at some quality cost. This option was called colorBufferType before r182

outputType

device preference

Texture type of the canvas output; other formats may add overhead

multiview

false

Use multiview for WebXR rendering when supported

The first listing is the complete entry point of the Bookshelf three.js track after the switch. It uses the Timer that replaced Clock in r183, an animation loop, and a resize handler that caps the pixel ratio (the topic of Performance and Disposal).

// main.js (Vite project, three@0.187)
import * as THREE from 'three/webgpu';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

const renderer = new THREE.WebGPURenderer( { antialias: true } );
renderer.setPixelRatio( Math.min( window.devicePixelRatio, 2 ) );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

// init() is asynchronous: it requests the adapter and device, or builds the WebGL 2 fallback.
await renderer.init();

const isWebGPU = renderer.backend.isWebGPUBackend === true;
console.log( isWebGPU ? 'Backend: WebGPU' : 'Backend: WebGL 2 fallback' );

const scene = new THREE.Scene();
scene.background = new THREE.Color( 0x1b1d26 );

const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 100 );
camera.position.set( 0, 1.6, 4 );

const controls = new OrbitControls( camera, renderer.domElement );
controls.target.set( 0, 1, 0 );

scene.add( new THREE.HemisphereLight( 0xffffff, 0x334455, 1.2 ) );
const lamp = new THREE.DirectionalLight( 0xffffff, 2.5 );
lamp.position.set( 3, 5, 2 );
scene.add( lamp );

const gltf = await new GLTFLoader().loadAsync( '/bookshelf.glb' );
scene.add( gltf.scene );

const timer = new THREE.Timer();
timer.connect( document );

window.addEventListener( 'resize', () => {
	camera.aspect = window.innerWidth / window.innerHeight;
	camera.updateProjectionMatrix();
	renderer.setSize( window.innerWidth, window.innerHeight );
} );

renderer.setAnimationLoop( ( timestamp ) => {
	timer.update( timestamp );
	controls.update();
	renderer.render( scene, camera );
} );

Things the listing shows and the table above summarises:

  • init() returns a promise and resolves when the device (or the fallback context) exists. render() may only be called after that. Inside a loop started with setAnimationLoop the initialisation is guaranteed, so the explicit await is only strictly needed for on-demand rendering, for feature detection like isWebGPUBackend, and for code that uses the renderer before the first frame.

  • Since r181 the *Async methods renderAsync(), computeAsync(), clearAsync(), initTextureAsync() and hasFeatureAsync() are deprecated; the synchronous methods work once the renderer is initialised. Older tutorials that await renderer.renderAsync() every frame still work but print deprecation warnings.

  • KTX2Loader.detectSupportAsync() is deprecated since r181: call detectSupport( renderer ) after await renderer.init().

  • renderer.backend is the active backend. isWebGPUBackend is a flag used in the three.js examples to tell the two apart; it is a convenience for logging and branching, not a stable public contract, so keep branches on it small.

Node materials and what happens to old materials

WebGPURenderer renders every material through the node system. The classic classes still work: a MeshStandardMaterial coming out of GLTFLoader is mapped by the renderer to its node counterpart (MeshStandardNodeMaterial) behind the scenes. That is why the Bookshelf looks the same after the switch with no change to the loading code. Node materials add a family of *Node properties that replace a stage of the shader with a node graph.

Property Replaces

colorNode

The base colour (diffuse colour times map)

emissiveNode

The emissive colour otherwise derived from emissive, emissiveIntensity and emissiveMap

roughnessNode, metalnessNode

Roughness and metalness otherwise derived from the numbers and maps

positionNode

The vertex position in the vertex stage

opacityNode, normalNode, outputNode

Alpha, the shading normal and the final fragment colour

A property such as emissiveNode replaces the built-in value completely. To modify the existing value instead of replacing it, the node library offers accessors such as materialEmissive, materialRoughness and materialMetalness, so material.roughnessNode = materialRoughness.mul( 0.5 ) halves the value that the maps would have produced.

TSL: the Three.js Shading Language

TSL is a JavaScript API for building shader graphs. Every function call returns a node; nothing runs on the GPU until the renderer compiles the graph that is attached to a material. This has three consequences that shape the code you write.

  1. Operators are methods. JavaScript has no operator overloading, so a + b * c is written a.add( b.mul( c ) ). The method names are add, sub, mul, div, sin, cos, pow, mix and so on, matching the GLSL and WGSL built-ins.

  2. Constants are baked, uniforms are live. A JavaScript number inside the graph is compiled into the shader. A uniform( value ) node is a slot you can change at run time without recompiling.

  3. One graph, two languages. The NodeBuilder walks the graph once per backend and emits WGSL for WebGPU or GLSL ES 3.00 for WebGL 2.

A TSL expression becomes a node graph, the NodeBuilder emits WGSL for the WebGPU backend and GLSL ES 3.00 for the WebGL 2 backend
Figure 2. One TSL graph compiled to WGSL or GLSL

The shader fragments in the figure are illustrative: the generated code has its own variable names and structure, but the arithmetic is what the graph encodes. The compiled result is cached, so a material with the same graph is compiled once per backend.

The building blocks

TSL function Use

uniform( value )

A value that can change without recompiling; hooks onObjectUpdate(), onRenderUpdate() and onFrameUpdate() update it automatically

uv( index )

The UV attribute as a vec2

texture( tex, uvNode )

Samples a texture and returns a vec4; the default coordinates are uv()

time, deltaTime

Float nodes with the elapsed seconds and the frame delta

color(), float(), vec2(), vec3(), vec4()

Typed constants and constructors

mix( x, y, a )

Linear interpolation, like the shader built-in

Fn( ( [ args ] ) => ... )

A reusable function node; required to use assign and conditionals

If( cond, fn ), Loop( ... )

Control flow; If is capitalised and chains .ElseIf() and .Else()

positionLocal, positionWorld, normalLocal

Geometry and transform inputs

instanceIndex, instancedArray( ... )

Per-instance index and a GPU storage array for compute

The Fn wrapper is the part that surprises people who know GLSL. A plain JavaScript function that returns nodes is fine for expressions, because it simply builds the graph, but statements that look like imperative shader code (assigning to a variable, If) need Fn, which records them as shader statements instead of executing them in JavaScript:

import { Fn, vec3, If, positionLocal } from 'three/tsl';

// Clamp the height of a vertex: an If inside Fn becomes a real shader branch.
const limitPosition = Fn( ( { position } ) => {
	const limit = 10;
	const result = vec3( position );

	If( result.y.greaterThan( limit ), () => {
		result.y = limit;
	} );

	return result;
} );

material.positionNode = limitPosition( { position: positionLocal } );

Two release-note details matter for new code: since r187 the operands of TSL math functions are implicitly coerced to a broader common type and since r181 the constant formerly called PI2 is TWO_PI. Since r185, in a node assigned to material.positionNode of a skinned mesh, use positionGeometry instead of positionLocal or the skinned transform is not applied.

The glowing title

The book covers in bookshelf.glb use one shared "Cover" material with a texture. The goal is a soft pulse on the covers, as if the titles were backlit, without touching the texture, normal map or lighting. That is exactly what emissiveNode is for.

Node graph: time times pulse speed plus uv x times six goes through sine and a scale and offset, is multiplied by the glow colour uniform and drives emissiveNode
Figure 3. The glowing title as a TSL graph

The pulse is \( p(u, t) = \tfrac{ 1 }{ 2 } \sin( s\,t + 6u ) + \tfrac{ 1 }{ 2 } \), with \( t \) the time in seconds, \( s \) the speed uniform and \( u \) the horizontal texture coordinate. The emissive colour is the glow colour multiplied by \( p \). Because \( 6u \) varies across the cover, the pulse sweeps over the book from left to right instead of flashing uniformly.

// glowing-title.js
import * as THREE from 'three/webgpu';
import { Fn, uniform, uv, time, sin, color } from 'three/tsl';

export const glow = {
	color: uniform( new THREE.Color( 0xffb347 ) ),
	speed: uniform( 2.0 )
};

// Reusable node: a 0..1 pulse that sweeps along the horizontal UV axis.
const pulse = Fn( () => {
	const phase = time.mul( glow.speed ).add( uv().x.mul( 6.0 ) );
	return sin( phase ).mul( 0.5 ).add( 0.5 );
} );

/**
 * Replaces the cover material of every book in the loaded glTF scene with a node material
 * that keeps the original textures and adds a pulsing emissive term.
 */
export function applyGlowingTitles( root ) {
	const cache = new Map();

	root.traverse( ( object ) => {
		if ( ! object.isMesh ) return;

		const materials = Array.isArray( object.material ) ? object.material : [ object.material ];

		const replaced = materials.map( ( old ) => {
			if ( old.name !== 'Cover' ) return old;
			if ( cache.has( old ) ) return cache.get( old );

			const node = new THREE.MeshStandardNodeMaterial( {
				map: old.map,
				normalMap: old.normalMap,
				roughness: old.roughness,
				metalness: old.metalness
			} );
			node.name = 'CoverGlow';
			node.emissiveNode = glow.color.mul( pulse() );

			cache.set( old, node );
			return node;
		} );

		object.material = Array.isArray( object.material ) ? replaced : replaced[ 0 ];
	} );
}

Call applyGlowingTitles( gltf.scene ) after loading. Because glow.color and glow.speed are uniforms, a debug panel or the click handler can change them every frame without recompiling anything:

// In the pointer handler of the "pull the book out" interaction:
function highlight( book ) {
	glow.speed.value = 6.0;                 // faster pulse while selected
	glow.color.value.set( 0xffe08a );       // brighter colour
}

function unhighlight() {
	glow.speed.value = 2.0;
	glow.color.value.set( 0xffb347 );
}

The material works on both backends: the same graph becomes WGSL on WebGPU and GLSL ES 3.00 on the fallback. Two practical points:

  • The glow is a single shared material, so every book pulses together. To select one book, give it its own clone of the node material (the cache above keys on the old material, so create a second node per book instead).

  • The emissive value is added to the lit result, it is not multiplied by light. With bloom (see below) the brightest part of the pulse is what blooms, so keep the emissive intensity near 1 and let the bloom threshold do the work.

Compute nodes

A compute node is TSL code that runs once per element of a GPU storage buffer, not once per pixel or vertex. In the Bookshelf it moves the "dust" motes around the lamp without touching the CPU. instancedArray allocates a storage buffer, instanceIndex is the index of the current invocation, and .compute( count ) turns an Fn into a dispatchable node.

// dust.js
import * as THREE from 'three/webgpu';
import { Fn, instancedArray, instanceIndex, deltaTime, float, If } from 'three/tsl';

const COUNT = 2000;

export function createDust( renderer ) {
	// Initial positions on the CPU; the array is uploaded once.
	const initial = new Float32Array( COUNT * 3 );
	for ( let i = 0; i < COUNT; i ++ ) {
		initial[ i * 3 ] = ( Math.random() - 0.5 ) * 4;
		initial[ i * 3 + 1 ] = Math.random() * 3;
		initial[ i * 3 + 2 ] = ( Math.random() - 0.5 ) * 2;
	}

	const positions = instancedArray( initial, 'vec3' );

	// One invocation per mote: fall slowly and wrap around at the floor.
	const update = Fn( () => {
		const p = positions.element( instanceIndex );
		p.y.subAssign( deltaTime.mul( 0.2 ) );
		If( p.y.lessThan( 0 ), () => {
			p.y.assign( 3 );
		} );
	} )().compute( COUNT );

	// Render the motes as camera-facing sprites that read their position from the same buffer.
	const material = new THREE.SpriteNodeMaterial( { transparent: true, opacity: 0.5 } );
	material.positionNode = positions.toAttribute();
	material.scaleNode = float( 0.02 );

	const sprites = new THREE.Sprite( material );
	sprites.count = COUNT;

	return { sprites, step: () => renderer.compute( update ) };
}

Use it in the loop before drawing: const dust = createDust( renderer ); scene.add( dust.sprites ); and call dust.step() at the start of every frame. Compute needs the WebGPU backend for its full capability; on the WebGL 2 fallback compute support is limited, so a production build checks renderer.backend.isWebGPUBackend and either skips the effect or computes it on the CPU there. The signature is compute( computeNodes, dispatchSize ), where the size may be a count, an [x, y, z] array or an indirect storage buffer; the return value is a promise only in some situations, so do not rely on it. computeAsync() is deprecated since r181 together with the other *Async methods.

Post-processing with RenderPipeline

Storyboard of five panels: import three/webgpu, await init, replace ShaderMaterial with node materials, replace EffectComposer with RenderPipeline and bloom, check which backend ran
Figure 4. Where the pieces of the Bookshelf migration go

EffectComposer does not work with WebGPURenderer. Its replacement is RenderPipeline, a class that owns the full frame: you describe the final output as a TSL node and call renderPipeline.render() instead of renderer.render(). The class was named PostProcessing until r182 and was renamed RenderPipeline in r183; old code that still uses the old name needs the rename, and its renderAsync() is deprecated like the rest of the async methods.

import * as THREE from 'three/webgpu';
import { pass } from 'three/tsl';
import { bloom } from 'three/addons/tsl/display/BloomNode.js';

// Bloom for the glowing titles. renderer, scene, camera and controls come from main.js.
const renderPipeline = new THREE.RenderPipeline( renderer );

const scenePass = pass( scene, camera );
const sceneColor = scenePass.getTextureNode();

// bloom( node, strength, radius, threshold )
const bloomPass = bloom( sceneColor, 0.7, 0.4, 0.85 );

// The output node is the last node of the chain: scene colour plus the blurred highlights.
renderPipeline.outputNode = sceneColor.add( bloomPass );

renderer.setAnimationLoop( ( timestamp ) => {
	timer.update( timestamp );
	controls.update();
	renderPipeline.render();   // not renderer.render( scene, camera )
} );

Set renderPipeline.needsUpdate = true after you replace outputNode at run time. The renderer can only use a RenderPipeline with WebGPURenderer. Several effect nodes changed in recent releases (see the checklist), for instance AnamorphicNode was removed in r185 in favour of BloomNode, and GTAONode AO is in the red channel only since r181.

Migration checklist from WebGLRenderer

If your code does this Do this instead Since

new THREE.WebGLRenderer() imported from the three entry point

new THREE.WebGPURenderer() imported from three/webgpu, then await renderer.init()

-

ShaderMaterial, RawShaderMaterial

A node material with colorNode, positionNode, emissiveNode and TSL; keep the GLSL version on WebGLRenderer if it must stay

-

material.onBeforeCompile to patch shader chunks

Replace the stage with a node (colorNode, outputNode, …​) or extend through Fn

-

EffectComposer, RenderPass, UnrealBloomPass

RenderPipeline, pass() and bloom() from three/addons/tsl/display/

-

new PostProcessing( renderer )

new RenderPipeline( renderer )

r183

renderAsync(), computeAsync(), clearAsync(), initTextureAsync(), hasFeatureAsync()

Synchronous render(), compute() and so on, after init()

r181 (deprecated)

new THREE.Clock()

new THREE.Timer() with timer.update( timestamp )

r183

renderer.shadowMap.type = THREE.PCFSoftShadowMap

THREE.PCFShadowMap, which is soft on WebGPURenderer

r182 (WebGL deprecated), r186 (WebGPU removed)

colorBufferType option, getColorBufferType()

outputBufferType, getOutputBufferType()

r182

WebGLCubeRenderTarget

CubeRenderTarget

r183

KTX2Loader.detectSupportAsync( renderer )

detectSupport( renderer ) after await renderer.init()

r181

TSL PI2

TWO_PI

r181

TSL directionToColor(), colorToDirection()

packNormalToRGB(), unpackRGBToNormal()

r185

renderer.library.addLight( ... )

CustomLight.registerNode( CustomLightNode )

r187

Screen looks too dark or semi-transparent against a transparent clear

Premultiplied alpha changed; set an opaque scene.background or renderer.setClearColor()

r185

The Migration Guide recommends upgrading in steps of about ten releases, because deprecation warnings last about that long, and reading the console after each step. PMREM environment maps became cube-render-target based in r187 and the old CubeUVReflectionMapping was removed, so image-based lighting can look slightly different after the upgrade.

Where the books are outdated

Book and chapter What it says Today

LTJ ch. 11, TCB ch. 6

Post-processing is EffectComposer with a chain of passes

Still valid with WebGLRenderer (plus an OutputPass); WebGPURenderer uses RenderPipeline. See Post-processing

LTJ ch. 4 and 11, TCB ch. 5

Custom shaders are GLSL ES 1.00 strings in ShaderMaterial

ShaderMaterial is a WebGLRenderer feature; on WebGPURenderer the shader is a TSL node graph compiled to WGSL or GLSL ES 3.00

PAR ch. 3, 7

WebGL 1.0 is the only backend

WebGLRenderer is WebGL 2 only since r163; WebGPURenderer adds a WebGPU backend

All books

The animation loop is requestAnimationFrame plus THREE.Clock

setAnimationLoop and THREE.Timer

None of the three books covers WebGPU, WGSL or TSL, so the sections above derive from the official documentation only.

Pitfalls

  • Forgetting await renderer.init() before the first manual render() gives an error about an uninitialised renderer; with setAnimationLoop the initialisation is automatic.

  • Mixing the three and three/webgpu entry points produces objects from two copies of the library that do not recognise each other. Use three/webgpu everywhere, including the addons that you import.

  • Using GLSL features in a node material: strings of GLSL do not go into colorNode. Express the logic with TSL, or keep that material on WebGLRenderer.

  • Comparing frame times between backends: the fallback is WebGL 2 with a different cost model, so profile on the backend your users get.

  • Compute on the fallback: guard compute-driven effects behind the backend check.

  • Testing only on one browser: use forceWebGL: true to exercise the fallback on a machine that has WebGPU.

See it in

The same renderer concepts in the neighbouring pages: WebGPU Overview and Comparison (the raw API behind this renderer), Materials and PBR (the classic material properties that the node properties override), and Performance and Disposal (releasing the resources this page creates).