|
|
@@ -1,3 +1,4 @@
|
|
|
+import { WebGLCoordinateSystem } from '../../constants.js';
|
|
|
import TempNode from '../core/TempNode.js';
|
|
|
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
|
|
|
|
|
|
@@ -117,6 +118,7 @@ class OperatorNode extends TempNode {
|
|
|
} else {
|
|
|
|
|
|
// Handle matrix operations
|
|
|
+
|
|
|
if ( builder.isMatrix( typeA ) ) {
|
|
|
|
|
|
if ( typeB === 'float' ) {
|
|
|
@@ -148,6 +150,7 @@ class OperatorNode extends TempNode {
|
|
|
}
|
|
|
|
|
|
// Handle non-matrix cases
|
|
|
+
|
|
|
if ( builder.getTypeLength( typeB ) > builder.getTypeLength( typeA ) ) {
|
|
|
|
|
|
// anytype x anytype: use the greater length vector
|
|
|
@@ -201,6 +204,7 @@ class OperatorNode extends TempNode {
|
|
|
if ( typeB === 'float' ) {
|
|
|
|
|
|
// Keep matrix type for typeA, but ensure typeB stays float
|
|
|
+
|
|
|
typeB = 'float';
|
|
|
|
|
|
} else if ( builder.isVector( typeB ) ) {
|
|
|
@@ -209,7 +213,9 @@ class OperatorNode extends TempNode {
|
|
|
typeB = builder.getVectorFromMatrix( typeA );
|
|
|
|
|
|
} else if ( builder.isMatrix( typeB ) ) {
|
|
|
+
|
|
|
// matrix x matrix - keep both types
|
|
|
+
|
|
|
} else {
|
|
|
|
|
|
typeA = typeB = type;
|
|
|
@@ -221,11 +227,13 @@ class OperatorNode extends TempNode {
|
|
|
if ( typeA === 'float' ) {
|
|
|
|
|
|
// Keep matrix type for typeB, but ensure typeA stays float
|
|
|
+
|
|
|
typeA = 'float';
|
|
|
|
|
|
} else if ( builder.isVector( typeA ) ) {
|
|
|
|
|
|
// vector x matrix
|
|
|
+
|
|
|
typeA = builder.getVectorFromMatrix( typeB );
|
|
|
|
|
|
} else {
|
|
|
@@ -256,50 +264,90 @@ class OperatorNode extends TempNode {
|
|
|
|
|
|
if ( output !== 'void' ) {
|
|
|
|
|
|
- if ( op === '<' && outputLength > 1 ) {
|
|
|
+ const isGLSL = builder.renderer.coordinateSystem === WebGLCoordinateSystem;
|
|
|
+
|
|
|
+ if ( op === '==' ) {
|
|
|
+
|
|
|
+ if ( isGLSL ) {
|
|
|
+
|
|
|
+ if ( outputLength > 1 ) {
|
|
|
+
|
|
|
+ return builder.format( `${ builder.getMethod( 'equal', output ) }( ${ a }, ${ b } )`, type, output );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ return builder.format( `( ${ a } ${ op } ${ b } )`, type, output );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // WGSL
|
|
|
+
|
|
|
+ if ( outputLength > 1 || ! builder.isVector( typeA ) ) {
|
|
|
+
|
|
|
+ return builder.format( `( ${ a } == ${ b } )`, type, output );
|
|
|
|
|
|
- if ( builder.useComparisonMethod ) {
|
|
|
+ } else {
|
|
|
+
|
|
|
+ return builder.format( `all( ${ a } == ${ b } )`, type, output );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if ( op === '<' && outputLength > 1 ) {
|
|
|
+
|
|
|
+ if ( isGLSL ) {
|
|
|
|
|
|
return builder.format( `${ builder.getMethod( 'lessThan', output ) }( ${ a }, ${ b } )`, type, output );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
+ // WGSL
|
|
|
+
|
|
|
return builder.format( `( ${ a } < ${ b } )`, type, output );
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if ( op === '<=' && outputLength > 1 ) {
|
|
|
|
|
|
- if ( builder.useComparisonMethod ) {
|
|
|
+ if ( isGLSL ) {
|
|
|
|
|
|
return builder.format( `${ builder.getMethod( 'lessThanEqual', output ) }( ${ a }, ${ b } )`, type, output );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
+ // WGSL
|
|
|
+
|
|
|
return builder.format( `( ${ a } <= ${ b } )`, type, output );
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if ( op === '>' && outputLength > 1 ) {
|
|
|
|
|
|
- if ( builder.useComparisonMethod ) {
|
|
|
+ if ( isGLSL ) {
|
|
|
|
|
|
return builder.format( `${ builder.getMethod( 'greaterThan', output ) }( ${ a }, ${ b } )`, type, output );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
+ // WGSL
|
|
|
+
|
|
|
return builder.format( `( ${ a } > ${ b } )`, type, output );
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if ( op === '>=' && outputLength > 1 ) {
|
|
|
|
|
|
- if ( builder.useComparisonMethod ) {
|
|
|
+ if ( isGLSL ) {
|
|
|
|
|
|
return builder.format( `${ builder.getMethod( 'greaterThanEqual', output ) }( ${ a }, ${ b } )`, type, output );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
+ // WGSL
|
|
|
+
|
|
|
return builder.format( `( ${ a } >= ${ b } )`, type, output );
|
|
|
|
|
|
}
|
|
|
@@ -315,6 +363,7 @@ class OperatorNode extends TempNode {
|
|
|
} else {
|
|
|
|
|
|
// Handle matrix operations
|
|
|
+
|
|
|
if ( builder.isMatrix( typeA ) && typeB === 'float' ) {
|
|
|
|
|
|
return builder.format( `( ${ b } ${ op } ${ a } )`, type, output );
|