Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[pull] dev from mrdoob:dev #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 20, 2025
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/materials/nodes/MeshMatcapNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { materialReference } from '../../nodes/accessors/MaterialReferenceNode.j
import { diffuseColor } from '../../nodes/core/PropertyNode.js';
import { vec3 } from '../../nodes/tsl/TSLBase.js';
import { mix } from '../../nodes/math/MathNode.js';
import { matcapUV } from '../../nodes/utils/MatcapUVNode.js';
import { matcapUV } from '../../nodes/utils/MatcapUV.js';

import { MeshMatcapMaterial } from '../MeshMatcapMaterial.js';

Expand Down
3 changes: 0 additions & 3 deletions src/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,16 @@ export { NodeUtils };
// utils
export { default as ArrayElementNode } from './utils/ArrayElementNode.js';
export { default as ConvertNode } from './utils/ConvertNode.js';
export { default as EquirectUVNode } from './utils/EquirectUVNode.js';
export { default as FunctionOverloadingNode } from './utils/FunctionOverloadingNode.js';
export { default as JoinNode } from './utils/JoinNode.js';
export { default as LoopNode } from './utils/LoopNode.js';
export { default as MatcapUVNode } from './utils/MatcapUVNode.js';
export { default as MaxMipLevelNode } from './utils/MaxMipLevelNode.js';
export { default as RemapNode } from './utils/RemapNode.js';
export { default as RotateNode } from './utils/RotateNode.js';
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
6 changes: 3 additions & 3 deletions src/nodes/TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export * from './math/MathUtils.js';
export * from './math/TriNoise3D.js';

// utils
export * from './utils/EquirectUVNode.js';
export * from './utils/EquirectUV.js';
export * from './utils/FunctionOverloadingNode.js';
export * from './utils/LoopNode.js';
export * from './utils/MatcapUVNode.js';
export * from './utils/MatcapUV.js';
export * from './utils/MaxMipLevelNode.js';
export * from './utils/Oscillators.js';
export * from './utils/Packing.js';
Expand All @@ -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
27 changes: 27 additions & 0 deletions src/nodes/utils/EquirectUV.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { positionWorldDirection } from '../accessors/Position.js';
import { Fn, vec2 } from '../tsl/TSLBase.js';

/**
* TSL function for creating an equirect uv node.
*
* Can be used to compute texture coordinates for projecting an
* equirectangular texture onto a mesh for using it as the scene's
* background.
*
* ```js
* scene.backgroundNode = texture( equirectTexture, equirectUV() );
* ```
*
* @tsl
* @function
* @param {?Node<vec3>} [dirNode=positionWorldDirection] - A direction vector for sampling which is by default `positionWorldDirection`.
* @returns {Node<vec2>}
*/
export const equirectUV = /*@__PURE__*/ Fn( ( [ dir = positionWorldDirection ] ) => {

const u = dir.z.atan( dir.x ).mul( 1 / ( Math.PI * 2 ) ).add( 0.5 );
const v = dir.y.clamp( - 1.0, 1.0 ).asin().mul( 1 / Math.PI ).add( 0.5 );

return vec2( u, v );

} );
65 changes: 0 additions & 65 deletions src/nodes/utils/EquirectUVNode.js

This file was deleted.

22 changes: 22 additions & 0 deletions src/nodes/utils/MatcapUV.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { normalView } from '../accessors/Normal.js';
import { positionViewDirection } from '../accessors/Position.js';
import { Fn, vec2, vec3 } from '../tsl/TSLBase.js';

/**
* TSL function for creating a matcap uv node.
*
* Can be used to compute texture coordinates for projecting a
* matcap onto a mesh. Used by {@link MeshMatcapNodeMaterial}.
*
* @tsl
* @function
* @returns {Node<vec2>} The matcap UV coordinates.
*/
export const matcapUV = /*@__PURE__*/ Fn( () => {

const x = vec3( positionViewDirection.z, 0, positionViewDirection.x.negate() ).normalize();
const y = positionViewDirection.cross( x );

return vec2( x.dot( normalView ), y.dot( normalView ) ).mul( 0.495 ).add( 0.5 ); // 0.495 to remove artifacts caused by undersized matcap disks

} ).once( [ 'NORMAL', 'VERTEX' ] )().toVar( 'matcapUV' );
49 changes: 0 additions & 49 deletions src/nodes/utils/MatcapUVNode.js

This file was deleted.

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 );
Loading