Initial commit

This commit is contained in:
ChKendel
2026-01-31 21:50:25 +01:00
commit c65f983229
1088 changed files with 452910 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import Node, { addNodeClass } from '../core/Node.js';
class ArrayElementNode extends Node { // @TODO: If extending from TempNode it breaks webgpu_compute
constructor( node, indexNode ) {
super();
this.node = node;
this.indexNode = indexNode;
this.isArrayElementNode = true;
}
getNodeType( builder ) {
return this.node.getNodeType( builder );
}
generate( builder ) {
const nodeSnippet = this.node.build( builder );
const indexSnippet = this.indexNode.build( builder, 'uint' );
return `${nodeSnippet}[ ${indexSnippet} ]`;
}
}
export default ArrayElementNode;
addNodeClass( 'ArrayElementNode', ArrayElementNode );

View File

@@ -0,0 +1,65 @@
import Node, { addNodeClass } from '../core/Node.js';
class ConvertNode extends Node {
constructor( node, convertTo ) {
super();
this.node = node;
this.convertTo = convertTo;
}
getNodeType( builder ) {
const requestType = this.node.getNodeType( builder );
let convertTo = null;
for ( const overloadingType of this.convertTo.split( '|' ) ) {
if ( convertTo === null || builder.getTypeLength( requestType ) === builder.getTypeLength( overloadingType ) ) {
convertTo = overloadingType;
}
}
return convertTo;
}
serialize( data ) {
super.serialize( data );
data.convertTo = this.convertTo;
}
deserialize( data ) {
super.deserialize( data );
this.convertTo = data.convertTo;
}
generate( builder, output ) {
const node = this.node;
const type = this.getNodeType( builder );
const snippet = node.build( builder, type );
return builder.format( snippet, type, output );
}
}
export default ConvertNode;
addNodeClass( 'ConvertNode', ConvertNode );

View File

@@ -0,0 +1,27 @@
import CondNode from '../math/CondNode.js';
import { expression } from '../code/ExpressionNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
let discardExpression;
class DiscardNode extends CondNode {
constructor( condNode ) {
discardExpression = discardExpression || expression( 'discard' );
super( condNode, discardExpression );
}
}
export default DiscardNode;
export const inlineDiscard = nodeProxy( DiscardNode );
export const discard = ( condNode ) => inlineDiscard( condNode ).append();
addNodeElement( 'discard', discard ); // @TODO: Check... this cause a little confusing using in chaining
addNodeClass( 'DiscardNode', DiscardNode );

View File

@@ -0,0 +1,33 @@
import TempNode from '../core/TempNode.js';
import { positionWorldDirection } from '../accessors/PositionNode.js';
import { nodeProxy, vec2 } from '../shadernode/ShaderNode.js';
import { addNodeClass } from '../core/Node.js';
class EquirectUVNode extends TempNode {
constructor( dirNode = positionWorldDirection ) {
super( 'vec2' );
this.dirNode = dirNode;
}
setup() {
const dir = this.dirNode;
const u = dir.z.atan2( dir.x ).mul( 1 / ( Math.PI * 2 ) ).add( 0.5 );
const v = dir.y.negate().clamp( - 1.0, 1.0 ).asin().mul( 1 / Math.PI ).add( 0.5 ); // @TODO: The use of negate() here could be an NDC issue.
return vec2( u, v );
}
}
export default EquirectUVNode;
export const equirectUV = nodeProxy( EquirectUVNode );
addNodeClass( 'EquirectUVNode', EquirectUVNode );

View File

@@ -0,0 +1,61 @@
import { addNodeClass } from '../core/Node.js';
import TempNode from '../core/TempNode.js';
class JoinNode extends TempNode {
constructor( nodes = [], nodeType = null ) {
super( nodeType );
this.nodes = nodes;
}
getNodeType( builder ) {
if ( this.nodeType !== null ) {
return builder.getVectorType( this.nodeType );
}
return builder.getTypeFromLength( this.nodes.reduce( ( count, cur ) => count + builder.getTypeLength( cur.getNodeType( builder ) ), 0 ) );
}
generate( builder, output ) {
const type = this.getNodeType( builder );
const nodes = this.nodes;
const primitiveType = builder.getPrimitiveType( type );
const snippetValues = [];
for ( const input of nodes ) {
let inputSnippet = input.build( builder );
const inputPrimitiveType = builder.getPrimitiveType( input.getNodeType( builder ) );
if ( inputPrimitiveType !== primitiveType ) {
inputSnippet = builder.format( inputSnippet, inputPrimitiveType, primitiveType );
}
snippetValues.push( inputSnippet );
}
const snippet = `${ builder.getType( type ) }( ${ snippetValues.join( ', ' ) } )`;
return builder.format( snippet, type, output );
}
}
export default JoinNode;
addNodeClass( 'JoinNode', JoinNode );

