Froxel renderer

VDBFrameVolume and VDBFrameRenderer, ported from mjurczyk's FrameRenderer, over a dense or a sparse source.

VDBFrameVolume is a Group whose proxy mesh draws a volume with froxel lighting: the volume's density and light are integrated into a view-aligned froxel grid, then composited over the scene up to the scene depth. It is mjurczyk's FrameVolume and FrameRenderer (three-openvdb, MIT) re-based on a volume source (D18). Since 0.2.0 the work runs in the core frame renderer (WebGPU compute kernels on three's device, D34; Rendering without three uses it directly): ./three collects the volumes and lights, records the core's update and composites its output. Add a volume to a scene and call renderer.render(scene, camera) as usual: the first proxy in a render runs the core update, and every proxy then composites. volume.frameRenderer.core is the core renderer (after the first render).

To try the settings below live, open the froxel renderer demo (demo 10, source in examples/src/demos/10-frame-renderer; locally, pnpm dev): it renders a cloud, smoke, an emissive explosion, a level set and a point grid with the panel's lighting, scattering, phase, spectral, shadow and quality settings, and lists the fixture script for any scene whose files are missing. The gallery shows the renderer on full-resolution sparse volumes: sky clouds (demo 11) and an explosion lighting the ground and props with its flames (demo 12).

Note

The pass timings recorded so far are provisional (D25). Read the quality settings below as defaults to tune, not as measured recommendations.

Sources

A volume reads its density only through a source. There are two:

SourceMade byWhat it holds
DensevdbDenseTextures(wvdbDenseVolume(readWvdb(bytes)))A .wvdb LOD (8-bit texels with a mip atlas). Density is clamped to 0..1.
SparsevdbSparseSource(grids, { density: id }, options)A pool grid at full resolution, read through vdbSample.

Both are handles and hold no GPU object: the frame renderer reads them into the core's own sources, which upload the dense texels and build the sparse LOD pyramid on the GPU. (0.1's vdbVolumeUniforms / vdbVolumeNodes, the sources' three textures and a sparse source's own pyramid are gone: for a custom material see Custom materials and compute below.)

import { readWvdb, wvdbDenseVolume } from '@pmndrs/vdb/tools';
import { VDBFrameVolume, vdbDenseTextures } from '@pmndrs/vdb/three';

// A dense source: the .wvdb's density as an 8-bit 3D texture with a mip atlas.
const source = vdbDenseTextures(wvdbDenseVolume(readWvdb(wvdb)));
const volume = new VDBFrameVolume(source, { extinction: 100 }); // the box is the file's bbox
scene.add(volume); // renderer.render(scene, camera) draws it, froxels first

volume.scatterColor.set('#ffffff');
// A measured medium in one call: albedo and extinction spectrum on the volume, the phase on the renderer.
volume.setMedium('fog');
// volume.bbox is the resolved box (here the file's): place the volume by it.
volume.position.copy(volume.bbox.getCenter(volume.position)).negate();

The sparse source needs a VDBGridNode with profile 'march', plus the helpers its paths use. Optional mask, albedo (one grid, or three for RGB) and emission grids are scalar and read at level 0. Its boxes are fixed when it is made; with followImage: true it re-reads them (and rebuilds its pyramid) after a pool.replace that changes the grid's box, and the volume's box follows, with no shader rebuild: the coarse-first swap in Compute and streaming.

import { VDBFrameVolume, VDBGridNode, vdbSparseSource } from '@pmndrs/vdb/three';

const id = pool.add(image);
pool.flush();

// A sparse source: a pool grid, at full resolution. The module needs the march profile and the
// helpers the source's HDDA and node-average paths use.
const grids = new VDBGridNode(renderer, pool, {
    profile: 'march',
    helpers: ['cellBoundTrilinear', 'hddaCellEnd', 'nodeAverage'],
});
const source = vdbSparseSource(
    grids,
    { density: id }, // optional: mask, albedo (one grid or three), emission
    { lod: 'coarse-pyramid', pyramidMax: 128, images: { density: image } },
);

const volume = new VDBFrameVolume(source, { extinction: 100, hdda: false }); // the box is the grid's world box
scene.add(volume);

LOD and HDDA

When a froxel spans many voxels, a sparse source filters. lod picks how:

  • 'coarse-pyramid' (default): a dense r16f pyramid, built on the GPU from the pool grid and rebuilt when the grid's imageRevision changes, so pool.replace frames work. pyramidMax is the base level's longest side (default 128).
  • 'node-average': no extra memory, trilinear over the nodes' stored averages. It blurs and brightens; it needs stats.
  • 'none': level 0 only, which aliases.

