Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Three.TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ export const mx_transform_uv = TSL.mx_transform_uv;
export const mx_worley_noise_float = TSL.mx_worley_noise_float;
export const mx_worley_noise_vec2 = TSL.mx_worley_noise_vec2;
export const mx_worley_noise_vec3 = TSL.mx_worley_noise_vec3;
export const namespace = TSL.namespace;
export const negate = TSL.negate;
export const neutralToneMapping = TSL.neutralToneMapping;
export const nodeArray = TSL.nodeArray;
Expand Down Expand Up @@ -462,6 +461,7 @@ export const storageTexture = TSL.storageTexture;
export const string = TSL.string;
export const struct = TSL.struct;
export const sub = TSL.sub;
export const subBuild = TSL.subBuild;
export const subgroupIndex = TSL.subgroupIndex;
export const subgroupSize = TSL.subgroupSize;
export const tan = TSL.tan;
Expand Down
5 changes: 3 additions & 2 deletions src/materials/nodes/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { positionLocal, positionView } from '../../nodes/accessors/Position.js';
import { skinning } from '../../nodes/accessors/SkinningNode.js';
import { morphReference } from '../../nodes/accessors/MorphNode.js';
import { mix } from '../../nodes/math/MathNode.js';
import { namespace, float, vec3, vec4, bool } from '../../nodes/tsl/TSLBase.js';
import { float, vec3, vec4, bool } from '../../nodes/tsl/TSLBase.js';
import AONode from '../../nodes/lighting/AONode.js';
import { lightingContext } from '../../nodes/lighting/LightingContextNode.js';
import IrradianceNode from '../../nodes/lighting/IrradianceNode.js';
Expand All @@ -25,6 +25,7 @@ import getAlphaHashThreshold from '../../nodes/functions/material/getAlphaHashTh
import { modelViewMatrix } from '../../nodes/accessors/ModelNode.js';
import { vertexColor } from '../../nodes/accessors/VertexColorNode.js';
import { premultiplyAlpha } from '../../nodes/display/BlendModes.js';
import { subBuild } from '../../nodes/core/SubBuildNode.js';

/**
* Base class for all node materials.
Expand Down Expand Up @@ -768,7 +769,7 @@ class NodeMaterial extends Material {

if ( this.positionNode !== null ) {

positionLocal.assign( namespace( this.positionNode, 'POSITION' ) );
positionLocal.assign( subBuild( this.positionNode, 'POSITION', 'vec3' ) );

}

Expand Down
1 change: 1 addition & 0 deletions src/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export { default as StructNode } from './core/StructNode.js';
export { default as StructTypeNode } from './core/StructTypeNode.js';
export { default as OutputStructNode } from './core/OutputStructNode.js';
export { default as MRTNode } from './core/MRTNode.js';
export { default as SubBuildNode } from './core/SubBuildNode.js';

import * as NodeUtils from './core/NodeUtils.js';
export { NodeUtils };
Expand Down
14 changes: 7 additions & 7 deletions src/nodes/accessors/Position.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ export const positionPrevious = /*@__PURE__*/ positionGeometry.toVarying( 'posit
*/
export const positionWorld = /*@__PURE__*/ ( Fn( ( builder ) => {

return modelWorldMatrix.mul( positionLocal ).xyz.toVarying( builder.getNamespace( 'v_positionWorld' ) );
return modelWorldMatrix.mul( positionLocal ).xyz.toVarying( builder.getSubBuildProperty( 'v_positionWorld' ) );

}, 'vec3' ).once( 'POSITION' ) )();
}, 'vec3' ).once( [ 'POSITION' ] ) )();

/**
* TSL object that represents the position world direction of the current rendered object.
*
* @tsl
* @type {Node<vec3>}
*/
export const positionWorldDirection = /*@__PURE__*/ ( Fn( ( builder ) => {
export const positionWorldDirection = /*@__PURE__*/ ( Fn( () => {

const vertexPWD = positionLocal.transformDirection( modelWorldMatrix ).toVarying( builder.getNamespace( 'v_positionWorldDirection' ) );
const vertexPWD = positionLocal.transformDirection( modelWorldMatrix ).toVarying( 'v_positionWorldDirection' );

return vertexPWD.normalize().toVar( 'positionWorldDirection' );

}, 'vec3' ).once( 'POSITION' ) )();
}, 'vec3' ).once( [ 'POSITION' ] ) )();

/**
* TSL object that represents the vertex position in view space of the current rendered object.
Expand All @@ -61,9 +61,9 @@ export const positionWorldDirection = /*@__PURE__*/ ( Fn( ( builder ) => {
*/
export const positionView = /*@__PURE__*/ ( Fn( ( builder ) => {

return builder.context.setupPositionView().toVarying( builder.getNamespace( 'v_positionView' ) );
return builder.context.setupPositionView().toVarying( 'v_positionView' );

}, 'vec3' ).once( 'POSITION' ) )();
}, 'vec3' ).once( [ 'POSITION' ] ) )();

/**
* TSL object that represents the position view direction of the current rendered object.
Expand Down
14 changes: 0 additions & 14 deletions src/nodes/core/CacheNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,4 @@ export default CacheNode;
*/
export const cache = ( node, parent ) => nodeObject( new CacheNode( nodeObject( node ), parent ) );

/**
* Assigns a namespace to the given node by updating its context.
*
* Important for TSL functions that use `.once( namespace )` to ensure that the namespace will run twice,
* once when the node is build in the specific namespace and once when the node is built in the others namespace.
*
* This is useful for nodes like `positionWorld` that need to be re-updated if used in `material.positionNode` and outside of it in the same material.
*
* @param {Object} node - The node to which the namespace will be assigned.
* @param {string} namespace - The namespace to be assigned to the node.
* @returns {Object} The updated node with the new namespace in its context.
*/
export const namespace = ( node, namespace ) => node.context( { namespace } );

addMethodChaining( 'cache', cache );
2 changes: 1 addition & 1 deletion src/nodes/core/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ class Node extends EventDispatcher {

console.warn( 'THREE.Node: Recursion detected.', this );

result = '';
result = '/* Recursion detected. */';

}

Expand Down
Loading