|
1 | 1 | import { varying } from '../core/VaryingNode.js';
|
| 2 | +import { Fn } from '../tsl/TSLCore.js'; |
2 | 3 | import { cameraViewMatrix } from './Camera.js';
|
3 | 4 | import { normalGeometry, normalLocal, normalView, normalWorld, transformedNormalView } from './Normal.js';
|
4 | 5 | import { tangentGeometry, tangentLocal, tangentView, tangentWorld, transformedTangentView } from './Tangent.js';
|
5 | 6 |
|
6 |
| -const getBitangent = ( crossNormalTangent ) => crossNormalTangent.mul( tangentGeometry.w ).xyz; |
| 7 | +/** |
| 8 | + * Returns the bitangent node and assigns it to a varying if the material is not flat shaded. |
| 9 | + * |
| 10 | + * @tsl |
| 11 | + * @private |
| 12 | + * @param {Node<vec3>} crossNormalTangent - The cross product of the normal and tangent vectors. |
| 13 | + * @param {string} varyingName - The name of the varying to assign the bitangent to. |
| 14 | + * @returns {Node<vec3>} The bitangent node. |
| 15 | + */ |
| 16 | +const getBitangent = /*@__PURE__*/ Fn( ( [ crossNormalTangent, varyingName ], builder ) => { |
| 17 | + |
| 18 | + let bitangent = crossNormalTangent.mul( tangentGeometry.w ).xyz; |
| 19 | + |
| 20 | + if ( builder.material.flatShading !== true ) { |
| 21 | + |
| 22 | + bitangent = varying( crossNormalTangent, varyingName ); |
| 23 | + |
| 24 | + } |
| 25 | + |
| 26 | + return bitangent; |
| 27 | + |
| 28 | +} ).once(); |
7 | 29 |
|
8 | 30 | /**
|
9 | 31 | * TSL object that represents the bitangent attribute of the current rendered object.
|
10 | 32 | *
|
11 | 33 | * @tsl
|
12 | 34 | * @type {Node<vec3>}
|
13 | 35 | */
|
14 |
| -export const bitangentGeometry = /*@__PURE__*/ varying( getBitangent( normalGeometry.cross( tangentGeometry ) ), 'v_bitangentGeometry' ).normalize().toVar( 'bitangentGeometry' ); |
| 36 | +export const bitangentGeometry = /*@__PURE__*/ getBitangent( normalGeometry.cross( tangentGeometry ), 'v_bitangentGeometry' ).normalize().toVar( 'bitangentGeometry' ); |
15 | 37 |
|
16 | 38 | /**
|
17 | 39 | * TSL object that represents the vertex bitangent in local space of the current rendered object.
|
18 | 40 | *
|
19 | 41 | * @tsl
|
20 | 42 | * @type {Node<vec3>}
|
21 | 43 | */
|
22 |
| -export const bitangentLocal = /*@__PURE__*/ varying( getBitangent( normalLocal.cross( tangentLocal ) ), 'v_bitangentLocal' ).normalize().toVar( 'bitangentLocal' ); |
| 44 | +export const bitangentLocal = /*@__PURE__*/ getBitangent( normalLocal.cross( tangentLocal ), 'v_bitangentLocal' ).normalize().toVar( 'bitangentLocal' ); |
23 | 45 |
|
24 | 46 | /**
|
25 | 47 | * TSL object that represents the vertex bitangent in view space of the current rendered object.
|
26 | 48 | *
|
27 | 49 | * @tsl
|
28 |
| - * @type {Node<vec4>} |
| 50 | + * @type {Node<vec3>} |
29 | 51 | */
|
30 |
| -export const bitangentView = /*@__PURE__*/ varying( getBitangent( normalView.cross( tangentView ) ), 'v_bitangentView' ).normalize().toVar( 'bitangentView' ); |
| 52 | +export const bitangentView = getBitangent( normalView.cross( tangentView ), 'v_bitangentView' ).normalize().toVar( 'bitangentView' ); |
31 | 53 |
|
32 | 54 | /**
|
33 | 55 | * TSL object that represents the vertex bitangent in world space of the current rendered object.
|
34 | 56 | *
|
35 | 57 | * @tsl
|
36 |
| - * @type {Node<vec4>} |
| 58 | + * @type {Node<vec3>} |
37 | 59 | */
|
38 |
| -export const bitangentWorld = /*@__PURE__*/ varying( getBitangent( normalWorld.cross( tangentWorld ) ), 'v_bitangentWorld' ).normalize().toVar( 'bitangentWorld' ); |
| 60 | +export const bitangentWorld = /*@__PURE__*/ getBitangent( normalWorld.cross( tangentWorld ), 'v_bitangentWorld' ).normalize().toVar( 'bitangentWorld' ); |
39 | 61 |
|
40 | 62 | /**
|
41 | 63 | * TSL object that represents the transformed vertex bitangent in view space of the current rendered object.
|
42 | 64 | *
|
43 | 65 | * @tsl
|
44 |
| - * @type {Node<vec4>} |
| 66 | + * @type {Node<vec3>} |
45 | 67 | */
|
46 |
| -export const transformedBitangentView = /*@__PURE__*/ getBitangent( transformedNormalView.cross( transformedTangentView ) ).normalize().toVar( 'transformedBitangentView' ); |
| 68 | +export const transformedBitangentView = /*@__PURE__*/ getBitangent( transformedNormalView.cross( transformedTangentView ), 'v_transformedBitangentView' ).normalize().toVar( 'transformedBitangentView' ); |
47 | 69 |
|
48 | 70 | /**
|
49 | 71 | * TSL object that represents the transformed vertex bitangent in world space of the current rendered object.
|
|
0 commit comments