Skip to content

WebGLRenderer Shaders: introduce transformNormalByInverseViewMatrix()#33351

Open
WestLangley wants to merge 2 commits intomrdoob:devfrom
WestLangley:dev-inverse_view_matrix
Open

WebGLRenderer Shaders: introduce transformNormalByInverseViewMatrix()#33351
WestLangley wants to merge 2 commits intomrdoob:devfrom
WestLangley:dev-inverse_view_matrix

Conversation

@WestLangley
Copy link
Copy Markdown
Collaborator

@WestLangley WestLangley commented Apr 7, 2026

This PR removes inverseTransformDirection() and introduces two new functions:

transformNormalByInverseViewMatrix() and

transformDirectionByInverseViewMatrix().

inverseTransformDirection() was used to transform both normals and direction vectors, leading to confusion.

@WestLangley WestLangley added this to the r184 milestone Apr 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 360.57
85.58
360.81
85.62
+235 B
+41 B
WebGPU 635.48
176.41
635.48
176.41
+0 B
+0 B
WebGPU Nodes 633.6
176.11
633.6
176.11
+0 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 492.95
120.2
493.19
120.24
+235 B
+40 B
WebGPU 707.66
191.31
707.66
191.31
+0 B
+0 B
WebGPU Nodes 656.88
178.57
656.88
178.57
+0 B
+0 B

reflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );

reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
reflectVec = transformNormalByInverseViewMatrix( reflectVec, viewMatrix );
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.

Hmm... reflectVec. What to make of applying this method to this particular vector?

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.

Maybe we add transformDirectionByInverseViewMatrix() for clarity? The code would be the same. It would be a small duplication of code, but more clear.

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

@WestLangley WestLangley changed the title WebGLRenderer Shaders: rename inverseTransformDirection() WebGLRenderer Shaders: introduce transformNormalByInverseViewMatrix() Apr 7, 2026
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.

1 participant