three.js
@pmndrs/vdb/three is the only part of the package that imports three. three is an optional peer dependency, pinned to
>=0.187.0 <0.188.0 (r187): VDBGridNode reaches into three's WebGPU backend, which is not public API, so each three
release is checked before the range widens. Another revision warns once. It needs WebGPURenderer on the WebGPU
backend. getDevice throws VDB_UNSUPPORTED_DEVICE before await renderer.init() and on the WebGL fallback.
What is in it
Create the device first
There is no renderer bootstrap. Request the adapter's device with the pool's limits and give it to three, so the
pool outlives renderer.dispose() and shares the device with other tools:
import { WebGPURenderer } from 'three/webgpu';
import { VDBGridPool } from '@pmndrs/vdb';
import { getDevice } from '@pmndrs/vdb/three';
// The host owns the device. Pass it to three, so renderer.dispose() never destroys it or the pool's buffer.
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) throw new Error('No WebGPU adapter');
const device = await adapter.requestDevice({ requiredLimits: VDBGridPool.requiredLimits(adapter) });
const renderer = new WebGPURenderer({ device });
await renderer.init();
getDevice(renderer) === device; // true: the renderer's WebGPU backend holds your device
const pool = await VDBGridPool.create(getDevice(renderer));
If three creates its own device instead, renderer.dispose() destroys that device, and the pool's buffer with it.
The rules
- One
VDBGridNodeper renderer. A node binds through one renderer's backend: make a second node for a second renderer, even on the same device. - One VDB module per shader. A shader holds at most one module, so every grid one shader reads goes through one
VDBGridNode. Both rules are checked when three builds a shader (VDB_BAD_OPTION). - Stage, flush, then render. Pool changes reach the GPU at
pool.update(encoder)orpool.flush(), before three renders. - Call
grids.update()each frame. It rebinds after a growth. Nothing recompiles. - Perspective cameras for
VDBVolumeMaterial. Its view ray ispositionWorld - cameraPosition.
VDBGridNode also installs a guard over three's attribute destruction, so renderer.dispose() and a stand-in's
dispose() never destroy the pool's buffer, and the first node on a backend self-tests that guard before any pool
buffer reaches three (VDB_ENGINE_MISMATCH if three would destroy a buffer behind it).