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
1 change: 0 additions & 1 deletion src/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export { default as SetNode } from './utils/SetNode.js';
export { default as SplitNode } from './utils/SplitNode.js';
export { default as SpriteSheetUVNode } from './utils/SpriteSheetUVNode.js';
export { default as StorageArrayElementNode } from './utils/StorageArrayElementNode.js';
export { default as TriplanarTexturesNode } from './utils/TriplanarTexturesNode.js';
export { default as ReflectorNode } from './utils/ReflectorNode.js';
export { default as RTTNode } from './utils/RTTNode.js';
export { default as MemberNode } from './utils/MemberNode.js';
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export * from './utils/ViewportUtils.js';
export * from './utils/RotateNode.js';
export * from './utils/SpriteSheetUVNode.js';
export * from './utils/Timer.js';
export * from './utils/TriplanarTexturesNode.js';
export * from './utils/TriplanarTextures.js';
export * from './utils/ReflectorNode.js';
export * from './utils/RTTNode.js';
export * from './utils/PostProcessingUtils.js';
Expand Down
65 changes: 65 additions & 0 deletions src/nodes/utils/TriplanarTextures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { add } from '../math/OperatorNode.js';
import { normalLocal } from '../accessors/Normal.js';
import { positionLocal } from '../accessors/Position.js';
import { texture } from '../accessors/TextureNode.js';
import { float, vec3, Fn } from '../tsl/TSLBase.js';

/**
* TSL function for creating a triplanar textures node.
*
* Can be used for triplanar texture mapping.
*
* ```js
* material.colorNode = triplanarTexture( texture( diffuseMap ) );
* ```
*
* @tsl
* @function
* @param {Node} textureXNode - First texture node.
* @param {?Node} [textureYNode=null] - Second texture node. When not set, the shader will sample from `textureXNode` instead.
* @param {?Node} [textureZNode=null] - Third texture node. When not set, the shader will sample from `textureXNode` instead.
* @param {?Node<float>} [scaleNode=float(1)] - The scale node.
* @param {?Node<vec3>} [positionNode=positionLocal] - Vertex positions in local space.
* @param {?Node<vec3>} [normalNode=normalLocal] - Normals in local space.
* @returns {Node<vec4>}
*/
export const triplanarTextures = /*@__PURE__*/ Fn( ( [ textureXNode, textureYNode = null, textureZNode = null, scaleNode = float( 1 ), positionNode = positionLocal, normalNode = normalLocal ] ) => {

// Reference: 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 );

} );

/**
* TSL function for creating a triplanar textures node.
*
* @tsl
* @function
* @param {Node} textureXNode - First texture node.
* @param {?Node} [textureYNode=null] - Second texture node. When not set, the shader will sample from `textureXNode` instead.
* @param {?Node} [textureZNode=null] - Third texture node. When not set, the shader will sample from `textureXNode` instead.
* @param {?Node<float>} [scaleNode=float(1)] - The scale node.
* @param {?Node<vec3>} [positionNode=positionLocal] - Vertex positions in local space.
* @param {?Node<vec3>} [normalNode=normalLocal] - Normals in local space.
* @returns {Node<vec4>}
*/
export const triplanarTexture = ( ...params ) => triplanarTextures( ...params );
148 changes: 0 additions & 148 deletions src/nodes/utils/TriplanarTexturesNode.js

This file was deleted.