Skip to content

WebGPURenderer: Replace "addLight" with "lightNode" reference - #34622

Merged
sunag merged 5 commits into
mrdoob:devfrom
gkjohnson:webgpu/light-nodes
Sep 21, 2026
Merged

sunag merged 5 commits into
mrdoob:devfrom
gkjohnson:webgpu/light-nodes

Conversation

@gkjohnson

@gkjohnson gkjohnson commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fix #34561
Related to #34218
Somewhat related to #34611, which moved area lights because it's not tree-shakeable at the moment.

Description

  • Replace internal light node map with a per-light "lightNode" reference on the prototype.
  • Deprecate the "addLight", "getLightNodeClass", and "addClass" functions.
  • Update the examples.

This will allow users to use class inheritance without breaking light rendering. And eventually this should allow for tree shaking the lights and light nodes in WebGPURenderer to reduce file sizes when the nodes can be assigned in-place in the light constructors. But that will require some some discussions around WebGLRenderer since it would mean importing all associated nodes with every light unless there are some other ideas for the short term.

@gkjohnson gkjohnson added this to the r187 milestone Sep 21, 2026
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
Core 389.56
102.22
389.61
102.25
+51 B
+26 B
WebGL 372.86
87.27
372.86
87.27
+0 B
+0 B
WebGPU 424.46
114.27
424.33
114.29
-128 B
+15 B
WebGPU Nodes 710.24
195.1
710.08
195.1
-160 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 517.33
124.35
517.33
124.35
+0 B
+0 B
WebGPU 763.61
204.37
763.42
204.62
-186 B
+244 B
WebGPU Nodes 709.61
190.95
709.42
191.19
-186 B
+238 B

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

🖼️ E2E screenshot tests

✅ All examples render correctly again (run).

Comment thread examples/jsm/lighting/LightProbeGrid.js Resolved
@Mugen87
Mugen87 requested a review from sunag September 21, 2026 09:03
@sunag
sunag merged commit b85bb7f into mrdoob:dev Sep 21, 2026
10 checks passed
@gkjohnson
gkjohnson deleted the webgpu/light-nodes branch September 21, 2026 14:59

renderer = new THREE.WebGPURenderer( { antialias: true } );
renderer.library.addLight( SunLightNode, SunLight );
SunLight.registerNode( SunLightNode );

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we're not doing this directly in SunLight to avoid bloating SunLight with node code when it's being used by the WebGLRenderer?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we're not doing this directly in SunLight to avoid bloating SunLight with node code when it's being used by the WebGLRenderer?

Yeah that's right. And tree shaking can't work for the built-in light nodes at the moment because it's using static functions in module scope / prototype modification. Unfortunately I don't know of a great way to address this without doing something like adding dedicate exports for WebGPURenderer-versions of lights. Eventually when WebGLRenderer is dropped (or at least priority is shifted away from supporting an optimal version of it) these kinds of concessions for the renderer can be addressed more easily.

Another option is to lean a bit harder into node support for WebGLRenderer.

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.

IESSpotLight: Creating a subclass of IESSpotLight breaks the light functionality

4 participants