Skip to content

Reflection probes: compute PMREM + reusable bakes (tracking, on top of #35046) - #1

Open
DennisSmolek wants to merge 5 commits into
base/bhouston-specular-probesfrom
pmrem-compute-probes
Open

DennisSmolek wants to merge 5 commits into
base/bhouston-specular-probesfrom
pmrem-compute-probes

Conversation

@DennisSmolek

@DennisSmolek DennisSmolek commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Tracking PR for our work on top of @bhouston's reflection probes (mrdoob#35046). The base branch, base/bhouston-specular-probes, is a copy of bhouston/specular-probes at e7ca274039, 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

Commit What Depends on
01b04cf96d PMREMGenerator: Prefilter with compute shaders on WebGPU. The same filter as dev, run as compute: one dispatch per level for all six faces, with the rough levels shared across a 64-thread workgroup. Output matches dev to half-float precision. This is the commit for the upstream PMREM PR. nothing; it also applies cleanly to dev
0b60cc22dd ReflectionProbes: Reuse the cube array and PMREM between bakes, add live capture to the example. bake() keeps its generator, PMREM and cube array while the resolution and probe count stay the same, so a re-bake neither allocates nor changes probes.texture. The example gets a "Live Capture" toggle that re-bakes every frame with the dynamic object included. nothing; independent of the compute commit
5757782928 A first attempt at the live capture flicker: a roughness floor for the bunny during capture. It reduced the flicker but didn't remove it, and the next commit replaces it. 0b60cc22dd
3cb8af5b6b ReflectionProbes: Capture the environment first and only when it changed, and clear it when it's removed. It fixes a bug in 0b60cc22dd: with the cube array reused, setting scene.environment to null left 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, version and pmremVersion) isn't captured again. 0b60cc22dd
0726aadb5b Examples: Animate the rooms, and keep the bunny out of live captures unless asked. The room lights drift through colours and the knot turns ("Animate Room"), so live capture has something to show. The bunny is left out of captures by default, and "Include in Capture" puts it back to show the flicker. 5757782928

To cherry-pick onto specular-probes:

git fetch https://github.com/DennisSmolek/three.js.git pmrem-compute-probes
git cherry-pick 01b04cf96d                # compute PMREM only
git cherry-pick 0b60cc22dd^..3cb8af5b6b   # bake() reuse, the example changes and the environment fix, in order

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() in webgpu_reflection_probes (3 probes + environment = 4 cubes):

Resolution specular-probes + compute + compute + reuse
64 21.7 ms 22.7 ms 16.8 ms
128 25.2 ms 23.2 ms 17.1 ms
256 28.8 ms 24.1 ms 17.4 ms

The compute commit alone helps little at small sizes, because bake() creates a new PMREMGenerator on 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, from npm run benchmark-pmrem), including mrdoob#35048:

Input dev mrdoob#35048 compute both
64 4.59 ms 2.45 ms 1.18 ms 0.75 ms
128 4.59 ms 3.60 ms 1.16 ms 0.86 ms
256 4.60 ms 4.64 ms 1.17 ms 1.08 ms

mrdoob#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:

Variant Biggest frame-to-frame step Reversals
Mirror bunny in the capture 9.41 26
Roughness floor of 0.1 during capture (5757782928) 1.17 2
Bunny paused, or set to None 0.00 0
Default now: bunny excluded, room animating (0726aadb5b) 0.14 0 (smooth colour drift)
"Include in Capture" on 7.25 18

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-probes with these commits
Textures 4 0
Render pipelines / shader modules 2 / 4 0 / 0
Bind groups 72 0
Buffers 6 0
Texture views 129 1 (the canvas)

An idea: time slicing (not part of this PR)

probes-timeslice-idea adds a probes option to bake() 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.html

Notes

  • 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-probes does this on every bake, since it always allocates a new array; with these commits it only happens on layout changes. Fixing it would mean switching ReflectionProbesNode to 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-probes without 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. ReflectionProbesNode still samples probes.texture while 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.

DennisSmolek and others added 2 commits October 18, 2026 12:07
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>
@github-actions

Copy link
Copy Markdown

📦 Bundle size

Full ESM build including core, minified and gzipped.

Before After Diff
Core 392.32
102.83
392.45
102.86
+133 B
+27 B
WebGL 778.74
194.39
778.87
194.41
+133 B
+17 B
WebGPU 1104.05
297.16
1105.93
297.91
+1.88 kB
+748 B
WebGPU Nodes 1102.00
296.81
1103.88
297.56
+1.88 kB
+747 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 518.96
124.67
518.96
124.67
+0 B
+0 B
WebGPU 782.38
209.41
788.04
211.29
+5.67 kB
+1.88 kB
WebGPU Nodes 728.48
195.98
734.21
197.64
+5.72 kB
+1.66 kB

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🖼️ E2E screenshot tests

❌ 1 example(s) failed (full artifacts).

Example Expected Actual Diff
webgpu_reflection_probes

DennisSmolek and others added 3 commits October 19, 2026 13:55
…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>
@bhouston

Copy link
Copy Markdown

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?

@DennisSmolek

Copy link
Copy Markdown
Owner Author

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.

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..

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.

2 participants