Skip to content

Commit c1c72c7

Browse files
authored
TSL: Move MatcapUVNode to matcapUV Fn constant (#31284)
* Move MatcapUVNode to matcapUV Fn constant * rename
1 parent a36bc1b commit c1c72c7

File tree

5 files changed

+24
-52
lines changed

5 files changed

+24
-52
lines changed

src/materials/nodes/MeshMatcapNodeMaterial.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { materialReference } from '../../nodes/accessors/MaterialReferenceNode.j
33
import { diffuseColor } from '../../nodes/core/PropertyNode.js';
44
import { vec3 } from '../../nodes/tsl/TSLBase.js';
55
import { mix } from '../../nodes/math/MathNode.js';
6-
import { matcapUV } from '../../nodes/utils/MatcapUVNode.js';
6+
import { matcapUV } from '../../nodes/utils/MatcapUV.js';
77

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

src/nodes/Nodes.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export { default as EquirectUVNode } from './utils/EquirectUVNode.js';
4545
export { default as FunctionOverloadingNode } from './utils/FunctionOverloadingNode.js';
4646
export { default as JoinNode } from './utils/JoinNode.js';
4747
export { default as LoopNode } from './utils/LoopNode.js';
48-
export { default as MatcapUVNode } from './utils/MatcapUVNode.js';
4948
export { default as MaxMipLevelNode } from './utils/MaxMipLevelNode.js';
5049
export { default as RemapNode } from './utils/RemapNode.js';
5150
export { default as RotateNode } from './utils/RotateNode.js';

src/nodes/TSL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export * from './math/TriNoise3D.js';
2727
export * from './utils/EquirectUVNode.js';
2828
export * from './utils/FunctionOverloadingNode.js';
2929
export * from './utils/LoopNode.js';
30-
export * from './utils/MatcapUVNode.js';
30+
export * from './utils/MatcapUV.js';
3131
export * from './utils/MaxMipLevelNode.js';
3232
export * from './utils/Oscillators.js';
3333
export * from './utils/Packing.js';

src/nodes/utils/MatcapUV.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { normalView } from '../accessors/Normal.js';
2+
import { positionViewDirection } from '../accessors/Position.js';
3+
import { Fn, vec2, vec3 } from '../tsl/TSLBase.js';
4+
5+
/**
6+
* TSL function for creating a matcap uv node.
7+
*
8+
* Can be used to compute texture coordinates for projecting a
9+
* matcap onto a mesh. Used by {@link MeshMatcapNodeMaterial}.
10+
*
11+
* @tsl
12+
* @function
13+
* @returns {Node<vec2>} The matcap UV coordinates.
14+
*/
15+
export const matcapUV = /*@__PURE__*/ Fn( () => {
16+
17+
const x = vec3( positionViewDirection.z, 0, positionViewDirection.x.negate() ).normalize();
18+
const y = positionViewDirection.cross( x );
19+
20+
return vec2( x.dot( normalView ), y.dot( normalView ) ).mul( 0.495 ).add( 0.5 ); // 0.495 to remove artifacts caused by undersized matcap disks
21+
22+
} ).once( [ 'NORMAL', 'VERTEX' ] )().toVar( 'matcapUV' );

src/nodes/utils/MatcapUVNode.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)