Skip to content

Camera: Exclude scale from view matrix.#32805

Merged
Mugen87 merged 2 commits into
mrdoob:devfrom
Mugen87:dev5
Jan 22, 2026
Merged

Camera: Exclude scale from view matrix.#32805
Mugen87 merged 2 commits into
mrdoob:devfrom
Mugen87:dev5

Conversation

@Mugen87

@Mugen87 Mugen87 commented Jan 20, 2026

Copy link
Copy Markdown
Collaborator

Related issue: #26659

Description

The PR makes the computation of the view matrix glTF conform by excluding the scale. From the spec:

The view matrix is derived from the global transform of the node containing the camera with the scaling ignored.

That fixes the lighting issues reported in #26659 when a uniform scale is applied to the camera. When taking the code from the fiddle and testing with the PR, it renders now as expected meaning the lighting does not change anymore.

@github-actions

github-actions Bot commented Jan 20, 2026

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 356.54
84.66
356.54
84.66
+0 B
+0 B
WebGPU 621.71
172.64
621.71
172.64
+0 B
+0 B
WebGPU Nodes 620.31
172.4
620.31
172.4
+0 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 489.06
119.62
489.35
119.68
+292 B
+58 B
WebGPU 692.38
187.94
692.67
187.95
+292 B
+15 B
WebGPU Nodes 642.06
175.09
642.35
175.13
+292 B
+41 B

Comment thread src/cameras/Camera.js

this.matrixWorld.decompose( _position, _quaternion, _scale );

if ( _scale.x === 1 && _scale.y === 1 && _scale.z === 1 ) {

@Mugen87 Mugen87 Jan 21, 2026

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.

Small optimization: If the scale is already 1, the method does not use a compose() to produce the view matrix.

@Mugen87

Mugen87 commented Jan 21, 2026

Copy link
Copy Markdown
Collaborator Author

@hybridherbst With a glTF complaint view matrix, the uniform scale use case from #26659 (comment) works now. However, with a non-uniform scale as well with negative scales, we can't use decompose() so we need a different approach for these use cases. However, with this PR uniformly scaled cameras should be (officially) supported.

@Mugen87 Mugen87 added this to the r183 milestone Jan 22, 2026
@Mugen87 Mugen87 merged commit 6e4cc1e into mrdoob:dev Jan 22, 2026
10 checks passed
@hybridherbst

Copy link
Copy Markdown
Contributor

Hi! That's great to hear. I think non-uniform camera scales are fortunately relatively rare but can still happen (e.g. when parenting a camera to something; another usecase that is not quite supported by three.js at the moment – see our older PRs for improving OrbitControls).

hybridherbst pushed a commit to needle-tools/three.js that referenced this pull request Feb 5, 2026
alvarosabu added a commit to Tresjs/tres that referenced this pull request Mar 26, 2026
Three.js r183 strips parent scale from camera view matrix (mrdoob/three.js#32805).
ContactShadows relied on shadowGroup scale to expand the camera frustum.
Fix sets camera frustum to world-space (scaled) dimensions directly
and calls updateProjectionMatrix() after changing frustum params.

Closes #1392

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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