Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

probe_bake

Bakes irradiance-volume probes on the GPU — one thread per probe of the chunk a dispatch covers. Each thread casts N uniform-sphere rays and path-traces each one through up to bounces surface interactions: every path vertex contributes its emissive plus its albedo (carried on the triangle records by compute.buildBvh) times the shadowed direct light there, and a segment that escapes contributes the sky. The resulting incoming radiance is projected into 9 SH L2 coefficients (Monte Carlo weighted) and written as 9 RGBA vec4s into output. Mirrors lightmap_bake's traversal + light model.

Bindings (see bindings.yaml): output (read_write), probe_positions, bvh_nodes, triangles, lights, bake_params — all array<vec4<f32>>. bake_params holds the per-bake constants the host packs once; the params uniform the engine appends is read per dispatch.

Dispatch shape

One bake is many dispatches. Each carries its own params: stage (1 = trace samples, 2 = write the completion flag), itemBase and itemCount (the probes of the chunk), sampleBegin and sampleEnd (the samples of the pass), and gridWidth. A probe's running sums sit in its record between passes (the coefficients in .xyz, the count of back-face exits in the first coefficient's .w); the pass that reaches the last sample adds the direct lobes, computes the six reaches and writes the final record. Stage 2 is one workgroup whose first invocation writes the flag, issued after every probe's last pass. A probe's result does not depend on how the host split the work.

Usage: dispatch by identity with compute.dispatch("@builtin::systems.globalIllumination.probe_bake", ...) (buffers in bindings order) — it resolves to the shader's stable guid and auto-compiles on first use (no setup).