|
|
@@ -1,9 +1,31 @@
|
|
|
import { varying } from '../core/VaryingNode.js';
|
|
|
+import { Fn } from '../tsl/TSLCore.js';
|
|
|
import { cameraViewMatrix } from './Camera.js';
|
|
|
import { normalGeometry, normalLocal, normalView, normalWorld, transformedNormalView } from './Normal.js';
|
|
|
import { tangentGeometry, tangentLocal, tangentView, tangentWorld, transformedTangentView } from './Tangent.js';
|
|
|
|
|
|
-const getBitangent = ( crossNormalTangent ) => crossNormalTangent.mul( tangentGeometry.w ).xyz;
|
|
|
+/**
|
|
|
+ * Returns the bitangent node and assigns it to a varying if the material is not flat shaded.
|
|
|
+ *
|
|
|
+ * @tsl
|
|
|
+ * @private
|
|
|
+ * @param {Node<vec3>} crossNormalTangent - The cross product of the normal and tangent vectors.
|
|
|
+ * @param {string} varyingName - The name of the varying to assign the bitangent to.
|
|
|
+ * @returns {Node<vec3>} The bitangent node.
|
|
|
+ */
|
|
|
+const getBitangent = /*@__PURE__*/ Fn( ( [ crossNormalTangent, varyingName ], builder ) => {
|
|
|
+
|
|
|
+ let bitangent = crossNormalTangent.mul( tangentGeometry.w ).xyz;
|
|
|
+
|
|
|
+ if ( builder.material.flatShading !== true ) {
|
|
|
+
|
|
|
+ bitangent = varying( crossNormalTangent, varyingName );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return bitangent;
|
|
|
+
|
|
|
+} ).once();
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the bitangent attribute of the current rendered object.
|
|
|
@@ -11,7 +33,7 @@ const getBitangent = ( crossNormalTangent ) => crossNormalTangent.mul( tangentGe
|
|
|
* @tsl
|
|
|
* @type {Node<vec3>}
|
|
|
*/
|
|
|
-export const bitangentGeometry = /*@__PURE__*/ varying( getBitangent( normalGeometry.cross( tangentGeometry ) ), 'v_bitangentGeometry' ).normalize().toVar( 'bitangentGeometry' );
|
|
|
+export const bitangentGeometry = /*@__PURE__*/ getBitangent( normalGeometry.cross( tangentGeometry ), 'v_bitangentGeometry' ).normalize().toVar( 'bitangentGeometry' );
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the vertex bitangent in local space of the current rendered object.
|
|
|
@@ -19,31 +41,31 @@ export const bitangentGeometry = /*@__PURE__*/ varying( getBitangent( normalGeom
|
|
|
* @tsl
|
|
|
* @type {Node<vec3>}
|
|
|
*/
|
|
|
-export const bitangentLocal = /*@__PURE__*/ varying( getBitangent( normalLocal.cross( tangentLocal ) ), 'v_bitangentLocal' ).normalize().toVar( 'bitangentLocal' );
|
|
|
+export const bitangentLocal = /*@__PURE__*/ getBitangent( normalLocal.cross( tangentLocal ), 'v_bitangentLocal' ).normalize().toVar( 'bitangentLocal' );
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the vertex bitangent in view space of the current rendered object.
|
|
|
*
|
|
|
* @tsl
|
|
|
- * @type {Node<vec4>}
|
|
|
+ * @type {Node<vec3>}
|
|
|
*/
|
|
|
-export const bitangentView = /*@__PURE__*/ varying( getBitangent( normalView.cross( tangentView ) ), 'v_bitangentView' ).normalize().toVar( 'bitangentView' );
|
|
|
+export const bitangentView = getBitangent( normalView.cross( tangentView ), 'v_bitangentView' ).normalize().toVar( 'bitangentView' );
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the vertex bitangent in world space of the current rendered object.
|
|
|
*
|
|
|
* @tsl
|
|
|
- * @type {Node<vec4>}
|
|
|
+ * @type {Node<vec3>}
|
|
|
*/
|
|
|
-export const bitangentWorld = /*@__PURE__*/ varying( getBitangent( normalWorld.cross( tangentWorld ) ), 'v_bitangentWorld' ).normalize().toVar( 'bitangentWorld' );
|
|
|
+export const bitangentWorld = /*@__PURE__*/ getBitangent( normalWorld.cross( tangentWorld ), 'v_bitangentWorld' ).normalize().toVar( 'bitangentWorld' );
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the transformed vertex bitangent in view space of the current rendered object.
|
|
|
*
|
|
|
* @tsl
|
|
|
- * @type {Node<vec4>}
|
|
|
+ * @type {Node<vec3>}
|
|
|
*/
|
|
|
-export const transformedBitangentView = /*@__PURE__*/ getBitangent( transformedNormalView.cross( transformedTangentView ) ).normalize().toVar( 'transformedBitangentView' );
|
|
|
+export const transformedBitangentView = /*@__PURE__*/ getBitangent( transformedNormalView.cross( transformedTangentView ), 'v_transformedBitangentView' ).normalize().toVar( 'transformedBitangentView' );
|
|
|
|
|
|
/**
|
|
|
* TSL object that represents the transformed vertex bitangent in world space of the current rendered object.
|