Skip to content

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Apr 26, 2025

Related issue: -

Description

Two or more PMREM nodes might refer to the same source textures. This use case currently works just for the first PMREM node since the second one produce a runtime error that can be reproduce with webgpu_materials_envmaps_bpcem. Just unselect the checkbox "box projected" and check the browser console:

three.webgpu.js:22545 Uncaught TypeError: Cannot set properties of undefined (setting 'material')
at PMREMGenerator._textureToCubeUV (three.webgpu.js:22545:17)
at PMREMGenerator._fromTexture (three.webgpu.js:22362:8)
at PMREMGenerator.fromCubemap (three.webgpu.js:22232:15)
at _getPMREMFromTexture (three.webgpu.js:22919:30)
at Proxy.updateBefore (three.webgpu.js:23140:13)
at Proxy.setup (three.webgpu.js:23164:8)
at Proxy.build (three.webgpu.js:1678:29)
at Proxy.build (three.webgpu.js:2209:16)
at Proxy.setup (three.webgpu.js:7086:26)
at Proxy.build (three.webgpu.js:1678:29)

That happens because every PMREM node has its own PMREMGenerator. The render targets used for generating the PMREM are cached and managed globally for the source texture. Meaning if the second generator wants to re-generate the PMREM, its internal state isn't ready. The PR fixes this issue by renaming _allocateTargets() to _allocateTarget() and just use the method for allocating the destination render target. A new _init() method makes sure internal resources (e.g the LOD planes or the blur material) are created if not ready. Exactly these resource were missing in the second generator and produced the above runtime error.

Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.33
78.33
336.33
78.33
+0 B
+0 B
WebGPU 547.45
151.77
547.49
151.78
+43 B
+9 B
WebGPU Nodes 546.8
151.61
546.84
151.62
+43 B
+8 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 465.78
112.28
465.78
112.28
+0 B
+0 B
WebGPU 622.3
168.35
622.34
168.36
+43 B
+9 B
WebGPU Nodes 577.17
157.62
577.22
157.63
+43 B
+3 B

@Mugen87 Mugen87 added this to the r177 milestone Apr 26, 2025
@sunag sunag merged commit 25873ff into mrdoob:dev Apr 27, 2025
12 checks passed
RuthySheffi pushed a commit to RuthySheffi/three.js that referenced this pull request Jun 5, 2025
RuthySheffi pushed a commit to RuthySheffi/three.js that referenced this pull request Jun 5, 2025
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