198
node_modules/three/examples/jsm/nodes/utils/LoopNode.js generated vendored Normal file
View File

@@ -0,0 +1,198 @@
import Node, { addNodeClass } from '../core/Node.js';
import { expression } from '../code/ExpressionNode.js';
import { bypass } from '../core/BypassNode.js';
import { context } from '../core/ContextNode.js';
import { addNodeElement, nodeObject, nodeArray } from '../shadernode/ShaderNode.js';
class LoopNode extends Node {
constructor( params = [] ) {
super();
this.params = params;
}
getVarName( index ) {
return String.fromCharCode( 'i'.charCodeAt() + index );
}
getProperties( builder ) {
const properties = builder.getNodeProperties( this );
if ( properties.stackNode !== undefined ) return properties;
//
const inputs = {};
for ( let i = 0, l = this.params.length - 1; i < l; i ++ ) {
const param = this.params[ i ];
const name = ( param.isNode !== true && param.name ) || this.getVarName( i );
const type = ( param.isNode !== true && param.type ) || 'int';
inputs[ name ] = expression( name, type );
}
properties.returnsNode = this.params[ this.params.length - 1 ]( inputs, builder.addStack(), builder );
properties.stackNode = builder.removeStack();
return properties;
}
getNodeType( builder ) {
const { returnsNode } = this.getProperties( builder );
return returnsNode ? returnsNode.getNodeType( builder ) : 'void';
}
setup( builder ) {
// setup properties
this.getProperties( builder );
}
generate( builder ) {
const properties = this.getProperties( builder );
const contextData = { tempWrite: false };
const params = this.params;
const stackNode = properties.stackNode;
for ( let i = 0, l = params.length - 1; i < l; i ++ ) {
const param = params[ i ];
let start = null, end = null, name = null, type = null, condition = null, update = null;
if ( param.isNode ) {
type = 'int';
name = this.getVarName( i );
start = '0';
end = param.build( builder, type );
condition = '<';
} else {
type = param.type || 'int';
name = param.name || this.getVarName( i );
start = param.start;
end = param.end;
condition = param.condition;
update = param.update;
if ( typeof start === 'number' ) start = start.toString();
else if ( start && start.isNode ) start = start.build( builder, type );
if ( typeof end === 'number' ) end = end.toString();
else if ( end && end.isNode ) end = end.build( builder, type );
if ( start !== undefined && end === undefined ) {
start = start + ' - 1';
end = '0';
condition = '>=';
} else if ( end !== undefined && start === undefined ) {
start = '0';
condition = '<';
}
if ( condition === undefined ) {
if ( Number( start ) > Number( end ) ) {
condition = '>=';
} else {
condition = '<';
}
}
}
const internalParam = { start, end, condition };
//
const startSnippet = internalParam.start;
const endSnippet = internalParam.end;
let declarationSnippet = '';
let conditionalSnippet = '';
let updateSnippet = '';
if ( ! update ) {
if ( type === 'int' ) {
if ( condition.includes( '<' ) ) update = '++';
else update = '--';
} else {
if ( condition.includes( '<' ) ) update = '+= 1';
else update = '-= 1';
}
}
declarationSnippet += builder.getVar( type, name ) + ' = ' + startSnippet;
conditionalSnippet += name + ' ' + condition + ' ' + endSnippet;
updateSnippet += name + ' ' + update;
const forSnippet = `for ( ${ declarationSnippet }; ${ conditionalSnippet }; ${ updateSnippet } )`;
builder.addFlowCode( ( i === 0 ? '\n' : '' ) + builder.tab + forSnippet + ' {\n\n' ).addFlowTab();
}
const stackSnippet = context( stackNode, contextData ).build( builder, 'void' );
const returnsSnippet = properties.returnsNode ? properties.returnsNode.build( builder ) : '';
builder.removeFlowTab().addFlowCode( '\n' + builder.tab + stackSnippet );
for ( let i = 0, l = this.params.length - 1; i < l; i ++ ) {
builder.addFlowCode( ( i === 0 ? '' : builder.tab ) + '}\n\n' ).removeFlowTab();
}
builder.addFlowTab();
return returnsSnippet;
}
}
export default LoopNode;
export const loop = ( ...params ) => nodeObject( new LoopNode( nodeArray( params, 'int' ) ) ).append();
addNodeElement( 'loop', ( returns, ...params ) => bypass( returns, loop( ...params ) ) );
addNodeClass( 'LoopNode', LoopNode );