hdda on a VDBFrameVolume skips empty space in the shadow march of a sparse source. The image is the same either way, and it is off by default: on the Apple GPU it slowed the shadow march in all 12 paired runs (D30). Dense sources ignore it.

A sparse source's level-0 samples walk the tree (8 lower-node lookups per trilinear sample), which is most of the gap to a dense source. An experimental brick cache that reads the touched leaves from a dense atlas instead (bit-identical in f32, one filtered fetch in f16) exists as an internal option until it is timed on a quiet machine; it is not part of the public API yet. Its working set is the level-0 blocks the froxels read: a medium cloud fits its default 64 MiB atlas, a very large one seen up close (the WDAS cloud at 512 × 512 froxels) does not, and then most samples still walk the tree.

Dense sequences and sparse copies

A dense source swaps frames with source.replace(frame); the volume picks up a new size or mip layout by itself (no updateSource() call). VDBSequence plays them: give it a loader that returns WvdbDenseVolume frames and start it on { source }. A frame that lacks a channel the source has reads that channel's absent value (emission 0, mask and albedo 1), so make the source from a frame that has every channel; a channel the source lacks is ignored. normalizeDensity divides by the source's mean, which changes from frame to frame; set densityMean to one value for the whole sequence (his sequences use the mean of all frames' non-zero texels).

import { readWvdb, wvdbDenseVolume, type WvdbDenseVolume } from '@pmndrs/vdb/tools';
import { VDBFrameVolume, VDBSequence, vdbDenseTextures } from '@pmndrs/vdb/three';

// One dense source for the whole sequence, made from a frame that has every channel.
const source = vdbDenseTextures(first);
const volume = new VDBFrameVolume(source, {
    // One mean for every frame, so the extinction does not pump (his sequences use the mean of all frames).
    densityMean: first.meanDensity,
});
scene.add(volume);

// VDBSequence plays any frame type into a { source }: the volume follows each replace by itself, and a
// frame without a channel the source has reads its absent value (emission 0, mask and albedo 1).
const sequence = new VDBSequence<WvdbDenseVolume>({
    urls,
    fps: 24,
    loader: async (url) => wvdbDenseVolume(readWvdb(new Uint8Array(await (await fetch(url)).arrayBuffer()))),
});
sequence.start({ source });
const frame = (now: number) => sequence.update(now); // each rendered frame

A sparse copy of a .wvdb level renders the same voxels through the sparse sampler. wvdbDenseToNvdb returns the options that line it up with the dense source (the texture's index box, the dense stats, the .wvdb box):

import { wvdbDenseToNvdb } from '@pmndrs/vdb/tools';
import { VDBGridNode, vdbSparseSource } from '@pmndrs/vdb/three';

// The same voxels as a sparse grid, lined up with the dense source in one spread: the texture's index box,
// the dense mean (normalizeDensity divides by the same value) and the .wvdb box.
const grid = wvdbDenseToNvdb(dense);
const id = pool.add(grid.image);
const grids = new VDBGridNode(renderer, pool, { profile: 'march', helpers: ['cellBoundTrilinear', 'hddaCellEnd'] });
const source = vdbSparseSource(grids, { density: id }, { ...grid.sparseSourceOptions, lod: 'coarse-pyramid' });
return new VDBFrameVolume(source);

The source, its kind (dense or sparse) and a sparse source's lod are fixed when the source and the volume are made. To change them, make a new source and a new VDBFrameVolume, and dispose the old ones.

Lighting

Settings live on volume.frameRenderer.settings. They belong to the VDBFrameRenderer, not to a volume: every volume that uses the same renderer shares them, and volumes in one renderer are lit together. With no frameRenderer prop a volume uses the shared vdbFrameRenderer(), so changing a setting changes it for all of them. Use vdbFrameRenderer(threeRenderer) for an instance shared only within one three renderer. To give a volume its own settings, make a separate new VDBFrameRenderer() and pass it as VDBFrameVolume(source, { frameRenderer }).

// Settings belong to the frame renderer, so volumes sharing one share its settings.
// For different settings, give a volume its own renderer.
const draft = new VDBFrameRenderer();
draft.settings.depth = 16;
const volume = new VDBFrameVolume(source, { frameRenderer: draft });
// vdbFrameRenderer(threeRenderer) is the instance shared only within that three renderer.
import { VDB_FRAME_LIGHT_BITS } from '@pmndrs/vdb/three';

const settings = volume.frameRenderer.settings; // shared by every volume that uses this renderer

// 'volume': each volume lights itself with its own shadow march.
// 'frame' (default): a world shadow grid shared by all volumes, with up to 4 cascades.
settings.lighting = 'frame';
settings.shadowResolution = 64;
settings.shadowCascades = 2;

// The scene's environment as lights: 'outward', 'directional' (default) or 'spherical-harmonics'.
settings.environmentLighting = 'spherical-harmonics';
settings.environmentShOrder = 2;

// Which of the scene's light types this volume uses.
volume.lights = VDB_FRAME_LIGHT_BITS.directional | VDB_FRAME_LIGHT_BITS.point | VDB_FRAME_LIGHT_BITS.environment;
lightingWhat it does
'frame' (default)A world shadow grid of every caster, up to 4 cascades, redrawn only when its signature changes. Transmittance from each grid voxel to up to 6 scene lights and the sky, an optional environment grid, then one gather per froxel that sums every volume's density and lights it, then temporal reprojection.
'volume'Each volume lights itself with its own shadow march.

environmentLighting turns the scene's environment into lights: 'outward' (L2 spherical-harmonics irradiance along each volume's outward direction), 'directional' (default, up to 8 lights) or 'spherical-harmonics' (quadrature lights of order 1 or 2), all extracted on the GPU from scene.environment (no readback). volume.lights is a bitmask of VDB_FRAME_LIGHT_BITS (ambient, point, directional, spot, hemisphere, environment); VDB_FRAME_ALL_LIGHTS is the default. Meshes with castShadow shadow the volumes through three's shadow maps (settings.occlusion, default on), and settings.ambientOcclusion (on by default since 0.2.0, 4 direction pairs: ambientOcclusionPairs) attenuates ambient, hemisphere and light-probe light by the medium; false gives 0.1's unshadowed ambient (about 35 to 148 % too bright in single scattering against a path-traced reference). The direction pairs form a fixed ring around the sky direction, also with jitter and temporal (no frame-to-frame change).

Distant light is ambient, hemisphere and light-probe light, and in 'frame' lighting the 'outward' environment. What the shadowing does with it depends on the multiple scattering mode, the same way in both lightings (since 0.2.0):

multipleScatteringdistant light on a volume
false or 'octaves'attenuated by the medium and weighted by the phase function (a dipole fit of the direction pairs): a position scatters toward the camera mostly the light that crossed the medium behind it
any other mode ('neural', the default; true, 'two-sided', 'mlp', 'multi-scale')attenuated by the medium, a solid-angle mean (the same for every view direction; with scattering the light is close to isotropic)

'volume' lighting fits the dipole per froxel in its march. 'frame' lighting stores it in the shadow grid: one more value per voxel, 8 bytes (24 with spectral), on top of the grid's 48 (120 with spectral and four slot groups). The renderer allocates it only while it is read, that is with 'frame' lighting, ambientOcclusion on, distant light in the scene and multipleScattering false or 'octaves'; a default scene ('neural') never pays it. It is freed at the next update after a setting turns it off, and after 120 updates in a row without distant light; switching between 'neural' and false therefore reallocates the grid's transmittance texture (one redraw of the transmittance, no change to the shadow grid). Without the phase weight (0.1, and the 0.2 previews in 'frame' lighting) a strongly forward-scattering medium lit mostly by distant light read up to about twice too bright where it faces the camera. The weight has no public switch of its own: ambientOcclusion = false turns the whole shadowing off.

Environment light and multiple scattering. Light from the environment gets one multiple-scattering estimate whatever the mode: with multipleScattering on true, 'two-sided', 'neural' or 'multi-scale', every environment light is lit by the same isotropic two-sided diffusion (a march toward the light and one away from it, no phase function), so those four modes draw the same frame, byte for byte, when the environment is the only light. Only false (direct light) and 'octaves' differ. This holds for 'directional', 'spherical-harmonics' and 'outward', in 'frame' and in 'volume' lighting, and it is what mjurczyk's renderer does (his capture equals ours). It is kept on purpose (D40).

  • Measured: his bunny cloud lit only by his sky-midday map ('frame' lighting, 'directional') is +7 % in energy with a 16 % median per-pixel error against a path-traced reference with full multiple scattering. 'outward' on the same scene is −10 % in energy with a 42 % median error.
  • Not measured: a thick cloud lit mostly by an overcast map. There the environment carries most of the multiply scattered light, and it gets a diffusion estimate, not the 'neural' network's. For sun light, 1D diffusion reads 17 to 69 % darker than the reference on the test scenes, where 'neural' is within about 6 % on 8 of 13; the environment's estimate may miss in the same direction, so such a cloud could look too dark inside.
  • If it matters: switching to 'volume' lighting or to another environmentLighting does not help, since they use the same estimate. Put the dominant source in the scene as a light of its own (a DirectionalLight for the sun): scene lights go through the selected mode ('neural' in 'frame' lighting), and the map then lights only the fill.

'frame' lighting reads every light through the shadow grid, so its resolution bounds how sharply light falls off into a dense medium. The grid's voxels snap to powers of two, so shadowResolution 64 puts between 32 and 64 cells across the casters. On a large or dense cloud that is too coarse (the WDAS cloud in sun is about 20 % too bright against a path-traced reference). settings.shadowResolutionMax (default 0, off) grows the grid: above shadowResolution, it uses the smallest side (a multiple of 16, at most the max) whose cells span at most 16 of a caster's voxels and 2 optical depths at its mean density (the WDAS cloud gets 80, a dense bunny 96). A small thin medium keeps shadowResolution. The grid costs about 48 bytes per voxel (a 128-voxel side is about 96 MiB, 64 is about 12 MiB), and 56 while the phase-weighted distant light above is in use (112 MiB and 14 MiB). The clamp to the device's limits counts that value only while it is allocated: at WebGPU's default limits one cascade then fits a side of 186 instead of 193, and four cascades of 128 clamp to 102 (warned once). Its transmittance pass grows with about the fourth power of the side, and runs only when the lights or casters change (every frame with jitter). frameRenderer.core?.shadowGridResolution reports the side in use.

Scattering and phase



const settings = volume.frameRenderer.settings;

// false: single scattering. true: 1D diffusion toward the light. 'two-sided': 2D slab diffusion.
// 'octaves': indirect octaves. 'neural' (default): a small trained network for the scene lights.
settings.multipleScattering = 'octaves';
settings.scatteringOctaves = 4; // each octave n has extinction a^n, light b^n, phase g c^n
settings.scatteringOctaveExtinction = 0.5;
settings.scatteringOctaveContribution = 0.5;
settings.scatteringOctavePhase = 0.5;

// Phase functions: 'isotropic', 'henyey-greenstein', 'dual-lobe', 'lorenz-mie' or 'lorenz-mie-rgb'.
// The renderer's phase is every volume's ('frame' lighting lights them all in one pass with it).
// The default is 'dual-lobe': a forward lobe (phaseG 0.8) and a back lobe (phaseBackG -0.3, phaseBackWeight 0.2).
settings.phaseG = 0.6;
settings.phaseBackWeight = 0.3;
settings.phase = 'henyey-greenstein'; // one forward lobe: the 0.1 default
// 'volume' lighting only: one volume's own phase, field by field (null: the renderer's again).
volume.phaseG = 0.3;

multipleScattering picks how the shadow marches approximate light that scatters more than once:

ValueMode
falseSingle scattering
true1D diffusion toward the light
'two-sided'2D slab diffusion toward and away from the light
'octaves'Indirect octaves: octave n has extinction a^n, light b^n and phase g c^n (scatteringOctave*)
'neural' (default)Our small trained network for the scene light slots in 'frame' lighting, diffusion elsewhere. It runs in a generic small-MLP evaluator: frameRenderer.mlp (EXPERIMENTAL, VDBFrameMlp data) holds the network (our weights, trained on procedural media); null runs 'neural' as 1D diffusion. 'mlp' is the same evaluator by its own name. The network reads its features at the reaches of a 64-voxel shadow grid whatever shadowResolution is (K6.Nb), so a finer grid sharpens the shadows without changing what the network sees. The default network was trained for Henyey-Greenstein g 0.8 (a network for the dual-lobe default is open work); a VDBFrameMlp may take the phase as extra inputs (extra: 'g', the mean cosine, or extra: 'phase', the two lobes (g₁, g₂, w): EXPERIMENTAL, no shipped network uses them).
'multi-scale'Multi-scale diffusion from mips of the shadow grid (multiScaleLevels).

The mode applies to the scene's own lights (directional, point, spot). Environment light gets the same isotropic diffusion in every mode but false and 'octaves', so an environment-only scene looks the same in true, 'two-sided', 'neural' and 'multi-scale': see Lighting for the measured accuracy and what to do when it matters.

The phase is 'isotropic', 'henyey-greenstein', 'dual-lobe', 'lorenz-mie' or 'lorenz-mie-rgb', with phaseG, phaseBackG, phaseBackWeight and phaseGExponent. The default is 'dual-lobe' with 0.8, −0.3 and 0.2: a forward lobe plus a weak back lobe, closer to a cloud's phase than one forward lobe (0.1 drew 'henyey-greenstein' g 0.8: set it for that look). Set it in one place, settings.phase*: it is the phase of every volume the renderer draws. 'frame' lighting lights all volumes in one pass, so it always uses it; in 'volume' lighting a volume's own phase* props (null by default) override it, field by field, for that volume (volume.getPhase() gives the result). His renderer read settings.phase in 'frame' lighting and only the volume's in 'volume' lighting.

Colour is grey by default. Set settings.spectral for per-channel extinction. A measured medium ('cloud', 'fog', 'ice', 'soot', 'white-smoke', 'dark-smoke', 'haze', 'dust') is one call, volume.setMedium(name), as his GUI's 'Medium' field: the volume's baseColor, extinctionScale and angstromExponent, the renderer's phase, and settings.spectral on. setMedium(null) restores the volume's own colour; vdbFrameMedium(name) returns the props without applying them. With spectral on, 'neural' runs its network once per colour channel, on that channel's extinction, albedo and optical depth, so a grey medium renders as it does with spectral off. His renderer ran 'neural' as 1D diffusion when spectral. 'multi-scale' runs its multi-scale lookup once per channel the same way.

Quality



const settings = volume.frameRenderer.settings;
settings.width = 256; // froxel grid, default 512 x 512 x 24
settings.height = 256;
settings.depth = 32;
settings.pixelsPerFroxel = 4; // at most one froxel per 4 x 4 canvas pixels (0: no cap)
settings.subSteps = 16;
settings.temporal = true; // reproject the froxels over frames
settings.jitter = true;

volume.shadowSteps = 16; // the shadow march of this volume
volume.mipmaps = true; // sample the source's coarser levels when a froxel spans many voxels
volume.hdda = true; // sparse sources: skip empty space in the shadow march (same image, off by default)

width, height and depth are the froxel grid (default 512 x 512 x 24). pixelsPerFroxel caps it at one froxel per N x N canvas pixels. fadeRadius fades density with view distance. srgbBlending (default true) blends over the scene in sRGB, as WebGLRenderer does.

Custom materials and compute

0.1 let a custom TSL material sample a source through vdbVolumeUniforms / vdbVolumeNodes (his createVolumeNodes shape). They are deleted in 0.2.0, with the sources' three textures and sparse pyramid; nothing replaces the shape, but each use has a home:

  • A custom TSL material over a NanoVDB grid: VDBGridNode (see VDBGridNode) puts the pool in three's node system: vdbSample (trilinear), vdbReadValue, and its opt-in helpers (cellBoundTrilinear, hddaCellEnd, nodeAverage, fastTrilinear) as wgslFn includes. VDBVolumeMaterial is built on it.
  • Custom WGSL or compute over a source: the core's vdbSparseSource (one source per pool) and vdbDenseSource (a .wvdb volume) generate the vdbSrc* functions (wgsl({ slot, profile }): density, mask, albedo, emission, LOD, and the HDDA span in the 'march' profile) and their bind group layout; see Raw WebGPU.
  • The full froxel look: VDBFrameRenderer with VDBFrameVolumes, as above.

Volume props

VDBFrameVolume props keep his names and defaults for the ported subset: baseColor, scatterColor, extinction (with normalizeDensity, the optical depth of the longest box side at the mean density, default 100), densityScale, densityCutoff, absorbance, opacity, emissiveIntensity, temperatureRange, offset3D, wrap3D, bbox, mipmaps, shadowSteps, lights, the phase overrides and hdda, plus densityMean (the mean normalizeDensity divides by; default the source's). densityScale behaves the same on dense and sparse sources. volume.bbox is the resolved box (the prop, or the source's), read-only: place the volume by it. A source.replace() needs no call (updateSource() forces a re-read). emissionColor is data: 'white' (default), { spectrum: 'planck' | 'soot', exponent } (his blackbody spectra), { lut } or { wgsl } (a validated WGSL hook). dispose() frees the proxy; the source belongs to you.

volume.frameRenderer.passHook brackets each core update: timestampWrites (a 'timestamp' query set and two indices, written before the first and after the last kernel the update records) and begin() / end(update) callbacks on the CPU. frameRenderer.froxels = false keeps the last froxels (no froxel work; the composite draws them again).