Skip to content

Commit

Permalink
TSL: UVNode - Move to TSL approach (#28511)
Browse files Browse the repository at this point in the history
* Normal/Tangent/Bitangent revisions

* UVNode: Move to TSL approach

* fix type
  • Loading branch information
sunag authored May 28, 2024
1 parent 66e1aa2 commit e811420
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 61 deletions.
2 changes: 1 addition & 1 deletion examples/jsm/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export * from './accessors/TangentNode.js';
export { default as TextureNode, texture, textureLoad, /*textureLevel,*/ sampler } from './accessors/TextureNode.js';
export { default as TextureStoreNode, textureStore } from './accessors/TextureStoreNode.js';
export { default as Texture3DNode, texture3D } from './accessors/Texture3DNode.js';
export { default as UVNode, uv } from './accessors/UVNode.js';
export * from './accessors/UVNode.js';
export { default as UserDataNode, userData } from './accessors/UserDataNode.js';

// display
Expand Down
12 changes: 6 additions & 6 deletions examples/jsm/nodes/accessors/BitangentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { tangentGeometry, tangentLocal, tangentView, tangentWorld, transformedTa

const getBitangent = ( crossNormalTangent ) => crossNormalTangent.mul( tangentGeometry.w ).xyz;

export const bitangentGeometry = varying( getBitangent( normalGeometry.cross( tangentGeometry ) ) ).normalize();
export const bitangentLocal = varying( getBitangent( normalLocal.cross( tangentLocal ) ) ).normalize();
export const bitangentView = varying( getBitangent( normalView.cross( tangentView ) ) ).normalize();
export const bitangentWorld = varying( getBitangent( normalWorld.cross( tangentWorld ) ) ).normalize();
export const transformedBitangentView = getBitangent( transformedNormalView.cross( transformedTangentView ) ).normalize();
export const transformedBitangentWorld = transformedBitangentView.transformDirection( cameraViewMatrix ).normalize();
export const bitangentGeometry = /*#__PURE__*/ varying( getBitangent( normalGeometry.cross( tangentGeometry ) ), 'v_bitangentGeometry' ).normalize().toVar( 'bitangentGeometry' );
export const bitangentLocal = /*#__PURE__*/ varying( getBitangent( normalLocal.cross( tangentLocal ) ), 'v_bitangentLocal' ).normalize().toVar( 'bitangentLocal' );
export const bitangentView = /*#__PURE__*/ varying( getBitangent( normalView.cross( tangentView ) ), 'v_bitangentView' ).normalize().toVar( 'bitangentView' );
export const bitangentWorld = /*#__PURE__*/ varying( getBitangent( normalWorld.cross( tangentWorld ) ), 'v_bitangentWorld' ).normalize().toVar( 'bitangentWorld' );
export const transformedBitangentView = /*#__PURE__*/ getBitangent( transformedNormalView.cross( transformedTangentView ) ).normalize().toVar( 'transformedBitangentView' );
export const transformedBitangentWorld = /*#__PURE__*/ transformedBitangentView.transformDirection( cameraViewMatrix ).normalize().toVar( 'transformedBitangentWorld' );
8 changes: 4 additions & 4 deletions examples/jsm/nodes/accessors/NormalNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { modelNormalMatrix } from './ModelNode.js';
import { vec3 } from '../shadernode/ShaderNode.js';

export const normalGeometry = /*#__PURE__*/ attribute( 'normal', 'vec3', vec3( 0, 1, 0 ) );
export const normalLocal = /*#__PURE__*/ varying( normalGeometry ).toVar( 'normalLocal' );
export const normalView = /*#__PURE__*/ varying( modelNormalMatrix.mul( normalLocal ), 'normalView' ).normalize();
export const normalWorld = /*#__PURE__*/ varying( normalView.transformDirection( cameraViewMatrix ), 'normalWorld' ).normalize();
export const normalLocal = /*#__PURE__*/ normalGeometry.toVar( 'normalLocal' );
export const normalView = /*#__PURE__*/ varying( modelNormalMatrix.mul( normalLocal ), 'v_normalView' ).normalize().toVar( 'normalView' );
export const normalWorld = /*#__PURE__*/ varying( normalView.transformDirection( cameraViewMatrix ), 'v_normalWorld' ).normalize().toVar( 'transformedNormalWorld' );
export const transformedNormalView = /*#__PURE__*/ property( 'vec3', 'transformedNormalView' );
export const transformedNormalWorld = /*#__PURE__*/ transformedNormalView.transformDirection( cameraViewMatrix ).normalize();
export const transformedNormalWorld = /*#__PURE__*/ transformedNormalView.transformDirection( cameraViewMatrix ).normalize().toVar( 'transformedNormalWorld' );
export const transformedClearcoatNormalView = /*#__PURE__*/ property( 'vec3', 'transformedClearcoatNormalView' );
8 changes: 4 additions & 4 deletions examples/jsm/nodes/accessors/TangentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const tangentGeometry = /*#__PURE__*/ tslFn( ( stack, builder ) => {

} )();

export const tangentLocal = /*#__PURE__*/ varying( tangentGeometry.xyz, 'tangentLocal' );
export const tangentView = /*#__PURE__*/ varying( modelViewMatrix.mul( vec4( tangentLocal, 0 ) ).xyz, 'tangentView' ).normalize();
export const tangentWorld = /*#__PURE__*/ varying( tangentView.transformDirection( cameraViewMatrix ), 'tangentWorld' ).normalize();
export const tangentLocal = /*#__PURE__*/ tangentGeometry.xyz.toVar( 'tangentLocal' );
export const tangentView = /*#__PURE__*/ varying( modelViewMatrix.mul( vec4( tangentLocal, 0 ) ).xyz, 'v_tangentView' ).normalize().toVar( 'tangentView' );
export const tangentWorld = /*#__PURE__*/ varying( tangentView.transformDirection( cameraViewMatrix ), 'v_tangentWorld' ).normalize().toVar( 'tangentWorld' );
export const transformedTangentView = /*#__PURE__*/ tangentView.toVar( 'transformedTangentView' );
export const transformedTangentWorld = /*#__PURE__*/ transformedTangentView.transformDirection( cameraViewMatrix ).normalize();
export const transformedTangentWorld = /*#__PURE__*/ transformedTangentView.transformDirection( cameraViewMatrix ).normalize().toVar( 'transformedTangentWorld' );
48 changes: 2 additions & 46 deletions examples/jsm/nodes/accessors/UVNode.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,3 @@
import { addNodeClass } from '../core/Node.js';
import AttributeNode from '../core/AttributeNode.js';
import { nodeObject } from '../shadernode/ShaderNode.js';
import { attribute } from '../core/AttributeNode.js';

class UVNode extends AttributeNode {

constructor( index = 0 ) {

super( null, 'vec2' );

this.isUVNode = true;

this.index = index;

}

getAttributeName( /*builder*/ ) {

const index = this.index;

return 'uv' + ( index > 0 ? index : '' );

}

serialize( data ) {

super.serialize( data );

data.index = this.index;

}

deserialize( data ) {

super.deserialize( data );

this.index = data.index;

}

}

export default UVNode;

export const uv = ( ...params ) => nodeObject( new UVNode( ...params ) );

addNodeClass( 'UVNode', UVNode );
export const uv = ( index ) => attribute( 'uv' + ( index > 0 ? index : '' ), 'vec2' );

0 comments on commit e811420

Please sign in to comment.