View File

@@ -0,0 +1,30 @@
import TempNode from '../core/TempNode.js';
import { transformedNormalView } from '../accessors/NormalNode.js';
import { positionViewDirection } from '../accessors/PositionNode.js';
import { nodeImmutable, vec2, vec3 } from '../shadernode/ShaderNode.js';
import { addNodeClass } from '../core/Node.js';
class MatcapUVNode extends TempNode {
constructor() {
super( 'vec2' );
}
setup() {
const x = vec3( positionViewDirection.z, 0, positionViewDirection.x.negate() ).normalize();
const y = positionViewDirection.cross( x );
return vec2( x.dot( transformedNormalView ), y.dot( transformedNormalView ) ).mul( 0.495 ).add( 0.5 );
}
}
export default MatcapUVNode;
export const matcapUV = nodeImmutable( MatcapUVNode );
addNodeClass( 'MatcapUVNode', MatcapUVNode );

View File

@@ -0,0 +1,46 @@
import UniformNode from '../core/UniformNode.js';
import { NodeUpdateType } from '../core/constants.js';
import { nodeProxy } from '../shadernode/ShaderNode.js';
import { addNodeClass } from '../core/Node.js';
class MaxMipLevelNode extends UniformNode {
constructor( textureNode ) {
super( 0 );
this.textureNode = textureNode;
this.updateType = NodeUpdateType.FRAME;
}
get texture() {
return this.textureNode.value;
}
update() {
const texture = this.texture;
const images = texture.images;
const image = ( images && images.length > 0 ) ? ( ( images[ 0 ] && images[ 0 ].image ) || images[ 0 ] ) : texture.image;
if ( image && image.width !== undefined ) {
const { width, height } = image;
this.value = Math.log2( Math.max( width, height ) );
}
}
}
export default MaxMipLevelNode;
export const maxMipLevel = nodeProxy( MaxMipLevelNode );
addNodeClass( 'MaxMipLevelNode', MaxMipLevelNode );

81
node_modules/three/examples/jsm/nodes/utils/OscNode.js generated vendored Normal file
View File

@@ -0,0 +1,81 @@
import Node, { addNodeClass } from '../core/Node.js';
import { timerLocal } from './TimerNode.js';
import { nodeObject, nodeProxy } from '../shadernode/ShaderNode.js';
class OscNode extends Node {
constructor( method = OscNode.SINE, timeNode = timerLocal() ) {
super();
this.method = method;
this.timeNode = timeNode;
}
getNodeType( builder ) {
return this.timeNode.getNodeType( builder );
}
setup() {
const method = this.method;
const timeNode = nodeObject( this.timeNode );
let outputNode = null;
if ( method === OscNode.SINE ) {
outputNode = timeNode.add( 0.75 ).mul( Math.PI * 2 ).sin().mul( 0.5 ).add( 0.5 );
} else if ( method === OscNode.SQUARE ) {
outputNode = timeNode.fract().round();
} else if ( method === OscNode.TRIANGLE ) {
outputNode = timeNode.add( 0.5 ).fract().mul( 2 ).sub( 1 ).abs();
} else if ( method === OscNode.SAWTOOTH ) {
outputNode = timeNode.fract();
}
return outputNode;
}
serialize( data ) {
super.serialize( data );
data.method = this.method;
}
deserialize( data ) {
super.deserialize( data );
this.method = data.method;
}
}
OscNode.SINE = 'sine';
OscNode.SQUARE = 'square';
OscNode.TRIANGLE = 'triangle';
OscNode.SAWTOOTH = 'sawtooth';
export default OscNode;
export const oscSine = nodeProxy( OscNode, OscNode.SINE );
export const oscSquare = nodeProxy( OscNode, OscNode.SQUARE );
export const oscTriangle = nodeProxy( OscNode, OscNode.TRIANGLE );
export const oscSawtooth = nodeProxy( OscNode, OscNode.SAWTOOTH );
addNodeClass( 'OscNode', OscNode );

