|
|
@@ -1,9 +1,9 @@
|
|
|
import { attribute } from '../core/AttributeNode.js';
|
|
|
import { cameraViewMatrix } from './Camera.js';
|
|
|
import { modelNormalMatrix, modelWorldMatrix } from './ModelNode.js';
|
|
|
-import { mat3, vec3, Fn, varying } from '../tsl/TSLBase.js';
|
|
|
+import { mat3, vec3, Fn } from '../tsl/TSLBase.js';
|
|
|
import { positionView } from './Position.js';
|
|
|
-import { faceDirection } from '../display/FrontFacingNode.js';
|
|
|
+import { directionToFaceDirection } from '../display/FrontFacingNode.js';
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the normal attribute of the current rendered object.
|
|
|
@@ -47,7 +47,7 @@ export const normalFlat = /*@__PURE__*/ positionView.dFdx().cross( positionView.
|
|
|
* @tsl
|
|
|
* @type {Node<vec3>}
|
|
|
*/
|
|
|
-export const normalView = /*@__PURE__*/ ( Fn( ( builder ) => {
|
|
|
+export const normalViewGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {
|
|
|
|
|
|
let node;
|
|
|
|
|
|
@@ -57,13 +57,13 @@ export const normalView = /*@__PURE__*/ ( Fn( ( builder ) => {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- node = varying( transformNormalToView( normalLocal ), 'v_normalView' ).normalize();
|
|
|
+ node = transformNormalToView( normalLocal ).toVarying( 'v_normalViewGeometry' ).normalize();
|
|
|
|
|
|
}
|
|
|
|
|
|
return node;
|
|
|
|
|
|
-}, 'vec3' ).once() )().toVar( 'normalView' );
|
|
|
+}, 'vec3' ).once() )().toVar( 'normalViewGeometry' );
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the vertex normal in world space of the current rendered object.
|
|
|
@@ -71,19 +71,19 @@ export const normalView = /*@__PURE__*/ ( Fn( ( builder ) => {
|
|
|
* @tsl
|
|
|
* @type {Node<vec3>}
|
|
|
*/
|
|
|
-export const normalWorld = /*@__PURE__*/ ( Fn( ( builder ) => {
|
|
|
+export const normalWorldGeometry = /*@__PURE__*/ ( Fn( ( builder ) => {
|
|
|
|
|
|
- let normal = normalView.transformDirection( cameraViewMatrix );
|
|
|
+ let normal = normalViewGeometry.transformDirection( cameraViewMatrix );
|
|
|
|
|
|
if ( builder.material.flatShading !== true ) {
|
|
|
|
|
|
- normal = varying( normal, 'v_normalWorld' );
|
|
|
+ normal = normal.toVarying( 'v_normalWorldGeometry' );
|
|
|
|
|
|
}
|
|
|
|
|
|
- return normal;
|
|
|
+ return normal.normalize().toVar( 'normalWorldGeometry' );
|
|
|
|
|
|
-}, 'vec3' ).once() )().normalize().toVar( 'normalWorld' );
|
|
|
+}, 'vec3' ).once() )();
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the transformed vertex normal in view space of the current rendered object.
|
|
|
@@ -91,17 +91,31 @@ export const normalWorld = /*@__PURE__*/ ( Fn( ( builder ) => {
|
|
|
* @tsl
|
|
|
* @type {Node<vec3>}
|
|
|
*/
|
|
|
-export const transformedNormalView = /*@__PURE__*/ ( Fn( ( builder ) => {
|
|
|
+export const normalView = /*@__PURE__*/ ( Fn( ( { subBuildFn, material, context } ) => {
|
|
|
|
|
|
- // Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
|
|
|
+ let node;
|
|
|
+
|
|
|
+ if ( subBuildFn === 'NORMAL' || subBuildFn === 'VERTEX' ) {
|
|
|
+
|
|
|
+ node = normalViewGeometry;
|
|
|
+
|
|
|
+ if ( material.flatShading !== true ) {
|
|
|
+
|
|
|
+ node = directionToFaceDirection( node );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- let node = builder.context.setupNormal().context( { getUV: null } );
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
|
|
|
+
|
|
|
+ node = context.setupNormal().context( { getUV: null } );
|
|
|
|
|
|
- if ( builder.material.flatShading !== true ) node = node.mul( faceDirection );
|
|
|
+ }
|
|
|
|
|
|
return node;
|
|
|
|
|
|
-}, 'vec3' ).once() )().toVar( 'transformedNormalView' );
|
|
|
+}, 'vec3' ).once( [ 'NORMAL', 'VERTEX' ] ) )().toVar( 'normalView' );
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the transformed vertex normal in world space of the current rendered object.
|
|
|
@@ -109,7 +123,7 @@ export const transformedNormalView = /*@__PURE__*/ ( Fn( ( builder ) => {
|
|
|
* @tsl
|
|
|
* @type {Node<vec3>}
|
|
|
*/
|
|
|
-export const transformedNormalWorld = /*@__PURE__*/ transformedNormalView.transformDirection( cameraViewMatrix ).toVar( 'transformedNormalWorld' );
|
|
|
+export const normalWorld = /*@__PURE__*/ normalView.transformDirection( cameraViewMatrix ).toVar( 'normalWorld' );
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the transformed clearcoat vertex normal in view space of the current rendered object.
|
|
|
@@ -117,17 +131,25 @@ export const transformedNormalWorld = /*@__PURE__*/ transformedNormalView.transf
|
|
|
* @tsl
|
|
|
* @type {Node<vec3>}
|
|
|
*/
|
|
|
-export const transformedClearcoatNormalView = /*@__PURE__*/ ( Fn( ( builder ) => {
|
|
|
+export const clearcoatNormalView = /*@__PURE__*/ ( Fn( ( { subBuildFn, context } ) => {
|
|
|
|
|
|
- // Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
|
|
|
+ let node;
|
|
|
|
|
|
- let node = builder.context.setupClearcoatNormal().context( { getUV: null } );
|
|
|
+ if ( subBuildFn === 'NORMAL' || subBuildFn === 'VERTEX' ) {
|
|
|
|
|
|
- if ( builder.material.flatShading !== true ) node = node.mul( faceDirection );
|
|
|
+ node = normalView;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
|
|
|
+
|
|
|
+ node = context.setupClearcoatNormal().context( { getUV: null } );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
return node;
|
|
|
|
|
|
-}, 'vec3' ).once() )().toVar( 'transformedClearcoatNormalView' );
|
|
|
+}, 'vec3' ).once( [ 'NORMAL', 'VERTEX' ] ) )().toVar( 'clearcoatNormalView' );
|
|
|
|
|
|
/**
|
|
|
* Transforms the normal with the given matrix.
|
|
|
@@ -174,3 +196,47 @@ export const transformNormalToView = /*@__PURE__*/ Fn( ( [ normal ], builder ) =
|
|
|
return cameraViewMatrix.transformDirection( transformedNormal );
|
|
|
|
|
|
} );
|
|
|
+
|
|
|
+// Deprecated
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the transformed vertex normal in view space of the current rendered object.
|
|
|
+ *
|
|
|
+ * @tsl
|
|
|
+ * @type {Node<vec3>}
|
|
|
+ * @deprecated since r178. Use `normalView` instead.
|
|
|
+ */
|
|
|
+export const transformedNormalView = ( Fn( () => { // @deprecated, r177
|
|
|
+
|
|
|
+ console.warn( 'THREE.TSL: "transformedNormalView" is deprecated. Use "normalView" instead.' );
|
|
|
+ return normalView;
|
|
|
+
|
|
|
+} ).once( [ 'NORMAL', 'VERTEX' ] ) )();
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the transformed vertex normal in world space of the current rendered object.
|
|
|
+ *
|
|
|
+ * @tsl
|
|
|
+ * @type {Node<vec3>}
|
|
|
+ * @deprecated since r178. Use `normalWorld` instead.
|
|
|
+ */
|
|
|
+export const transformedNormalWorld = ( Fn( () => { // @deprecated, r177
|
|
|
+
|
|
|
+ console.warn( 'THREE.TSL: "transformedNormalWorld" is deprecated. Use "normalWorld" instead.' );
|
|
|
+ return normalWorld;
|
|
|
+
|
|
|
+} ).once( [ 'NORMAL', 'VERTEX' ] ) )();
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the transformed clearcoat vertex normal in view space of the current rendered object.
|
|
|
+ *
|
|
|
+ * @tsl
|
|
|
+ * @type {Node<vec3>}
|
|
|
+ * @deprecated since r178. Use `clearcoatNormalView` instead.
|
|
|
+ */
|
|
|
+export const transformedClearcoatNormalView = ( Fn( () => { // @deprecated, r177
|
|
|
+
|
|
|
+ console.warn( 'THREE.TSL: "transformedClearcoatNormalView" is deprecated. Use "clearcoatNormalView" instead.' );
|
|
|
+ return clearcoatNormalView;
|
|
|
+
|
|
|
+} ).once( [ 'NORMAL', 'VERTEX' ] ) )();
|