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/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
1 change: 0 additions & 1 deletion src/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ 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';
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export * from './math/TriNoise3D.js';
export * from './utils/EquirectUVNode.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 Down
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.