View File

@@ -0,0 +1,55 @@
import TempNode from '../core/TempNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
class PackingNode extends TempNode {
constructor( scope, node ) {
super();
this.scope = scope;
this.node = node;
}
getNodeType( builder ) {
return this.node.getNodeType( builder );
}
setup() {
const { scope, node } = this;
let result = null;
if ( scope === PackingNode.DIRECTION_TO_COLOR ) {
result = node.mul( 0.5 ).add( 0.5 );
} else if ( scope === PackingNode.COLOR_TO_DIRECTION ) {
result = node.mul( 2.0 ).sub( 1 );
}
return result;
}
}
PackingNode.DIRECTION_TO_COLOR = 'directionToColor';
PackingNode.COLOR_TO_DIRECTION = 'colorToDirection';
export default PackingNode;
export const directionToColor = nodeProxy( PackingNode, PackingNode.DIRECTION_TO_COLOR );
export const colorToDirection = nodeProxy( PackingNode, PackingNode.COLOR_TO_DIRECTION );
addNodeElement( 'directionToColor', directionToColor );
addNodeElement( 'colorToDirection', colorToDirection );
addNodeClass( 'PackingNode', PackingNode );

View File

@@ -0,0 +1,42 @@
import Node, { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
class RemapNode extends Node {
constructor( node, inLowNode, inHighNode, outLowNode, outHighNode ) {
super();
this.node = node;
this.inLowNode = inLowNode;
this.inHighNode = inHighNode;
this.outLowNode = outLowNode;
this.outHighNode = outHighNode;
this.doClamp = true;
}
setup() {
const { node, inLowNode, inHighNode, outLowNode, outHighNode, doClamp } = this;
let t = node.sub( inLowNode ).div( inHighNode.sub( inLowNode ) );
if ( doClamp === true ) t = t.clamp();
return t.mul( outHighNode.sub( outLowNode ) ).add( outLowNode );
}
}
export default RemapNode;
export const remap = nodeProxy( RemapNode, null, null, { doClamp: false } );
export const remapClamp = nodeProxy( RemapNode );
addNodeElement( 'remap', remap );
addNodeElement( 'remapClamp', remapClamp );
addNodeClass( 'RemapNode', RemapNode );

View File

@@ -0,0 +1,43 @@
import TempNode from '../core/TempNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeProxy, vec2 } from '../shadernode/ShaderNode.js';
class RotateUVNode extends TempNode {
constructor( uvNode, rotationNode, centerNode = vec2( 0.5 ) ) {
super( 'vec2' );
this.uvNode = uvNode;
this.rotationNode = rotationNode;
this.centerNode = centerNode;
}
setup() {
const { uvNode, rotationNode, centerNode } = this;
const cosAngle = rotationNode.cos();
const sinAngle = rotationNode.sin();
const vector = uvNode.sub( centerNode );
const rotatedVector = vec2( // @TODO: Maybe we can create mat2 and write something like rotationMatrix.mul( vector )?
vec2( cosAngle, sinAngle ).dot( vector ),
vec2( sinAngle.negate(), cosAngle ).dot( vector )
);
return rotatedVector.add( centerNode );
}
}
export default RotateUVNode;
export const rotateUV = nodeProxy( RotateUVNode );
addNodeElement( 'rotateUV', rotateUV );
addNodeClass( 'RotateUVNode', RotateUVNode );

62
node_modules/three/examples/jsm/nodes/utils/SetNode.js generated vendored Normal file
View File

@@ -0,0 +1,62 @@
import { addNodeClass } from '../core/Node.js';
import TempNode from '../core/TempNode.js';
import { vectorComponents } from '../core/constants.js';
class SetNode extends TempNode {
constructor( sourceNode, components, targetNode ) {
super();
this.sourceNode = sourceNode;
this.components = components;
this.targetNode = targetNode;
}
getNodeType( builder ) {
return this.sourceNode.getNodeType( builder );
}
generate( builder ) {
const { sourceNode, components, targetNode } = this;
const sourceType = this.getNodeType( builder );
const targetType = builder.getTypeFromLength( components.length );
const targetSnippet = targetNode.build( builder, targetType );
const sourceSnippet = sourceNode.build( builder, sourceType );
const length = builder.getTypeLength( sourceType );
const snippetValues = [];
for ( let i = 0; i < length; i ++ ) {
const component = vectorComponents[ i ];
if ( component === components[ 0 ] ) {
snippetValues.push( targetSnippet );
i += components.length - 1;
} else {
snippetValues.push( sourceSnippet + '.' + component );
}
}
return `${ builder.getType( sourceType ) }( ${ snippetValues.join( ', ' ) } )`;
}
}
export default SetNode;
addNodeClass( 'SetNode', SetNode );

View File

@@ -0,0 +1,37 @@
import Node, { addNodeClass } from '../core/Node.js';
import { maxMipLevel } from './MaxMipLevelNode.js';
import { nodeProxy } from '../shadernode/ShaderNode.js';
class SpecularMIPLevelNode extends Node {
constructor( textureNode, roughnessNode = null ) {
super( 'float' );
this.textureNode = textureNode;
this.roughnessNode = roughnessNode;
}
setup() {
const { textureNode, roughnessNode } = this;
// taken from here: http://casual-effects.blogspot.ca/2011/08/plausible-environment-lighting-in-two.html
const maxMIPLevelScalar = maxMipLevel( textureNode );
const sigma = roughnessNode.mul( roughnessNode ).mul( Math.PI ).div( roughnessNode.add( 1.0 ) );
const desiredMIPLevel = maxMIPLevelScalar.add( sigma.log2() );
return desiredMIPLevel.clamp( 0.0, maxMIPLevelScalar );
}
}
export default SpecularMIPLevelNode;
export const specularMIPLevel = nodeProxy( SpecularMIPLevelNode );
addNodeClass( 'SpecularMIPLevelNode', SpecularMIPLevelNode );

View File

@@ -0,0 +1,106 @@
import Node, { addNodeClass } from '../core/Node.js';
import { vectorComponents } from '../core/constants.js';
const stringVectorComponents = vectorComponents.join( '' );
class SplitNode extends Node {
constructor( node, components = 'x' ) {
super();
this.node = node;
this.components = components;
this.isSplitNode = true;
}
getVectorLength() {
let vectorLength = this.components.length;
for ( const c of this.components ) {
vectorLength = Math.max( vectorComponents.indexOf( c ) + 1, vectorLength );
}
return vectorLength;
}
getNodeType( builder ) {
return builder.getTypeFromLength( this.components.length );
}
generate( builder, output ) {
const node = this.node;
const nodeTypeLength = builder.getTypeLength( node.getNodeType( builder ) );
let snippet = null;
if ( nodeTypeLength > 1 ) {
let type = null;
const componentsLength = this.getVectorLength();
if ( componentsLength >= nodeTypeLength ) {
// needed expand the input node
type = builder.getTypeFromLength( this.getVectorLength() );
}
const nodeSnippet = node.build( builder, type );
if ( this.components.length === nodeTypeLength && this.components === stringVectorComponents.slice( 0, this.components.length ) ) {
// unnecessary swizzle
snippet = builder.format( nodeSnippet, type, output );
} else {
snippet = builder.format( `${nodeSnippet}.${this.components}`, this.getNodeType( builder ), output );
}
} else {
// ignore .components if .node returns float/integer
snippet = node.build( builder, output );
}
return snippet;
}
serialize( data ) {
super.serialize( data );
data.components = this.components;
}
deserialize( data ) {
super.deserialize( data );
this.components = data.components;
}
}
export default SplitNode;
addNodeClass( 'SplitNode', SplitNode );

View File

@@ -0,0 +1,41 @@
import Node, { addNodeClass } from '../core/Node.js';
import { uv } from '../accessors/UVNode.js';
import { nodeProxy, float, vec2 } from '../shadernode/ShaderNode.js';
class SpriteSheetUVNode extends Node {
constructor( countNode, uvNode = uv(), frameNode = float( 0 ) ) {
super( 'vec2' );
this.countNode = countNode;
this.uvNode = uvNode;
this.frameNode = frameNode;
}
setup() {
const { frameNode, uvNode, countNode } = this;
const { width, height } = countNode;
const frameNum = frameNode.mod( width.mul( height ) ).floor();
const column = frameNum.mod( width );
const row = height.sub( frameNum.add( 1 ).div( width ).ceil() );
const scale = countNode.reciprocal();
const uvFrameOffset = vec2( column, row );
return uvNode.add( uvFrameOffset ).mul( scale );
}
}
export default SpriteSheetUVNode;
export const spritesheetUV = nodeProxy( SpriteSheetUVNode );
addNodeClass( 'SpriteSheetUVNode', SpriteSheetUVNode );

View File

@@ -0,0 +1,94 @@
import UniformNode from '../core/UniformNode.js';
import { NodeUpdateType } from '../core/constants.js';
import { nodeObject, nodeImmutable } from '../shadernode/ShaderNode.js';
import { addNodeClass } from '../core/Node.js';
class TimerNode extends UniformNode {
constructor( scope = TimerNode.LOCAL, scale = 1, value = 0 ) {
super( value );
this.scope = scope;
this.scale = scale;
this.updateType = NodeUpdateType.FRAME;
}
/*
@TODO:
getNodeType( builder ) {
const scope = this.scope;
if ( scope === TimerNode.FRAME ) {
return 'uint';
}
return 'float';
}
*/
update( frame ) {
const scope = this.scope;
const scale = this.scale;
if ( scope === TimerNode.LOCAL ) {
this.value += frame.deltaTime * scale;
} else if ( scope === TimerNode.DELTA ) {
this.value = frame.deltaTime * scale;
} else if ( scope === TimerNode.FRAME ) {
this.value = frame.frameId;
} else {
// global
this.value = frame.time * scale;
}
}
serialize( data ) {
super.serialize( data );
data.scope = this.scope;
data.scale = this.scale;
}
deserialize( data ) {
super.deserialize( data );
this.scope = data.scope;
this.scale = data.scale;
}
}
TimerNode.LOCAL = 'local';
TimerNode.GLOBAL = 'global';
TimerNode.DELTA = 'delta';
TimerNode.FRAME = 'frame';
export default TimerNode;
// @TODO: add support to use node in timeScale
export const timerLocal = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.LOCAL, timeScale, value ) );
export const timerGlobal = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.GLOBAL, timeScale, value ) );
export const timerDelta = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.DELTA, timeScale, value ) );
export const frameId = nodeImmutable( TimerNode, TimerNode.FRAME ).uint();
addNodeClass( 'TimerNode', TimerNode );

