Installation

The package, its peer dependencies, WebGPU requirements, and the device limits helper.
pnpm add @pmndrs/reflections three

With TypeScript, also install @types/three. The package is ESM only and needs WebGPU.

Peer dependencies

Every peer is optional, so you install only what you use.

PeerVersionYou need it for
three>=0.187.0The three.js adapter. r187 is the floor.
@babylonjs/core>=9.35.0 <10The Babylon adapter.
pixi.js>=8.22.0 <9The pixi adapter.
@pmndrs/raytracer^0.1.0The ray-traced fallback (rayTracing: true). The only ray-tracing provider.
@pmndrs/bvh^0.1.0The BVH that @pmndrs/raytracer walks. Install it with the raytracer.

For ray tracing, install both:

pnpm add @pmndrs/raytracer @pmndrs/bvh

The denoiser is not a peer on purpose. It plugs in through a small interface, so you pass an object in. Install it as its own package, denoiser ^2.0.0 (npm install denoiser). See Denoising and upscaling.

Each adapter has a page with its own install line and a minimal setup: three.js, React Three Fiber, Babylon.js, pixi.js. The adapter comparison lists what each one supports.

Entry points

ImportWhat it holds
@pmndrs/reflectionsThe three.js surface. Same as /three.
@pmndrs/reflections/threethree.js adapter.
@pmndrs/reflections/coreEngine-agnostic passes on a GPUDevice.
@pmndrs/reflections/babylonBabylon.js adapter (experimental).
@pmndrs/reflections/pixipixi.js adapter (experimental).

The package is ES modules only, with sideEffects: false.

Requirements

  • WebGPU. Current Chrome and Edge, and Safari Technology Preview, have it. There is no WebGL path.
  • Compute shaders and storage textures. Everything WebGPU gives you by default.
  • More device limits than the defaults. The G-buffer and the composite use more colour-attachment bytes and sampled textures than WebGPU's default limits allow. The next section shows how to ask for them. The ray-traced pass fits WebGPU's default of 8 storage buffers per stage in three's default setup (see Troubleshooting).
  • Optional features the library uses when the adapter has them: subgroups (a faster tracer variant) and timestamp-query (per-pass GPU times).

Ask for the right device limits

WebGPU gives you the default limits unless you ask for more. reflectionsRequiredLimits(adapter) returns the limits this library wants, clamped to what your adapter can do:

  • up to 64 colour-attachment bytes per sample (the default is 32), so the G-buffer can carry the lit image and three's exact specular weights;
  • up to 32 sampled textures per shader stage (the default is 16), so probe sets of several sizes fit next to a material's own maps;
  • the limits the depth downsampler needs for six-level mip dispatches.

With three, pass them when you create the renderer:

export async function createRenderer(canvas: HTMLCanvasElement): Promise<THREE.WebGPURenderer> {
  const adapter = await navigator.gpu.requestAdapter();
  if (!adapter) throw new Error('WebGPU is not available');
  const renderer = new THREE.WebGPURenderer({
    canvas,
    antialias: false,
    // Asks for the most the adapter allows, up to what the library uses.
    requiredLimits: reflectionsRequiredLimits(adapter),
  });
  await renderer.init();
  return renderer;
}

If you create the GPUDevice yourself (raw WebGPU, the core entry, pixi), pass the same object to adapter.requestDevice({ requiredLimits }). On an adapter that cannot give the extra limits, the library turns the optional G-buffer targets off and falls back to estimates. It does not crash. See Troubleshooting for the messages you may see.

Bundlers

Vite, webpack 5 (and so Next.js) and esbuild need no special configuration. Without @pmndrs/raytracer and @pmndrs/bvh installed, webpack prints a "Module not found" warning for each and builds; ray tracing then stays off with one console warning. With Vite, if you link the package from outside your project, add its folder to server.fs.allow.