Просмотр исходного кода

Revert "MathNode: Fix `transformDirection()`." (#33349)

WestLangley 1 месяц назад
Родитель
Сommit
8b169b04ff

+ 3 - 3
src/nodes/accessors/Normal.js

@@ -1,5 +1,5 @@
 import { attribute } from '../core/AttributeNode.js';
-import { cameraViewMatrix, cameraWorldMatrix } from './Camera.js';
+import { cameraViewMatrix } from './Camera.js';
 import { modelNormalMatrix, modelWorldMatrix } from './ModelNode.js';
 import { mat3, vec3, Fn } from '../tsl/TSLBase.js';
 import { positionView } from './Position.js';
@@ -74,7 +74,7 @@ export const normalViewGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {
  */
 export const normalWorldGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {
 
-	let normal = normalViewGeometry.transformDirection( cameraWorldMatrix );
+	let normal = normalViewGeometry.transformDirection( cameraViewMatrix );
 
 	if ( builder.isFlatShading() !== true ) {
 
@@ -124,7 +124,7 @@ export const normalView = /*@__PURE__*/ ( Fn( ( builder ) => {
  * @tsl
  * @type {Node<vec3>}
  */
-export const normalWorld = /*@__PURE__*/ normalView.transformDirection( cameraWorldMatrix ).toVar( 'normalWorld' );
+export const normalWorld = /*@__PURE__*/ normalView.transformDirection( cameraViewMatrix ).toVar( 'normalWorld' );
 
 /**
  * TSL object that represents the clearcoat vertex normal of the current rendered object in view space.

+ 3 - 3
src/nodes/accessors/ReflectVector.js

@@ -1,4 +1,4 @@
-import { cameraWorldMatrix } from './Camera.js';
+import { cameraViewMatrix } from './Camera.js';
 import { normalView } from './Normal.js';
 import { positionViewDirection } from './Position.js';
 import { materialRefractionRatio } from './MaterialProperties.js';
@@ -25,7 +25,7 @@ export const refractView = /*@__PURE__*/ positionViewDirection.negate().refract(
  * @tsl
  * @type {Node<vec3>}
  */
-export const reflectVector = /*@__PURE__*/ reflectView.transformDirection( cameraWorldMatrix ).toVar( 'reflectVector' );
+export const reflectVector = /*@__PURE__*/ reflectView.transformDirection( cameraViewMatrix ).toVar( 'reflectVector' );
 
 /**
  * Used for sampling cube maps when using cube refraction mapping.
@@ -33,4 +33,4 @@ export const reflectVector = /*@__PURE__*/ reflectView.transformDirection( camer
  * @tsl
  * @type {Node<vec3>}
  */
-export const refractVector = /*@__PURE__*/ refractView.transformDirection( cameraWorldMatrix ).toVar( 'reflectVector' );
+export const refractVector = /*@__PURE__*/ refractView.transformDirection( cameraViewMatrix ).toVar( 'reflectVector' );

+ 2 - 2
src/nodes/accessors/Tangent.js

@@ -1,5 +1,5 @@
 import { attribute } from '../core/AttributeNode.js';
-import { cameraWorldMatrix } from './Camera.js';
+import { cameraViewMatrix } from './Camera.js';
 import { modelViewMatrix } from './ModelNode.js';
 import { Fn, vec4 } from '../tsl/TSLBase.js';
 import { tangentViewFrame } from './TangentUtils.js';
@@ -57,4 +57,4 @@ export const tangentView = /*@__PURE__*/ ( Fn( ( builder ) => {
  * @tsl
  * @type {Node<vec3>}
  */
-export const tangentWorld = /*@__PURE__*/ tangentView.transformDirection( cameraWorldMatrix ).toVarying( 'v_tangentWorld' ).normalize().toVar( 'tangentWorld' );
+export const tangentWorld = /*@__PURE__*/ tangentView.transformDirection( cameraViewMatrix ).toVarying( 'v_tangentWorld' ).normalize().toVar( 'tangentWorld' );

+ 2 - 2
src/nodes/lighting/EnvironmentNode.js

@@ -1,7 +1,7 @@
 import LightingNode from './LightingNode.js';
 import { isolate } from '../core/IsolateNode.js';
 import { roughness, clearcoatRoughness } from '../core/PropertyNode.js';
-import { cameraWorldMatrix } from '../accessors/Camera.js';
+import { cameraViewMatrix } from '../accessors/Camera.js';
 import { normalView, clearcoatNormalView, normalWorld } from '../accessors/Normal.js';
 import { positionViewDirection } from '../accessors/Position.js';
 import { float, pow4 } from '../tsl/TSLBase.js';
@@ -144,7 +144,7 @@ const createRadianceContext = ( roughnessNode, normalViewNode ) => {
 				// Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.
 				reflectVec = pow4( roughnessNode ).mix( reflectVec, normalViewNode ).normalize();
 
-				reflectVec = reflectVec.transformDirection( cameraWorldMatrix );
+				reflectVec = reflectVec.transformDirection( cameraViewMatrix );
 
 			}
 

+ 8 - 7
src/nodes/math/MathNode.js

@@ -184,21 +184,22 @@ class MathNode extends TempNode {
 			// dir can be either a direction vector or a normal vector
 			// upper-left 3x3 of matrix is assumed to be orthogonal
 
-			let matrixNode, dirNode;
+			let tA = aNode;
+			let tB = bNode;
 
-			if ( builder.isMatrix( aNode.getNodeType( builder ) ) ) {
+			if ( builder.isMatrix( tA.getNodeType( builder ) ) ) {
 
-				matrixNode = aNode;
-				dirNode = vec4( vec3( bNode ), 0.0 );
+				tB = vec4( vec3( tB ), 0.0 );
 
 			} else {
 
-				matrixNode = bNode;
-				dirNode = vec4( vec3( aNode ), 0.0 );
+				tA = vec4( vec3( tA ), 0.0 );
 
 			}
 
-			outputNode = normalize( mul( matrixNode, dirNode ).xyz );
+			const mulNode = mul( tA, tB ).xyz;
+
+			outputNode = normalize( mulNode );
 
 		}
 

粤ICP备19079148号