View File

@@ -0,0 +1,62 @@
import Node, { addNodeClass } from '../core/Node.js';
import { add } from '../math/OperatorNode.js';
import { normalWorld } from '../accessors/NormalNode.js';
import { positionWorld } from '../accessors/PositionNode.js';
import { texture } from '../accessors/TextureNode.js';
import { addNodeElement, nodeProxy, float, vec3 } from '../shadernode/ShaderNode.js';
class TriplanarTexturesNode extends Node {
constructor( textureXNode, textureYNode = null, textureZNode = null, scaleNode = float( 1 ), positionNode = positionWorld, normalNode = normalWorld ) {
super( 'vec4' );
this.textureXNode = textureXNode;
this.textureYNode = textureYNode;
this.textureZNode = textureZNode;
this.scaleNode = scaleNode;
this.positionNode = positionNode;
this.normalNode = normalNode;
}
setup() {
const { textureXNode, textureYNode, textureZNode, scaleNode, positionNode, normalNode } = this;
// Ref: https://github.com/keijiro/StandardTriplanar
// Blending factor of triplanar mapping
let bf = normalNode.abs().normalize();
bf = bf.div( bf.dot( vec3( 1.0 ) ) );
// Triplanar mapping
const tx = positionNode.yz.mul( scaleNode );
const ty = positionNode.zx.mul( scaleNode );
const tz = positionNode.xy.mul( scaleNode );
// Base color
const textureX = textureXNode.value;
const textureY = textureYNode !== null ? textureYNode.value : textureX;
const textureZ = textureZNode !== null ? textureZNode.value : textureX;
const cx = texture( textureX, tx ).mul( bf.x );
const cy = texture( textureY, ty ).mul( bf.y );
const cz = texture( textureZ, tz ).mul( bf.z );
return add( cx, cy, cz );
}
}
export default TriplanarTexturesNode;
export const triplanarTextures = nodeProxy( TriplanarTexturesNode );
export const triplanarTexture = ( ...params ) => triplanarTextures( ...params );
addNodeElement( 'triplanarTexture', triplanarTexture );
addNodeClass( 'TriplanarTexturesNode', TriplanarTexturesNode );