probeGI.package
This package holds more than this page lists. See all of its files in its world.
README.md
probeGI
Indirect diffuse light from a field of probes traced against the scene.
The field is up to four nested grids of probes (cascades), each centred on the
camera and each with cascadeSpacingRatio times the spacing of the one before,
so the finest holds the nearest surfaces in detail and the coarsest reaches far.
Every frame each probe shoots raysPerProbe rays through the scene's
acceleration structure and records what comes back: the sky where a ray leaves
the scene, and at a surface the sun's light (with a shadow ray toward the sun),
the light of the scene's point, spot, area and distant lights (with a shadow ray
toward each), the surface's emission, and the light that surface takes from the
field as the previous frame left it. That last term carries light from surface
to surface, one bounce per frame.
The scene those rays walk holds every entity's model and every drawn copy of
each population renderer.mesh.drawInstanced registers as traced (which
follows castsShadows unless the registration says otherwise), so plants and
props block the sky and the sun from the probes under and around them and send
their own colour back. A population whose matrices only a compute pass writes
cannot be placed and reports traced = "noCpuTransforms" from
renderer.mesh.instanceInfo.
Each probe keeps two small octahedral maps of the sphere around it, blended over frames by a hysteresis: the irradiance arriving from each direction (and, in the alpha, the share of the sky it sees that way), and the mean and mean-squared distance its rays travel in each direction, each ray counted at most a cell diagonal of its cascade far (and, in the blue, the share of rays that left the scene). A surface reads the eight probes around it, weighted by trilinear share, by how squarely it faces each probe, and by the Chebyshev bound on how much of the way to the surface each probe sees clear, so a probe on the far side of a wall carries no weight. What a surface reads is stable under camera motion because the maps live in probe space and each grid is anchored to the world.
Where each probe stands
Each probe also keeps an offset from its lattice position and whether it stands
inside geometry, which a pass of its own works out from the probe's rays every
frame. A probe more than insideShare of whose rays hit the back of a surface
stands inside geometry and carries no weight wherever the field is read. One on
a solid's boundary (some of its rays left the solid: it stands on a surface, or
in a wall where a corner opens) moves toward the side its rays open onto,
probeClearance of a spacing a frame; one buried in a solid stays put, inside.
A probe outside geometry nearer than probeClearance to a surface facing it
moves away from it. A probe moves at most 0.45 of a spacing from its lattice
position along any axis, and one whose cell enters its grid starts on its
lattice position.
A pass of its own reads the field at every surface in view, multiplies by the
surface's diffuse colour and the field's gain and tint, and adds the result to
the frame. It reads the G-buffer, so it runs on the deferred path, and it turns
scene ray tracing on when it starts. A closed room of walls 0.3 m thick holds the
field's light out at a finest spacing of 1 m or 2 m.
Within edgeFade cells of a cascade's edge a point is read partly from the next
coarser cascade, whose probes stand farther apart. A coarser probe and the finer
probe that weighs in most at the point must see each other, so a coarser probe
past a wall the finer probes resolve carries no weight there, and the coarser cascade
takes its share only as far as its probes see the point as clear as the finer
cascade's do; the rest stays with the finer cascade. A room of walls 0.3 m
thick in a field only eight probes tall, most of it inside the fade band of its
finest cascade, holds the coarser cascades' light out too.
The field's sky is the captured sky of a sky light member: skySource names it
and its captured environment is what a ray that leaves the scene returns. The
field is where the sky's diffuse light is occluded, so a scene that places it
gives the sky light a diffuse of 0.
The scene's lights
A ray's surface takes the light of the lights the light grid lists where it
stands, with the falloff, spot cone and rect integral the surfaces are shaded
with (@builtin::shaderModules.scene_lights), so the bounce a lamp sends is in
the units of its direct light: the lamp that lights a red floor directly lights,
through the field, the wall that floor faces. The surface counts as one on the
default light channel. Of the lights that reach it, it takes the
maxLocalLights that put the most light on it unshadowed and traces one shadow
ray toward each, as long as the way to the light, so a lamp behind a wall adds
nothing on the far side of it. A rect light's ray goes to a point drawn across
its face for each ray and frame, so the field, which blends its rays over frames,
reads the share of the rect a surface sees.
Each light a ray's surface takes costs one shadow ray, so the trace costs at
most raysPerProbe x probes x maxLocalLights shadow rays a frame for the
scene's lights, on top of its own rays and the sun's. A light out of reach of a
surface (past its radius, outside a spot's cone, behind a single-sided rect)
costs a few compares there and no ray. A surface reached by more lights than
maxLocalLights takes is stated: the field reads its stats store back every 60
drawn frames, and while a ray hit since the read before was reached by more, the
sentence naming how many reached it stands in the feature's log, in
live.droppedLights and in the member's notice.
What it publishes
modules.state("@builtin::systems.probeGI.probeGI.live") holds the field's
parameter buffer (params), the two atlas pairs (irradiance, visibility),
the ray store (rays), which of each pair the last frame wrote (current),
droppedLights (the sentence stating that ray hits are reached by more of the
scene's lights than maxLocalLights takes, nil while none are), and
skyVisibility: a screen-sized picture with, per surface in view, the share of
the sky it sees over its hemisphere in red and along its mirror direction in
green (widened toward the hemisphere's by roughness). A sky light member whose
occlusionSource names this member scales its diffuse and reflection terms by
that picture.
Parameters
| name | default | what it is |
|---|---|---|
probesPerAxis | (16, 8, 16) | Probes each cascade holds along x, y and z, each 2 to 64; every cascade holds that many, and the whole field holds at most 65536 probes. A setting past that limit is stated in the feature's log, in live.clamped and in the notice of the member's application, with what the field holds. |
cascades | 3 | Nested grids, 1 to 4. |
baseSpacing | 1.5 | Distance between neighbouring probes of the finest cascade, in world units. |
cascadeSpacingRatio | 2 | How many times a cascade's spacing the next coarser has. |
followCamera | true | Whether the field is centred on the camera. |
anchor | (0, 0, 0) | The field's centre when followCamera is off. |
belowShare | 0.6 | The share of each cascade's height that lies below the camera. |
edgeFade | 3 | How many cells inside a cascade's edge its light fades over into the next coarser cascade. A point no cascade holds reads the coarsest cascade at its nearest cell. |
gridOffset | (0.5, 0.5, 0.5) | Where the lattice sits relative to the world's whole multiples of the spacing, in spacings. |
raysPerProbe | 48 | Rays each probe shoots every frame, 8 to 256. |
irradianceHysteresis | 0.97 | Share of a probe's irradiance carried over per sixtieth of a second: a slower frame carries over proportionally less. |
hysteresisFloor | 0.8 | The share carried over where a texel changed by more than changeThreshold. |
changeThreshold | 1 | Relative luminance change that takes hysteresisFloor. |
maxCatchUp | 2 | The most sixtieths of a second one drawn frame advances the field, 1 to 12. A frame after a longer gap (an editor that idles and wakes, a slow frame) blends as if only this many had passed, so one frame keeps at least irradianceHysteresis^maxCatchUp of the history (0.94 at the defaults, hysteresisFloor^maxCatchUp = 0.64 where a texel changed past changeThreshold) and the field follows a lasting change within a few dozen drawn frames. At 12, a frame after a long gap keeps 0.69 of the history. |
visibilityHysteresis | 0.97 | Share of a probe's distance moments carried over per sixtieth of a second. |
visibilitySharpness | 50 | Cosine power a ray weighs in by when it joins the distance moments. |
irradiancePower | 1 | Cosine power a ray weighs in by when it joins the irradiance. |
bounceGain | 1 | How much of the light a surface takes from the field is sent on again. |
maxBounceLuminance | 16 | The most luminance a ray carries back; 0 sets no limit. |
skySource | empty | The sky light member whose capture rays that leave the scene return; empty, black. |
skyIntensity | 1 | Gain on the sky's light. |
skyBelowHorizon | 0 | Share of the sky's light kept by a ray that leaves the scene below the horizon. |
sunIntensity | 1 | Gain on the sun's light at a ray's surface. |
localLightIntensity | 1 | Gain on the light of the scene's point, spot, area and distant lights at a ray's surface. |
maxLocalLights | 8 | The most of the scene's lights one ray's surface takes, 0 to 16, each with a shadow ray: the ones that put the most light on it. 0 takes none. A surface reached by more is stated (above). |
emissiveGain | 1 | Gain on emitted light. |
maxRayDistance | 200 | How far a ray looks, in world units. |
normalBias | 0.25 | How far, in spacings, a read point moves along its normal. |
viewBias | 0.1 | How far, in spacings, a read point moves toward the viewer. |
weightCrush | 0.2 | Probe weights under this fall off by their cube. |
intensity | 1 | How much of the field's light reaches the frame; 0 draws nothing. |
tint | (1, 1, 1) | A colour the field's light is multiplied by. |
minimumIrradiance | 0 | A floor under the irradiance over pi any surface receives. |
probeClearance | 0.1 | How far, in spacings, a probe keeps from the surfaces around it: a probe on a solid's boundary moves out by this much a frame, and one outside geometry nearer a surface than this moves away from it to this far. |
insideShare | 0.25 | The share of a probe's rays that hit the back of a surface past which the probe stands inside geometry, where no surface reads it. |
update | true | Whether the probes trace and blend every frame. Off, the field keeps the light, distances and probe places it holds, its grids stay where they stand, and every surface reads it as it stands, so two frames drawn apart read the same field: what changes between them is what else changed. On again, the field goes on from what it holds. |
# a setup member
- id: probeGI
source: "@builtin::systems.probeGI.probeGI"
values:
skySource: "@builtin::systems.sky.skyLight"
raysPerProbe: 48