Skip to content

Add a per-light bounce limit like Cycles' light max_bounces - #67

Merged
anxuanng merged 2 commits into
mainfrom
2015-per-light-bounces
Nov 17, 2026
Merged

anxuanng merged 2 commits into
mainfrom
2015-per-light-bounces

Conversation

@anxuanng

@anxuanng anxuanng commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Part of codepawl/crucible#2015. Crucible moves its pin to this commit in its own pull request.

A light input may carry maxBounces (0 to 254), the equivalent of a Cycles light's max_bounces. The Classroom sun (limit 2) is 1.6 times too bright in Crucible only because Cook runs every light to the scene limit (codepawl/crucible#2013).

Design

  • Format: bits 8 to 15 of LightRecord.flags hold limit + 1; 0 means no limit beyond the scene's. No new field and no change in record size, and an input packed before this reads as no limit, so PACK_REVISION stays. Documented in FORMAT-v2.md section 6.
  • Kernel: a limited light adds direct light only at path vertices 0..limit. The light sample (surface, tree and volume paths) reads the current vertex; a bounced ray that reaches a light reads the vertex that cast it, so the sample and the hit of one MIS pair pass the same test. Camera rays are not limited.
  • v1 input: the sun's code rides in the fourth float of the sun direction, every other light's in the last float of its last texel; the v1 to v2 upgrade rebuilds maxBounces from them (the path Crucible's render jobs take).
  • Packer: lights.sun, points[], spots[] and areas[] take maxBounces; anything but a whole number from 0 to 254 throws a RangeError that says what to pass.

How I checked it

  • node --test tests/light-bounce-limit.test.mjs -> 3 pass; with pack-input-v2.mjs reverted to main, 2 of the 3 fail. tests/light-bounce-limit-v1.test.mjs -> 2 pass (v1 sun slot, upgrade). All tests/*.test.mjs -> 185 pass; earlier 2 fail (bits not written, bad values not refused).
  • node --test on js-surface-validation, legacy-kernel-pack, shadow-ray-pick, test-discovery, pack-revision, shading-parity -> 47 pass.
  • Not run: the WGSL change was not compiled and tests/gpu/light-bounce-limit.test.mjs (a sun of limit 0 leaves a wall that only the floor bounce lights dark; limit 1 lights it; limit 254 equals no limit) skips here. This machine has no GPU budget; the lavapipe job compiles the kernel and traces the room fixture.

Evidence

Nothing to show for the default: a light without maxBounces packs the same bits as before.

…/crucible#2015)

A light input may carry maxBounces (0 to 254). The packer stores it as limit + 1 in bits 8 to 15 of
LightRecord.flags; 0 keeps today's behaviour, so older inputs render the same and the record size
does not change. The kernel adds a limited light's direct light, and its MIS hit from a bounced ray,
only at path vertices 0..limit, so the sample and the hit share one rule.

Tests: a pack test (no GPU) pins the bits, the default and the refusal of bad values; a trace test
for a GPU runner pins the kernel on a wall that only the floor bounce lights. Not run here: the
kernel was not compiled or traced on this machine.
@anxuanng
anxuanng merged commit 6437bb7 into main Nov 17, 2026
5 checks passed
@anxuanng
anxuanng deleted the 2015-per-light-bounces branch November 17, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant