Repository navigation
Conversation
…#1715) Opt-in `caustics: "light-tracing"` (`causticPhotons` 1 to 64 per pixel sample): paths start on the emissive triangles, follow smooth glass and mirror bounces (dispersion with the hero wavelength included) and, after a solid caster, join the pinhole camera at the first rough or diffuse hit and are splatted into a u32 fixed point buffer (binding 15). The host adds the splat to the film sums. Camera paths drop the diffuse, smooth bounce, emitter chain they would find themselves. No MIS between the two. Off compiles the feature out of the kernel.
…e fan finder tools (crucible#1715) The dispersion short's prism scene sent its light out through the prism base by total internal reflection, so no fan reached the floor and light tracing had nothing to add there. With a tilted, lifted prism the fan exists, and a camera-path reference on the fan showed that filterGlossy blurred the camera paths' glass into a non-singular lobe: the caustic chain was not dropped, and the blurred copy of the caustic stayed in the image next to the light traced one. The blur now skips smooth glass and mirror lobes while light tracing is on. Tools: --prism-tilt, --prism-lift, --no-fill and --filter-glossy for caustic-render, caustic-diff (where light tracing added light), and caustic-reference takes SCENE_FLAGS, SIZE and BOX so its box can sit on the fan.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of codepawl/crucible#1715.
Opt-in light tracing for caustics:
caustics: "light-tracing"(packing option) withcausticPhotons(1 to 64 light paths per pixel sample, default 1). Off by default.What it does
atomicAdd, stochastic rounding). The host adds the splat to the film sums when it reads the film back (add_caustic_splat), rescaled to the photons really traced.caustic_photonstakes the first reserved word ofKernelParamsV2(byte 324, still 336 bytes); the flag iskernel_flagsbit 8192.FRAME_HAS_CAUSTIC_LIGHT_TRACINGis rewritten tofalseper frame, as the texture mip flag is).orthographic,noiseThreshold, an unknown value orcausticPhotonswithout light tracing, each naming what to pass.Limits (documented in the README): emissive triangles only (analytic lights and the environment are not light traced), pinhole (no depth of field in the caustic), no adaptive sampling, a caustic seen through glass is not joined, emission direction is not importance sampled toward casters.
Evidence
Why no rainbow appeared
The storyboard's prism lies flat on the floor under a sun that is high in the sky. With a debug counter at each stage of the light path (temporary, removed), 540 x 960, 8 samples x 32 photons: 132.7 M photons emitted, 92.4 M hit a surface, 189 k vertices after a caster, 23.7 k reached a diffuse surface, 23.0 k were inside the image, 29 passed the camera visibility test. The shadow ray of the other 22,989 hits the prism itself, and a map of where the photons land puts 99.9% of them under the prism (x -0.15 to 0.15, z -0.25 to 0.25). The cause is physics, not a culling bug: a ray entering the left face at that angle meets the right face at 53 degrees, past the 41 degree critical angle for glass of 1.517, is totally internally reflected and leaves through the base into the floor. There is no fan to the right of that prism, so the camera-path image has none either. Light tracing on that scene adds 1.0 in total to the picture (the difference image is black: https://raw.githubusercontent.com/codepawl/cook/evidence-52/diff-as-built.png).
The scene tools now take
--prism-tilt(turn about the prism axis, resting on its lowest edge) and--prism-lift(a stand). With tilt -30 degrees and lift 0.5 m the entry face is near the angle of minimum deviation and a fan lands on the floor: https://raw.githubusercontent.com/codepawl/cook/evidence-52/diff-s64-p32.png is the difference (light tracing on minus off, same seed, 64 x 32): added energy 3382, 3298, 3092 (R, G, B summed over the image), 15,199 pixels above 10% of the peak, box x 53 to 539, y 434 to 766, centroid (376, 572).Reference on the fan
Camera paths only (filterGlossy 0, 2048 samples, no fill panel) against light tracing (128 x 8), sun radius 0.3 with the same power, 270 x 480, mean of a 60 x 50 box inside the fan (x 150 to 210, y 270 to 320):
The ratio is stable across seeds and photon counts (a second reference seed gave 0.2021, 0.1912, 0.1768; 256 x 16 light tracing gave 0.1691), so it is bias, not noise. It is outside the 10% I aimed for and I do not yet know where the missing 15% is. With a sun of radius 0.8 the ratio was 0.96 (0.148 against 0.143), so it depends on the sun size. The earlier table in this description (ratio 1.0) was a box in the shadow that holds no caustic; the camera-path reference there equals the image without any sun at all.
What the reference showed, and the fix
The camera-path reference at the default filterGlossy found almost none of the caustic (box mean 0.082 with a sun of radius 0.8, the same as with no caustic), and with
filterGlossy: 0it found it (0.148). The blur turns the camera path's smooth glass into a non-singular lobe after a diffuse bounce. With light tracing that also meant the camera path's chain was not dropped, so a blurred copy of the caustic stayed next to the light traced one. The blur now skips smooth glass and mirror lobes while light tracing is on (test:light tracing keeps smooth glass sharp under filterGlossy).Timings and smoothness
Storyboard scene with tilt -30, lift 0.5 (prism, sun radius 0.09 emission 900, fill panel, floor, dispersion 1) on an RTX 3060 shared with other jobs, so the wall times carry neighbour load (they vary by up to 2x between identical runs). Roughness is the mean absolute difference of neighbouring pixels over the mean, in a 120 x 100 box on the fan (x 300 to 420, y 540 to 640 at 540 x 960; doubled at 1080 x 1920):
Roughness depends on samples x photons and not on the size; time grows with the pixel count. The fan reads as smooth at 128 x 64 (0.14) and reaches 0.10 at 256 x 64. Stills: https://raw.githubusercontent.com/codepawl/cook/evidence-52/540x960-s16-p4.png, https://raw.githubusercontent.com/codepawl/cook/evidence-52/540x960-s64-p32.png, https://raw.githubusercontent.com/codepawl/cook/evidence-52/540x960-s256-p64.png, https://raw.githubusercontent.com/codepawl/cook/evidence-52/1080x1920-s256-p64.png.
Not done: importance sampling of the emission toward the casters. Only 0.14% of the photons cross a caster here, so it would cut the time a lot (the photon count is the cost), but the fan is smooth without it at the counts above, and the 15% bias should be understood first.
How I checked it
node --test: 187 pass, includingtests/caustic-light-tracing.test.mjs(option validation, off packs the same bytes, the flag and photon word are the only differences, kernel text checks, a GPU test that light tracing changes no pixel of a scene without a caster, and a GPU test that filterGlossy does not move a light traced image of smooth glass).cargo test(addon crate): passes, including the new specialization test (flag off or zero photons compiles the feature out), the splat scale and kernel text test, andadd_caustic_splatunit tests.tools/caustic-reference.sh,tools/caustic-sweep.sh,tools/caustic-render.mjs,tools/caustic-noise.mjs,tools/caustic-diff.mjs.