Renderer · function
composeGlobalField
Fill every cascade from the instances standing near the camera.
Explained in Hello world.
function composeGlobalField(instances: readonly GlobalFieldInstance[], cameraPos: ReadonlyVec3, radius: number, out: GlobalField): voidimport { composeGlobalField } from '@driftengine/core';Parameters
| Parameter | Type | Description |
|---|---|---|
instances | readonly GlobalFieldInstance[] | |
cameraPos | ReadonlyVec3 | |
radius | number | |
out | GlobalField |
In depth
radius is the innermost cascade's half-extent in metres; each cascade outside it reaches twice
as far at the same sample count.
Every cascade's centre is snapped to a multiple of its own step, and that is the decision this function exists to make. A grid centred on the exact camera position resamples the entire world at a new sub-pixel offset every frame, so every value changes slightly every frame and the indirect light shimmers — worst on a slow camera, which is exactly when a viewer is looking at it. Snapped, a camera move is either nothing at all or a whole voxel, and a whole voxel leaves every sample the two grids share bit-identical.
A point no instance is near takes the cascade's own reach rather than infinity. That is an underestimate of the true distance, which is the safe direction: a march that steps by it takes a shorter step than it could and converges anyway, where an overestimate steps through the wall it was meant to stop at.
This is the reference, and it visits every sample of every cascade for every instance that is
not culled outright. scripts/gpu-parity.mjs is the pattern the WGSL will be checked against,
and the WGSL is where the brick culling belongs — a CPU implementation that was already
accelerated would be a second thing to be wrong rather than the thing the first is checked by.