Level sets and points

VDBLevelSetMaterial and VDBLevelSetPhysicalMaterial trace an OpenVDB level set's surface on the sparse pool; VDBPoints draws point grids.

Level sets

VDBLevelSetMaterial is a MeshStandardNodeMaterial that draws the zero surface of a NanoVDB level set (a signed distance grid) by tracing it on the sparse pool, at the grid's full resolution. Lights, shadows, depth and fog are three's own. Give it a VDBGridNode made with profile 'march' and the 'levelSet' helper, and a mesh with an identity transform and vdbProxyGeometry(pool.info(id), { pad: 1 }). The grid is placed with pool.setTransform, not with the mesh.

The trace is the core's vdbLevelSetHit (an HDDA skip over empty space, then a trilinear sample of the distance field), and the normal is a central difference of that field (normalStep: 0: the exact gradient of the trilinear cell the trace hits). It works with perspective and orthographic cameras, so directional-light shadow maps trace too. maxSamples (samples per fragment) and normalStep are live uniforms, and the trace is exposed as TSL nodes (hitWorldNode, normalViewNode, ...) for custom shading.

See the level sets demo: four OpenVDB level sets, each in its own pool, traced at full resolution with an HDR sky and shadows.

Glass and clearcoat

VDBLevelSetPhysicalMaterial is the same trace on three's MeshPhysicalNodeMaterial: transmission, ior, thickness, attenuationColor and attenuationDistance, dispersion, clearcoat, sheen and iridescence work on the traced surface. Its options and nodes are VDBLevelSetMaterial's, plus three's physical parameters.

import { Mesh } from 'three/webgpu';
import { VDBGridNode, VDBLevelSetPhysicalMaterial, vdbProxyGeometry } from '@pmndrs/vdb/three';

const grids = new VDBGridNode(renderer, pool, { profile: 'march', helpers: ['levelSet'] });
// Three's physical material on the traced surface: transmission refracts from the hit, thickness in world units.
const glass = new VDBLevelSetPhysicalMaterial(renderer, grids, id, {
    color: 0xffffff,
    roughness: 0.04,
    transmission: 1,
    ior: 1.5,
    thickness: 0.2,
    attenuationColor: 0xbfe3ff,
    attenuationDistance: 0.8,
    // Copy the frame before this piece draws, so it sees glass drawn before it (one copy per piece).
    backdrop: 'object',
});
scene.add(new Mesh(vdbProxyGeometry(pool.info(id), { pad: 1 }), glass));
// Coloured shadows: the shadow map carries the light the glass lets through.
renderer.shadowMap.transmitted = true;
// Lacquer instead: { clearcoat: 1, clearcoatRoughness: 0.05 } (the clearcoat uses the traced normal).

