Installation

Add the packages to a WebGPU project.
pnpm add @pmndrs/pathtracer @pmndrs/raytracer

@pmndrs/pathtracer depends on @pmndrs/raytracer, which depends on @pmndrs/bvh and @pmndrs/downsampler (texture mips on the GPU). Install @pmndrs/raytracer on its own if you only trace rays from your own shaders.

Requirements

  • A browser with WebGPU (see Browser and GPU support).
  • An ES module bundler: Vite, webpack 5, esbuild or Rollup. The packages are ESM only and ship modern JavaScript (ES2022).
  • TypeScript users: add @webgpu/types to compilerOptions.types.

Bundler notes

@pmndrs/bvh builds its trees in web workers. Vite pre-bundles dependencies by default, which breaks the worker URLs, so exclude it:

vite.config.ts
import { defineConfig } from 'vite';

export default defineConfig({
  optimizeDeps: { exclude: ['@pmndrs/bvh'] },
  build: { target: 'esnext' },
});

If the workers cannot load, the trees are still built on the main thread, only slower.

Versions

Both packages are released together from the repository. Keep them on the same version.