Jelajahi Sumber

TSL: Make `not()` on vector produce component-wise logical not (#33442)

Shota Matsuda 3 bulan lalu
induk
melakukan
21829d86ff
1 mengubah file dengan 23 tambahan dan 3 penghapusan
  1. 23 3
      src/nodes/math/OperatorNode.js

+ 23 - 3
src/nodes/math/OperatorNode.js

@@ -128,10 +128,16 @@ class OperatorNode extends TempNode {
 
 
 			return builder.getIntegerType( typeA );
 			return builder.getIntegerType( typeA );
 
 
-		} else if ( op === '!' || op === '&&' || op === '||' || op === '^^' ) {
+		} else if ( op === '&&' || op === '||' || op === '^^' ) {
 
 
 			return 'bool';
 			return 'bool';
 
 
+		} else if ( op === '!' ) {
+
+			const typeLength = builder.getTypeLength( typeA );
+
+			return typeLength > 1 ? `bvec${ typeLength }` : 'bool';
+
 		} else if ( op === '==' || op === '!=' || op === '<' || op === '>' || op === '<=' || op === '>=' ) {
 		} else if ( op === '==' || op === '!=' || op === '<' || op === '>' || op === '<=' || op === '>=' ) {
 
 
 			const typeLength = Math.max( builder.getTypeLength( typeA ), builder.getTypeLength( typeB ) );
 			const typeLength = Math.max( builder.getTypeLength( typeA ), builder.getTypeLength( typeB ) );
@@ -330,9 +336,23 @@ class OperatorNode extends TempNode {
 
 
 				}
 				}
 
 
-			} else if ( op === '!' || op === '~' ) {
+			} else if ( op === '!' ) {
+
+				if ( isGLSL && builder.isVector( typeA ) ) {
+
+					return builder.format( `not( ${a} )`, output );
+
+				} else {
+
+					// WGSL and scalars on GLSL
+
+					return builder.format( `( ${op} ${a} )`, typeA, output );
+
+				}
+
+			} else if ( op === '~' ) {
 
 
-				return builder.format( `(${op}${a})`, typeA, output );
+				return builder.format( `( ${op} ${a} )`, typeA, output );
 
 
 			} else if ( fnOpSnippet ) {
 			} else if ( fnOpSnippet ) {
 
 

粤ICP备19079148号