Transmission is three's screen-space refraction: the surface shows the frame behind it, bent by the traced normal, as MeshPhysicalMaterial glass does on a mesh. It starts the refracted ray at the traced hit, not at the proxy box (whose back face three's own model would read), and thickness is in world units. Anisotropy needs mesh tangents and does not apply.

  • Glass behind glass. three copies the frame once per render, at the first transmissive draw, so by default a glass surface does not see other glass through itself. backdrop: 'object' copies the frame (with its mips) before every draw of that material instead: three sorts transparent objects back to front, so each piece sees the glass behind it. It costs one framebuffer copy per glass piece per frame.
  • Coloured shadows. With renderer.shadowMap.transmitted = true (set it before the first render) the material casts the light it lets through, transmission · color · (1 − F0)² · attenuation over thickness, instead of black: three's transmitted shadow map, with this tint as the material's castShadowNode (set your own castShadowNode to override it). The shadow map keeps the nearest caster's colour, so glass in front of an opaque piece tints that piece's shadow instead of leaving it black.
  • Specular antialiasing. specularAntialiasing: true (off by default) widens the roughness (and the clearcoat roughness) by how much the traced normal turns across the pixel (Tokuyoshi and Kaplanyan's geometric specular antialiasing). three's own term reads the proxy box's flat normal and adds nothing on a traced surface, so a low-roughness highlight on a crease lands on a few pixel centres with extreme values. With it, a clearcoat at roughness 0.04 on the teapot's lid comes 3.4 times closer to a supersampled frame in linear colour and its brightest pixels drop from ~140 to ~2. In a tone-mapped image lit by an environment it can look worse (the widened clearcoat roughness blurs the reflection across a crease: ACES error on the teapot lid 1.7 times higher in demo 13's studio lighting), so use it where linear peaks matter (bloom, HDR output). The materials set roughnessNode for it: a roughnessNode of your own replaces it.
  • Thin grooves alias. One ray per pixel samples a groove narrower than a pixel at a few pixel centres, so it shows as specks; no normal or roughness setting fixes that. Render more rays per pixel (a higher pixel ratio, or more frames). MSAA does not help: a traced surface has no triangle edges inside the proxy box. Demo 13 averages 16 frames jittered over a 4×4 sub-pixel grid while the camera rests (examples/src/demos/jitter-accumulator.ts: render each frame into a half-float target with camera.setViewOffset(w, h, dx, dy, w, h), keep the running mean in linear colour, tone map after). The converged frame is the 4×4 supersampled one. While the camera moves, use a temporal resolve with the hit's velocity (next section); three's stock TRAA wiring is no substitute, because its velocity buffer holds the proxy box's motion.

Temporal antialiasing and upscalers

A temporal resolve (three's TRAA, @pmndrs/upscaler, a pass of your own) needs a velocity buffer: for each pixel, how far its surface point moved on screen since the previous frame. three's velocity node computes it from the rasterized vertex, and for a level-set material that vertex is on the proxy box, not on the traced surface. The resolve then fetches its history from another surface point, and the result can be worse than no antialiasing at all (numbers below).

VDBLevelSetVelocityNode writes the velocity of the traced hit instead. Put one in the MRT of the pass that draws the scene, as the velocity output:

  • For VDBLevelSetMaterial and VDBLevelSetPhysicalMaterial (any material with a hitWorldNode) it reprojects the hit with this frame's and the previous frame's view-projection. For every other material it returns three's own velocity, so meshes keep what they had.
  • The value is three's convention: NDC of this frame minus NDC of the previous frame, y up, without jitter.
  • It belongs in the pass's or the renderer's MRT, not in material.mrtNode. three r187 takes a material's mrtNode as its whole output in a render into a target that has no MRT (an accumulation pass, a read-back of the same scene).

With three's TRAA:

import { RenderPipeline } from 'three/webgpu';
import { mrt, output, pass } from 'three/tsl';
import { traa } from 'three/addons/tsl/display/TRAANode.js';
import { VDBLevelSetVelocityNode } from '@pmndrs/vdb/three';

// One node for the whole pass: the hit's velocity for level-set materials, three's `velocity` for other meshes.
const hitVelocity = new VDBLevelSetVelocityNode();
const scenePass = pass(scene, camera);
scenePass.setMRT(mrt({ output, velocity: hitVelocity }));
// three's TRAA jitters the camera and gives its unjittered projection to three's velocity node; ours reads it.
const resolved = traa(scenePass.getTextureNode('output'), scenePass.getTextureNode('depth'), scenePass.getTextureNode('velocity'), camera);
const pipeline = new RenderPipeline(renderer, resolved);
renderer.setAnimationLoop(() => pipeline.render());
// At a camera cut or an aspect change: hitVelocity.reset();

What the node keeps track of, and what you do:

  • The previous frame is the previous render in which the node was drawn with the same camera. It needs no animation loop and no call per frame. (three's own velocity, which the other meshes get, advances with the renderer's frame id: use renderer.setAnimationLoop when the scene has moving meshes.)
  • Moving level sets. A level set is placed with pool.setTransform, not with its mesh. The node reads the placement per grid and adds its motion, so a level set that moves or turns gets correct vectors. Rebuild the proxy geometry after a move, as always. Two limits: a material whose gridId is a TSL node gets the camera's motion only, and a grid whose image changes (pool.replace, a sequence) has no motion vectors for the change.
  • Jitter. The velocity must not contain the sub-pixel jitter. three's TRAA hands its unjittered projection to three's velocity node, and this node reads the same matrix, so the wiring above needs nothing more. A host that jitters the camera itself calls hitVelocity.setProjectionMatrix(cleanProjection) once (the matrix is read at every render, and three's node gets it too) and setProjectionMatrix(null) when it stops.
  • Cuts and resizes. Call hitVelocity.reset() at a camera cut, after a resize that changes the aspect, and when this pass draws again after frames drawn another way. The next frame then has zero velocity on level sets. Reset the resolve's own history at the same time.
  • Several level sets and materials share the one node; each grid has its own motion.

A worked example: @pmndrs/upscaler as antialiasing

@pmndrs/upscaler is an FSR 2/3-style temporal upscaler; at ratio 1 (QualityMode.NativeAA) it is temporal antialiasing at display resolution. @pmndrs/vdb does not depend on it: the node is the only library part, the rest is wiring. Demo 13 does this while its camera sways (examples/src/demos/hit-velocity-upscaler.ts).

import { DepthTexture, FloatType, HalfFloatType, RenderTarget } from 'three/webgpu';
import { mrt, output } from 'three/tsl';
import { QualityMode, Upscaler } from '@pmndrs/upscaler';
import { VDBLevelSetVelocityNode } from '@pmndrs/vdb/three';

// NativeAA: the upscaler's temporal path at ratio 1 (display resolution in, display resolution out).
const upscaler = new Upscaler({ renderer });
upscaler.settings.sharpness = 0; // the default RCAS sharpening (0.8) brings the groove specks back
upscaler.configure({ displayWidth: width, displayHeight: height, qualityMode: QualityMode.NativeAA, path: 'temporal' });
await upscaler.init();

const hitVelocity = new VDBLevelSetVelocityNode();
// The upscaler jitters the camera itself: give the node (and, through it, three's velocity) the clean projection.
hitVelocity.setProjectionMatrix(upscaler.unjitteredProjectionMatrix);
const sceneMrt = mrt({ output, velocity: hitVelocity });

// Colour and velocity in half float, and a real depth texture: the materials write the hit's depth.
const depthTexture = new DepthTexture(width, height);
depthTexture.type = FloatType;
const input = new RenderTarget(width, height, { count: 2, type: HalfFloatType, depthTexture, samples: 0 });
input.textures[0]!.name = 'output';
input.textures[1]!.name = 'velocity';

function frame(deltaTime: number): void {
    upscaler.beginFrame(camera); // sub-pixel jitter on
    renderer.setMRT(sceneMrt);
    renderer.setRenderTarget(input);
    renderer.render(scene, camera);
    renderer.setRenderTarget(null);
    renderer.setMRT(null);
    upscaler.endFrame(camera); // jitter off
    upscaler.dispatch({ color: input.textures[0]!, depth: depthTexture, velocity: input.textures[1]!, deltaTime }, camera);
    // upscaler.outputTexture now holds the antialiased frame (linear HDR): draw it to the canvas with a full-screen quad.
}
function cut(): void {
    // A camera cut, a resize, or the first frame after frames drawn another way: drop both histories.
    upscaler.resetHistory();
    hitVelocity.reset();
}
  • Depth is a real depth texture: the level-set materials write the hit's depth, which the upscaler's disocclusion test needs.
  • Sharpening is off (sharpness = 0). The upscaler's default RCAS pass (0.8) re-sharpens exactly the sub-pixel groove pixels the resolve just averaged: on the teapot lid the dark specks came back (20 at rest, against 4 without it).

What to expect

Measured on the OpenVDB teapot's lid (a groove narrower than a pixel under a clearcoat), Apple Metal, 384 × 216: the RMS error of the ACES-tone-mapped frame against a 4×4 supersampled frame of the same pose, after 32 frames of a camera orbit. m4 is 0.04° per frame, the speed of demo 13's sway; m40 is ten times that. Both resolves use the same VDBLevelSetVelocityNode.

Framestudio lightingHDR sky
plain (one ray per pixel)0.00840.0155
@pmndrs/upscaler, hit velocity, m40.00480.0114
@pmndrs/upscaler, three's velocity (the proxy box), m40.01100.0292
three's TRAA, hit velocity, m40.00270.0073
three's TRAA, three's velocity (the proxy box), m40.00700.0177
@pmndrs/upscaler, hit velocity, m10 / m20 / m400.0058 / 0.0066 / 0.00780.0135 / 0.0168 / 0.0199
three's TRAA, hit velocity, m10 / m20 / m400.0041 / 0.0048 / 0.00520.0108 / 0.0122 / 0.0126
three's TRAA, three's velocity, m400.01170.0322
at rest, 32 frames: @pmndrs/upscaler / three's TRAA0.0039 / 0.00190.0096 / 0.0029
at rest, 16 jittered frames averaged0.00000.0001
  • The hit's velocity is what makes a temporal resolve work. With it both resolves beat the plain frame at the sway's speed. With the proxy's velocity the upscaler is worse than the plain frame already at that speed, and three's TRAA is two to three times further from the reference than with the hit's.
  • The two resolves differ in what they keep. The upscaler keeps the lid's groove as a line (3 isolated dark pixels at m4 in studio lighting; the supersampled frame has 6, the plain frame 31). three's TRAA has the lower error but smooths the groove away while the camera moves (0 isolated dark pixels). These are numbers from stills: look at both in motion before choosing.
  • Fast orbits under an HDR sky are soft. With the upscaler the error passes the plain frame's from about five times the sway's speed (0.0168 against 0.0155). The clearcoat reflects the sky, and a reflection does not move with the surface, so no surface velocity is right for it. The frames show blur, not trails. Demo 13 therefore resolves only while the camera moves by itself, and shows the plain frame while the visitor drags.
  • At rest, accumulate. A temporal resolve at rest is a clamped moving average, not the supersampled frame. The jittered accumulation of the previous section stays the reference-quality path.

Demo 13's query flags select the path: ?aa=upscaler resolves every moving frame, ?aa=rest never (the plain frame in motion, the accumulation at rest), ?aa=0 turns all antialiasing off; the default resolves while the camera sways or tweens. ?specaa=1 turns on the materials' specularAntialiasing.

specularAntialiasing is a different tool and is off by default, in the library and in demo 13. It widens the roughness where the traced normal turns within a pixel, which bounds the linear peaks of a highlight on a crease: use it when those peaks feed bloom or an HDR output. It does not antialias the image. After tone mapping it measured worse in demo 13 (ACES error on the lid 0.0143 against 0.0085 without it, in studio lighting), because the widened clearcoat blurs the reflection across the crease.

Quantized level sets

An Fp8 or FpN level set (vdbQuantize(image, 'fp8') or 'fpn' with a tolerance in world units, from @pmndrs/vdb/tools) traces like the float one: the VDBGridNode compiles the pool's grid types. The OpenVDB teapot goes from 77 MiB to 26 MiB as Fp8, and its hits move by the quantization error (about 1/85 of a voxel for Fp8).

A mesh for collision or export

The trace is for display. When a level set must become triangles (a collision shape, an export, picking on the CPU), vdbLevelSetMesh(image, options) from @pmndrs/vdb/tools meshes the zero surface with surface nets (Gibson 1998): one vertex per cell whose corners change sign, placed at the mean of that cell's edge crossings, and one quad per sign-changing lattice edge. It has no marching-cubes table. It walks the sparse leaves, reads corners in a neighbouring leaf, a tile or the background from there, and takes every grid type the CPU readers decode (Float, Half, Fp4, Fp8, Fp16, FpN). The result is a closed, consistently oriented mesh (an open one where a bbox clips it) with positions, indices and, with normals: true, unit normals pointing out of the solid.

import { vdbLevelSetMesh } from '@pmndrs/vdb/tools';

// Surface nets over the sparse leaves: one vertex per cell the surface crosses, positions in world space.
const mesh = vdbLevelSetMesh(levelSet, { normals: true });
console.log(mesh.vertexCount, 'vertices,', mesh.triangleCount, 'triangles');

// Triangles wind counter-clockwise seen from outside (normals point toward positive distance), so
// three's BufferGeometry, a physics engine's trimesh or an exporter can take the arrays as they are.
const { positions, indices, normals } = mesh;
// Another level, or a clipped part of the grid (inclusive index-space voxel box):
// vdbLevelSetMesh(levelSet, { isoValue: 0.02, bbox: { min: [-64, -64, -64], max: [64, 64, 64] } });

Vertices sit within a fraction of a voxel of the zero set (0.02 voxel from the analytic sphere in the tests), so the mesh is as fine as the grid: the OpenVDB teapot gives 1.68 million vertices (81 MB with normals), a 43-voxel-diameter sphere 8,700. space: 'index' returns voxel coordinates. A grid whose map mirrors an axis keeps its triangles outward in world space. Every cell has one vertex, so a mesh has nothing to weld (no two vertices share a position in the tests).

Options that change the vertices, all off by default:

  • project: true moves each vertex onto the iso surface of its cell's trilinear field. On the test sphere it takes the field error at the vertices to zero and the error against the true sphere from 0.011 to 0.009 voxel (rms), with triangles of the same shape.
    • Cost. It runs once, on the CPU, when the mesh is built; nothing changes per frame, and the mesh has the same vertex and triangle counts. It reads no extra voxels: each vertex takes 2 to 3 Newton steps (mean 2.6 to 2.9, at most 8) on the 8 corner values its cell already read. Building the mesh took about 20 % more CPU time with it on (paired runs: sphere 1.22×, torus 1.20×, a 66 k-triangle teapot clip 1.14×, the whole 3.37 M-triangle teapot in chunks 1.22×; relax: 3 plus project 1.3 to 1.5×). Those are ratios from a busy machine, not timings.
    • Benefit. Vertices are closer to the true shape: sphere 0.0113 → 0.0094 voxel rms (−16 %), 0.0172 → 0.0116 max (−32 %); torus 0.0230 → 0.0190 rms (−17 %), 0.0432 → 0.0288 max (−33 %). No vertex moves more than 0.02 voxel on these shapes, so a render does not show it: at 40 pixels per voxel the largest move is under one pixel. It matters where the numbers are used, not looked at: collision and contact, measurement, export to CAD-style tools, and after relax.
    • Side effect. At sharp creases a few more triangles fold (winding against their vertex normals): 1 → 20 of 3.37 million on the teapot, 1 → 4 of 2.73 million on the Venus statue, 0 → 0 on smooth shapes.
    • node scripts/k3/mesh-project-report.mjs (after pnpm build) reproduces the numbers and draws the comparison figures.
  • relax: n runs n iterations of Gibson's relaxation: each vertex moves to the mean of its neighbours, but never out of its cell. It is meant for binary-like data (a mask stored as ±value), where it halves the staircase error. On a distance field it gives better-shaped triangles (smallest angle 8° → 30° on the sphere) but pulls vertices off the surface (0.06 voxel at 3 iterations), so pair it with project: true there.
  • tiles: true also meshes where tiles meet the background or each other, with no leaf in between, as a fog volume can have (normals then point toward higher density, into the medium). Without it, isoValue must stay inside a level set's narrow band (|isoValue| < background). With it, any level works on a grid whose tiles hold other values; a clamped level set (every tile ±background) still throws, because it stores no surface out there.

For a grid whose whole mesh would not fit in memory, vdbLevelSetMeshChunks returns the same mesh in index-space chunks, one at a time. Each chunk holds the triangles of the cells whose min corner is in its bbox, and only the vertices those use. A vertex on a seam has bit-identical positions and normals in both chunks, so joining the chunks on equal positions gives the one-shot mesh. The teapot in chunks of 128 is 100 chunks, the largest 43,000 vertices.

import { vdbLevelSetMeshChunks } from '@pmndrs/vdb/tools';

// One chunk in memory at a time; options are checked here, before the first chunk.
for (const chunk of vdbLevelSetMeshChunks(levelSet, { chunkSize: 128, normals: true, project: true })) {
    // chunk.bbox: the index-space cells it owns. Hand each chunk to the physics engine or the writer as it comes.
    upload(chunk.positions, chunk.indices, chunk.normals!);
}

Decimating the mesh

A surface-nets mesh has about two triangles per cell the surface crosses, which is more than a collision shape or an export needs. vdbLevelSetMeshDecimate(image, mesh, { error }) removes vertices by edge collapses (in quadric-error order, Garland and Heckbert 1997) and lets the grid decide each one: a collapse happens only while the triangles it changes stay within error voxels (default 0.1) of the iso surface of the grid's trilinear field, keep facing outward and are not needles. It takes a vdbLevelSetMesh result or one chunk of vdbLevelSetMeshChunks, in world or index space, and returns the same shape with a subset of the input's vertices: positions and normals are unchanged, no vertex is new.

import { vdbLevelSetMesh, vdbLevelSetMeshDecimate } from '@pmndrs/vdb/tools';

const fine = vdbLevelSetMesh(levelSet, { normals: true });
// Collapse edges while the changed triangles stay within 0.1 voxel of the grid's zero surface
// (checked at sample points on each triangle; between them up to 9 % more was measured).
const coarse = vdbLevelSetMeshDecimate(levelSet, fine, { error: 0.1 });
console.log(fine.triangleCount, '->', coarse.triangleCount, 'triangles');
// Same shape as the input: a subset of its vertices (positions and normals unchanged), new indices.
// A triangle budget instead: vdbLevelSetMeshDecimate(levelSet, fine, { error: 0.5, targetTriangles: 20_000 });

At 0.1 voxel the test sphere goes from 17,424 to 1,874 triangles, a torus from 10,064 to 1,698 and the whole OpenVDB teapot (in 100 chunks) from 3.37 million to 108,000, with the measured distance to the surface at 0.100 to 0.107 voxel.

What the bound means:

  • It is checked at sample points on each changed triangle (a lattice of at most 0.25 voxel, vertices included), not everywhere. Between them more was measured on a 0.05-voxel lattice: 1 % over the bound on a sphere, 3 % on a torus, 7 % on an Fp8 torus and 9 % beside a box's edges. Pass a smaller error when you need a margin, or bound: 'hard' (below) for a bound that holds at every point.
  • It is in voxels and against the level isoValue (default 0); pass the isoValue the mesh was made at.
  • Input triangles that are already farther away stay as they are. The mesher's triangles across a sharp crease can be 0.2 voxel off, so a box keeps its edge vertices (23 % of its triangles are left at 0.1; see creases below).

Three options, all off by default (the default result is unchanged byte for byte):

// A hard-edged shape: also merge inside flat faces and along straight creases (the surface stays where it is).
const box = vdbLevelSetMeshDecimate(levelSet, fine, { error: 0.1, creases: true });
// Thin features: split the mesher's saddle edges into two sheets and replace triangles that face inward.
const clean = vdbLevelSetMeshDecimate(levelSet, fine, { error: 0.1, repair: true });
// A bound that holds at every point of the new triangles, not only at sample points (more triangles, slower).
const strict = vdbLevelSetMeshDecimate(levelSet, fine, { error: 0.1, bound: 'hard' });
  • creases: true also accepts a collapse that leaves the surface where it is: every triangle it changes lies in the plane of the one it replaces (within 1 % of error, counted from the input mesh). That merges vertices inside a flat face and along a straight crease without asking the grid, so the test box goes to 6 % of its triangles instead of 23 %, and nothing ends up farther from the level set than the input mesh already was. Corners and curved creases keep their vertices, and no vertex is new, so a simplifier that places vertices still does better on a hard-edged shape: meshoptimizer took the same box to 108 triangles at the same measured distance (with needles of 1.4°).
  • repair: true splits the mesher's saddle edges (an edge with four triangles, where two sheets of a thin feature pass through one pair of cells) into two sheets, by the field's side at the edge, and lets a collapse replace a triangle that faces against the field's gradient. The split adds copies of the edge's vertices (same position and normal, after the input's vertices), so the result is no longer a strict subset; joining vertices by position puts the edge back. On the clipped teapot the 11 saddle edges go and the inward-facing triangles drop from 16 to 4.
  • bound: 'hard' checks every point of each changed triangle instead of sample points: around each sample the field's change inside the triangle is bounded from the gradients of the cells nearby, and the surface is shown to lie within error along the triangle's normal. It is conservative: at 0.1 voxel it left 7 % more triangles on the sphere and 63 % more on the torus than the sampled bound, for about three times the field samples, and it refuses collapses where the gradient turns sharply (creases, saddle regions, the edge of the narrow band).

Vertices on an open boundary (a clip box, a chunk seam) and on non-manifold edges never move or go away, so each chunk can be decimated on its own and the chunks still join on equal positions into a closed mesh. targetTriangles stops early at a triangle count. The result is deterministic. It runs in JavaScript and samples the grid for every candidate, so it is slower than a mesh-only simplifier such as meshoptimizer, which you can run on the mesher's output instead (lock the borders for chunks); its error setting is its own quadric measure, not a distance to the level set (at 0.1 it measured 0.19 to 0.42 voxel on the same meshes).

Shadows cost a trace per texel

A mesh that casts a shadow draws into the shadow map with the same material, so the map is traced too: one orthographic ray per shadow texel the proxy covers. Demo 13 (four level sets) took 44 ms a frame at 1280 by 720 on an M-series Mac with the automatic update on, and 12 ms with light.shadow.autoUpdate = false.

For a static scene, turn the automatic update off and ask for a new map only when something moved. Set light.shadow.autoUpdate = false, then light.shadow.needsUpdate = true once, and again after the light or a caster changes.

Set needsUpdate for a few frames after a change rather than one. three r187 WebGPU also drops PCFSoftShadowMap (it warns and uses PCFShadowMap).

Points

VDBPoints draws the points of an OpenVDB point data grid as one instanced sprite, with the point colour from the grid's Cd attribute when it has one. Parse the .vdb with parseVdb from @pmndrs/vdb/tools, turn a grid with valueType: 'ptdataidx32' into render data with vdbPointRenderData(grid), and pass that to new VDBPoints(data, { size }). The default diameter is half the mean point spacing.

vdbPointRenderData returns plain typed arrays, so it can run in a worker. order: 'prefix' orders the points so that every prefix of k tenths of the arrays is an even subsample (data.prefix[k] points). A density control then only sets points.pointCount, with no new buffers. attributes carries other attributes in the same order, and onProgress reports the decode and the copy.

import { parseVdb, vdbPointRenderData, vdbPointRenderDataTransfer, type VdbPointDataGrid } from '@pmndrs/vdb/tools';

const grid = parseVdb(bytes).grids.find((g): g is VdbPointDataGrid => g.valueType === 'ptdataidx32')!;
const data = vdbPointRenderData(grid, {
    order: 'prefix', // data.prefix[k]: the first k tenths are an even subsample (prefix[1] = every 10th point)
    attributes: ['v'], // data.attributes.v.values, in the same order as data.positions
    onProgress: ({ stage, done, total }) => postMessage({ stage, done, total }),
});
postMessage(data, { transfer: vdbPointRenderDataTransfer(data) });
// In the page: new VDBPoints(data); later points.pointCount = data.prefix![1] draws 10 % of them.

The points demo decodes the grids in a worker this way and colours them by Cd or by speed.

Streaming .wvdb points

A .wvdb points grid stores its points coarse first: LOD 0 holds every 64th point (with three LODs), LOD 1 brings it to every 8th, and the last LOD adds the rest. VDBPoints.fromWvdbGrid(header) makes a VDBPoints sized for the whole grid, and addWvdbLevel(level) writes each level a WvdbStreamReader decodes. Only the new points are uploaded. Every point that has arrived is drawn, and the sprites are wider while the cloud is sparse.

import { WvdbStreamReader, type WvdbPointsGridHeader, type WvdbPointsLevel } from '@pmndrs/vdb/tools';
import { VDBPoints } from '@pmndrs/vdb/three';

const reader = new WvdbStreamReader({ partialLods: true });
const body = (await fetch(url)).body!.getReader();
let points: VDBPoints | null = null;
for (;;) {
    const { done, value } = await body.read();
    if (done) break;
    for (const event of reader.push(value)) {
        if (!points) {
            // Sized for the whole grid; draws nothing until the first level arrives.
            points = VDBPoints.fromWvdbGrid(reader.header!.grids[0] as WvdbPointsGridHeader);
            scene.add(points);
        }
        // Uploads the new range, draws every point that has arrived, widens the sprites while it is sparse.
        points.addWvdbLevel(event.levels[0] as WvdbPointsLevel);
    }
}
reader.end();