Browse Source

NodeMaterial: Cleanup `alphaTest` (#31147)

* NodeMaterial: Cleanup `alphaTest`

* cleanup

* cleanup

* cleanup
sunag 7 months ago
parent
commit
8301152886
2 changed files with 17 additions and 11 deletions
  1. 1 1
      examples/webgpu_lines_fat_raycasting.html
  2. 16 10
      src/materials/nodes/NodeMaterial.js

+ 1 - 1
examples/webgpu_lines_fat_raycasting.html

@@ -97,7 +97,7 @@
 
 				clock = new THREE.Clock();
 
-				renderer = new THREE.WebGPURenderer( { antialias: true, alpha: true } );
+				renderer = new THREE.WebGPURenderer( { antialias: true, alpha: true, trackTimestamp: true } );
 				renderer.setPixelRatio( window.devicePixelRatio );
 				renderer.setSize( window.innerWidth, window.innerHeight );
 				renderer.setClearColor( 0x000000, 0.0 );

+ 16 - 10
src/materials/nodes/NodeMaterial.js

@@ -783,8 +783,6 @@ class NodeMaterial extends Material {
 	 */
 	setupDiffuseColor( { object, geometry } ) {
 
-		let colorNode = this.colorNode ? vec4( this.colorNode ) : materialColor;
-
 		// MASK
 
 		if ( this.maskNode !== null ) {
@@ -793,6 +791,10 @@ class NodeMaterial extends Material {
 
 		}
 
+		// COLOR
+
+		let colorNode = this.colorNode ? vec4( this.colorNode ) : materialColor;
+
 		// VERTEX COLORS
 
 		if ( this.vertexColors === true && geometry.hasAttribute( 'color' ) ) {
@@ -819,7 +821,7 @@ class NodeMaterial extends Material {
 
 		}
 
-		// COLOR
+		// DIFFUSE COLOR
 
 		diffuseColor.assign( colorNode );
 
@@ -830,20 +832,16 @@ class NodeMaterial extends Material {
 
 		// ALPHA TEST
 
-		let alphaTestNode;
+		let alphaTestNode = null;
 
 		if ( this.alphaTestNode !== null || this.alphaTest > 0 ) {
 
 			alphaTestNode = this.alphaTestNode !== null ? float( this.alphaTestNode ) : materialAlphaTest;
 
-		} else {
-
-			alphaTestNode = float( 0 );
+			diffuseColor.a.lessThanEqual( alphaTestNode ).discard();
 
 		}
 
-		diffuseColor.a.lessThanEqual( alphaTestNode ).discard();
-
 		// ALPHA HASH
 
 		if ( this.alphaHash === true ) {
@@ -852,10 +850,18 @@ class NodeMaterial extends Material {
 
 		}
 
-		if ( this.transparent === false && this.blending === NormalBlending && this.alphaToCoverage === false ) {
+		// OPAQUE
+
+		const isOpaque = this.transparent === false && this.blending === NormalBlending && this.alphaToCoverage === false;
+
+		if ( isOpaque ) {
 
 			diffuseColor.a.assign( 1.0 );
 
+		} else if ( alphaTestNode === null ) {
+
+			diffuseColor.a.lessThanEqual( 0 ).discard();
+
 		}
 
 	}

粤ICP备19079148号