three.js
The three.js adapter is the main one. It has every feature in the library: probes, screen-space reflections, the
ray-traced fallback, the denoiser seam, presets and the hybrid resolve. Reflections.create sets them all up in one
call. See the adapter comparison for the other engines.
It needs WebGPURenderer from three/webgpu (r187 or newer) and works with MeshStandardMaterial and
MeshPhysicalMaterial, and their node versions.
Install
pnpm add @pmndrs/reflections threepnpm add @pmndrs/raytracer @pmndrs/bvh denoiserMinimal setup
This is examples/quickstart without its
scene and controls. Reflections.create builds the G-buffer, the screen-space pass, a baked probe, the denoiser and
the composite in a RenderPipeline.
// A WebGPURenderer with the device limits the passes need, already initialised.
const renderer = await createReflectionsRenderer({ canvas, antialias: false });
const reflections = await Reflections.create(renderer, scene, {
preset: 'default', // or 'performance'
rayTracing: false, // true needs @pmndrs/raytracer and @pmndrs/bvh
denoiser: (device, { roughnessThreshold }) => new FfxReflectionDenoiser(device, { roughnessThreshold: roughnessThreshold ** 2 }),
});
// Where you called renderer.render(scene, camera):
renderer.setAnimationLoop(() => reflections.render(camera));
The options are in the quick start. After the scene or its
environment changes, call reflections.bake(). Every piece stays public on the object: reflections.ssr,
.hybrid, .probes, .trace and .pipeline.
For a cheaper start with no extra passes, bake probes only. See the quick start. To build the frame yourself, see first frame and the sections below.
Device limits
The passes ask for more than WebGPU's default limits: up to 64 colour-attachment bytes per sample (the default is 32)
and up to 32 sampled textures per stage (the default is 16). createReflectionsRenderer asks for them for you. To
build the renderer yourself, pass requiredLimits: reflectionsRequiredLimits(adapter) to WebGPURenderer
(Installation).
The ray-traced pass binds 8 storage buffers per stage in three's default setup, which is WebGPU's default limit. It runs
on a plain device. If a configuration needs more, the pass warns once, sets pass.traceError, and screen space and
probes continue. See Troubleshooting.
A plain new WebGPURenderer() works, with one console warning. Its default colour-attachment limit (32 bytes per
sample) cannot hold the G-buffer and the lit image together (36), so the scene is drawn a second time for the lit
image and three's specular weights are estimated. Use createReflectionsRenderer, or pass
requiredLimits: reflectionsRequiredLimits(adapter), to avoid the extra draw.
Known gaps
- Basic, Lambert and Phong materials get no reflections, by design. Use a standard material.
- On three r187, probes need
installCubeArraySupport(renderer)to use a real cube array.Reflections.createdoes it for you. Without it, probes use a 2D array. - The ray-traced BVH is built once. Moving meshes need
reflections.trace.refit()each frame. Changed geometry needs a new build. - One
Reflectionsper canvas. - Without a denoiser, glossy reflections are noisy.
Live example
The quickstart runs this page's setup. The showcase runs the whole pipeline on real scenes, with each source switchable. three.js has every feature on the two rooms that all the engine pages share, and Materials shows which materials get reflections. The examples page lists them all.
The pieces
Reflections is built from these. Use them directly to wire the frame yourself.
The render loop
Each frame, in this order:
ssr.render(scene, camera) // 1. G-buffer + trace
hybrid.update() // 2. resolve + denoise
pipeline.render() // 3. composite into your output
ssr.render replaces renderer.render(scene, camera) for the scene, because it renders the scene into the G-buffer.
The composite node (hybrid.composite().final) is the lit image with the reflections in place. Put it in a
RenderPipeline, or into your own post-processing chain.
Resizing
The pass sizes its G-buffer from gbufferOptions: { width, height } (default: the renderer's size). When the canvas
changes size, resize the G-buffer and reset the history so the denoiser does not blend frames of different sizes:
ssr.gbuffer.setSize(width, height);
ssr.resetHistory();
hybrid.resetHistory();
Several composites
hybrid.composite() can be called again for another place the reflections show, such as a debug view or a second
camera's uv. Build the composites again after you change reflectionResolution (hybrid.rebuild(), then
composite()), because they read different textures at half resolution.
Camera cuts and jitter
Call resetHistory() on a camera cut or a teleport. For an upscaler or TAA, pass the jitter to
ssr.render(scene, camera, { jitter }). The showcase's DisplayAA helper (examples/shared/antialias.ts) shows the
whole wiring with @pmndrs/upscaler.