Skip to content

Commit 8b169b0

Browse files
authored
Revert "MathNode: Fix transformDirection()." (#33349)
1 parent e4110f5 commit 8b169b0

5 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/nodes/accessors/Normal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { attribute } from '../core/AttributeNode.js';
2-
import { cameraViewMatrix, cameraWorldMatrix } from './Camera.js';
2+
import { cameraViewMatrix } from './Camera.js';
33
import { modelNormalMatrix, modelWorldMatrix } from './ModelNode.js';
44
import { mat3, vec3, Fn } from '../tsl/TSLBase.js';
55
import { positionView } from './Position.js';
@@ -74,7 +74,7 @@ export const normalViewGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {
7474
*/
7575
export const normalWorldGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {
7676

77-
let normal = normalViewGeometry.transformDirection( cameraWorldMatrix );
77+
let normal = normalViewGeometry.transformDirection( cameraViewMatrix );
7878

7979
if ( builder.isFlatShading() !== true ) {
8080

@@ -124,7 +124,7 @@ export const normalView = /*@__PURE__*/ ( Fn( ( builder ) => {
124124
* @tsl
125125
* @type {Node<vec3>}
126126
*/
127-
export const normalWorld = /*@__PURE__*/ normalView.transformDirection( cameraWorldMatrix ).toVar( 'normalWorld' );
127+
export const normalWorld = /*@__PURE__*/ normalView.transformDirection( cameraViewMatrix ).toVar( 'normalWorld' );
128128

129129
/**
130130
* TSL object that represents the clearcoat vertex normal of the current rendered object in view space.

src/nodes/accessors/ReflectVector.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cameraWorldMatrix } from './Camera.js';
1+
import { cameraViewMatrix } from './Camera.js';
22
import { normalView } from './Normal.js';
33
import { positionViewDirection } from './Position.js';
44
import { materialRefractionRatio } from './MaterialProperties.js';
@@ -25,12 +25,12 @@ export const refractView = /*@__PURE__*/ positionViewDirection.negate().refract(
2525
* @tsl
2626
* @type {Node<vec3>}
2727
*/
28-
export const reflectVector = /*@__PURE__*/ reflectView.transformDirection( cameraWorldMatrix ).toVar( 'reflectVector' );
28+
export const reflectVector = /*@__PURE__*/ reflectView.transformDirection( cameraViewMatrix ).toVar( 'reflectVector' );
2929

3030
/**
3131
* Used for sampling cube maps when using cube refraction mapping.
3232
*
3333
* @tsl
3434
* @type {Node<vec3>}
3535
*/
36-
export const refractVector = /*@__PURE__*/ refractView.transformDirection( cameraWorldMatrix ).toVar( 'reflectVector' );
36+
export const refractVector = /*@__PURE__*/ refractView.transformDirection( cameraViewMatrix ).toVar( 'reflectVector' );

src/nodes/accessors/Tangent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { attribute } from '../core/AttributeNode.js';
2-
import { cameraWorldMatrix } from './Camera.js';
2+
import { cameraViewMatrix } from './Camera.js';
33
import { modelViewMatrix } from './ModelNode.js';
44
import { Fn, vec4 } from '../tsl/TSLBase.js';
55
import { tangentViewFrame } from './TangentUtils.js';
@@ -57,4 +57,4 @@ export const tangentView = /*@__PURE__*/ ( Fn( ( builder ) => {
5757
* @tsl
5858
* @type {Node<vec3>}
5959
*/
60-
export const tangentWorld = /*@__PURE__*/ tangentView.transformDirection( cameraWorldMatrix ).toVarying( 'v_tangentWorld' ).normalize().toVar( 'tangentWorld' );
60+
export const tangentWorld = /*@__PURE__*/ tangentView.transformDirection( cameraViewMatrix ).toVarying( 'v_tangentWorld' ).normalize().toVar( 'tangentWorld' );

src/nodes/lighting/EnvironmentNode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import LightingNode from './LightingNode.js';
22
import { isolate } from '../core/IsolateNode.js';
33
import { roughness, clearcoatRoughness } from '../core/PropertyNode.js';
4-
import { cameraWorldMatrix } from '../accessors/Camera.js';
4+
import { cameraViewMatrix } from '../accessors/Camera.js';
55
import { normalView, clearcoatNormalView, normalWorld } from '../accessors/Normal.js';
66
import { positionViewDirection } from '../accessors/Position.js';
77
import { float, pow4 } from '../tsl/TSLBase.js';
@@ -144,7 +144,7 @@ const createRadianceContext = ( roughnessNode, normalViewNode ) => {
144144
// Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.
145145
reflectVec = pow4( roughnessNode ).mix( reflectVec, normalViewNode ).normalize();
146146

147-
reflectVec = reflectVec.transformDirection( cameraWorldMatrix );
147+
reflectVec = reflectVec.transformDirection( cameraViewMatrix );
148148

149149
}
150150

src/nodes/math/MathNode.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,22 @@ class MathNode extends TempNode {
184184
// dir can be either a direction vector or a normal vector
185185
// upper-left 3x3 of matrix is assumed to be orthogonal
186186

187-
let matrixNode, dirNode;
187+
let tA = aNode;
188+
let tB = bNode;
188189

189-
if ( builder.isMatrix( aNode.getNodeType( builder ) ) ) {
190+
if ( builder.isMatrix( tA.getNodeType( builder ) ) ) {
190191

191-
matrixNode = aNode;
192-
dirNode = vec4( vec3( bNode ), 0.0 );
192+
tB = vec4( vec3( tB ), 0.0 );
193193

194194
} else {
195195

196-
matrixNode = bNode;
197-
dirNode = vec4( vec3( aNode ), 0.0 );
196+
tA = vec4( vec3( tA ), 0.0 );
198197

199198
}
200199

201-
outputNode = normalize( mul( matrixNode, dirNode ).xyz );
200+
const mulNode = mul( tA, tB ).xyz;
201+
202+
outputNode = normalize( mulNode );
202203

203204
}
204205

0 commit comments

Comments
 (0)