Repository navigation
Reflection probes: compute PMREM + reusable bakes (tracking, on top of #35046) - #1
DennisSmolek wants to merge 5 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ive capture to the example. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
📦 Bundle sizeFull ESM build including core, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
🖼️ E2E screenshot tests❌ 1 example(s) failed (full artifacts).
|
…y in webgpu_reflection_probes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… bunny out of live captures unless asked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ged, and clear it when it's removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This is phenomenal. The speed ups are massive. I agree that you should exclude the bunny from captures - all dynamic objects should be excluded from the captures. IT should be the static environment. Your speed up of the PMREM is build at the lowered resolution but @Mugen87 said that at this resolution it may not be guaranteed to be accurate/high quality: mrdoob#35048 (comment). So we may need to actually change the results of the PMREM at low resolutions, rather than match them exactly. Maybe that could be done via a separate PR. I think the solution to that problem is calculate a a perfect PMREM convolution for each size and then ensure that your code matches that perfect result rather than the current result? |
Sorry I missed this, I was prepping to PR upstream so I thought I PR'd to myself an early draft. I did a version where I exclude the bunny in this version https://pmndrs.github.io/denoiser/three-temporal/reflections-rooms.html But a lot of it super experimental. Im not sure on his quality remark. So far its been pretty solid. We use it in Sky and at work.. |



Tracking PR for our work on top of @bhouston's reflection probes (mrdoob#35046). The base branch,
base/bhouston-specular-probes, is a copy ofbhouston/specular-probesate7ca274039, so this diff shows only our commits. It's here for review and cherry-picking, and won't be merged.Live demo: https://raw.githack.com/DennisSmolek/three.js/pmrem-compute-probes/examples/webgpu_reflection_probes.html
Live Capture and Animate Room are on by default. The room lights drift through colours, the knot turns, and every reflection follows within the frame. Turn off Live Capture to see the reflections go stale, or turn on Dynamic Test → Include in Capture to see why moving mirrors are left out of probes.
Commits
01b04cf96ddev, run as compute: one dispatch per level for all six faces, with the rough levels shared across a 64-thread workgroup. Output matchesdevto half-float precision. This is the commit for the upstream PMREM PR.dev0b60cc22ddbake()keeps its generator, PMREM and cube array while the resolution and probe count stay the same, so a re-bake neither allocates nor changesprobes.texture. The example gets a "Live Capture" toggle that re-bakes every frame with the dynamic object included.57577829280b60cc22dd3cb8af5b6b0b60cc22dd: with the cube array reused, settingscene.environmenttonullleft the old environment in its slot. A changed environment is now captured before the probes, so they reflect it in the same bake instead of the next one. An unchanged environment (same texture,versionandpmremVersion) isn't captured again.0b60cc22dd0726aadb5b5757782928To cherry-pick onto
specular-probes:Measurements
Apple M5 Pro, Chrome 155 (Metal), headless, render loop stopped. Minimum of 7 bursts of 10 bakes, each burst waiting for
onSubmittedWorkDone(), with each build on its own origin. Two runs agree to within 1 ms.probes.bake()inwebgpu_reflection_probes(3 probes + environment = 4 cubes):specular-probesThe compute commit alone helps little at small sizes, because
bake()creates a newPMREMGeneratoron every call, which also rebuilds its compute nodes. With reuse, the bake no longer grows with resolution. Most of the remaining ~17 ms is the six scene renders per probe, so fully live probes would also want time-slicing, for example one probe or one face per frame, or re-baking only probes whose contents changed.PMREM alone (
fromCubemap, fromnpm run benchmark-pmrem), including mrdoob#35048:devmrdoob#35048 and the compute commit stack. Combined, the output matches mrdoob#35048 alone (≥ 99.3% of texels bit-identical, max difference 0.11%).
The live capture flicker
With a mirror bunny (roughness 0) in the live capture, a room's reflections flicker while the bunny passes near that room's probe. The cause is the room light's highlight on the mirror. From the probe it's smaller than one capture pixel and far brighter than the room, so each frame it either lands on a pixel centre (a huge spike) or falls between them (nothing). The prefilter spreads that one texel's energy across the rough levels, so the whole room pulses. Your code flickers identically once the bunny is in the capture, so it isn't caused by the reuse or the compute path. The original example never shows it because
capture()hides the bunny.Measured on the rendered right room, with the page's own animation loop running for 9 s:
5757782928)0726aadb5b)The roughness floor cut the flicker by about 6×, but it was still visible, so the example now follows the usual practice: moving objects stay out of the probes. Screen-space reflections are the usual way to show them.
No rebuilds
GPU objects created per frame during a live bake of 4 cubes plus the main render, after a warm-up:
specular-probesAn idea: time slicing (not part of this PR)
probes-timeslice-ideaadds aprobesoption tobake()to re-capture only some probes, and a Time Slicing toggle to the example that re-captures one probe per frame in turn. A live update then costs 4.8 ms per frame instead of 14.4 ms, with each probe at most three frames old, and after one round the result is identical to a full bake. Demo: https://raw.githack.com/DennisSmolek/three.js/37bf3312353d13a0b97b710b8320161452d927ac/examples/webgpu_reflection_probes.htmlNotes
A bake that changes the layout reflects the previous environment. When the resolution or probe count changes, materials keep sampling the previous cube array until the bake finishes, so the probes captured in that bake reflect the old environment slot. The next bake corrects it.
specular-probesdoes this on every bake, since it always allocates a new array; with these commits it only happens on layout changes. Fixing it would mean switchingReflectionProbesNodeto the new array mid-bake, which needs a shader rebuild.The first capture after a change can be one bake late. With the render loop stopped, the first bake after changing the lights captures the previous colours, and later bakes are correct.
specular-probeswithout our commits does the same, so it isn't caused by them. In a running loop it means a capture can be a frame behind. Worth a separate look.Bug found and fixed on the way: an earlier version of the reuse commit disposed the old cube array before capturing.
ReflectionProbesNodestill samplesprobes.texturewhile the probes render the scene, so the old array now stays alive until the new one is filled, as in the original code.Lights around
bake(): adding or removing lights changes every material's lighting setup and costs a rebuild on the next capture.bake()uses the scene's own lights, so it's unaffected, but code that adds a light just for a capture pays this cost; keeping such a light in the scene at intensity 0 avoids it.Box projection, blending and
ReflectionProbesNode: unchanged.