ソースを参照

WebGPURenderer: Reuse `MatcapUVNode` in `MeshMatcapNodeMaterial` (#28274)

* add note

* use matcapUV
sunag 1 年間 前
コミット
494173b26d

+ 3 - 7
examples/jsm/nodes/materials/MeshMatcapNodeMaterial.js

@@ -1,11 +1,10 @@
 import NodeMaterial, { addNodeMaterial } from './NodeMaterial.js';
 import NodeMaterial, { addNodeMaterial } from './NodeMaterial.js';
 import { materialReference } from '../accessors/MaterialReferenceNode.js';
 import { materialReference } from '../accessors/MaterialReferenceNode.js';
 import { diffuseColor } from '../core/PropertyNode.js';
 import { diffuseColor } from '../core/PropertyNode.js';
-import { vec2, vec3 } from '../shadernode/ShaderNode.js';
-import { positionViewDirection } from '../accessors/PositionNode.js';
+import { vec3 } from '../shadernode/ShaderNode.js';
 import { MeshMatcapMaterial } from 'three';
 import { MeshMatcapMaterial } from 'three';
-import { transformedNormalView } from '../accessors/NormalNode.js';
 import { mix } from '../math/MathNode.js';
 import { mix } from '../math/MathNode.js';
+import { matcapUV } from '../utils/MatcapUVNode.js';
 
 
 const defaultValues = new MeshMatcapMaterial();
 const defaultValues = new MeshMatcapMaterial();
 
 
@@ -27,10 +26,7 @@ class MeshMatcapNodeMaterial extends NodeMaterial {
 
 
 	setupVariants( builder ) {
 	setupVariants( builder ) {
 
 
-		const x = vec3( positionViewDirection.z, 0.0, positionViewDirection.x.negate() ).normalize();
-		const y = positionViewDirection.cross( x );
-
-		const uv = vec2( x.dot( transformedNormalView ), y.dot( transformedNormalView ) ).mul( 0.495 ).add( 0.5 ) ; // 0.495 to remove artifacts caused by undersized matcap disks
+		const uv = matcapUV;
 
 
 		let matcapColor;
 		let matcapColor;
 
 

+ 1 - 1
examples/jsm/nodes/utils/MatcapUVNode.js

@@ -17,7 +17,7 @@ class MatcapUVNode extends TempNode {
 		const x = vec3( positionViewDirection.z, 0, positionViewDirection.x.negate() ).normalize();
 		const x = vec3( positionViewDirection.z, 0, positionViewDirection.x.negate() ).normalize();
 		const y = positionViewDirection.cross( x );
 		const y = positionViewDirection.cross( x );
 
 
-		return vec2( x.dot( transformedNormalView ), y.dot( transformedNormalView ) ).mul( 0.495 ).add( 0.5 );
+		return vec2( x.dot( transformedNormalView ), y.dot( transformedNormalView ) ).mul( 0.495 ).add( 0.5 ); // 0.495 to remove artifacts caused by undersized matcap disks
 
 
 	}
 	}