1
+ import { WebGLCoordinateSystem } from '../../constants.js' ;
1
2
import TempNode from '../core/TempNode.js' ;
2
3
import { addMethodChaining , nodeProxy } from '../tsl/TSLCore.js' ;
3
4
@@ -117,6 +118,7 @@ class OperatorNode extends TempNode {
117
118
} else {
118
119
119
120
// Handle matrix operations
121
+
120
122
if ( builder . isMatrix ( typeA ) ) {
121
123
122
124
if ( typeB === 'float' ) {
@@ -148,6 +150,7 @@ class OperatorNode extends TempNode {
148
150
}
149
151
150
152
// Handle non-matrix cases
153
+
151
154
if ( builder . getTypeLength ( typeB ) > builder . getTypeLength ( typeA ) ) {
152
155
153
156
// anytype x anytype: use the greater length vector
@@ -201,6 +204,7 @@ class OperatorNode extends TempNode {
201
204
if ( typeB === 'float' ) {
202
205
203
206
// Keep matrix type for typeA, but ensure typeB stays float
207
+
204
208
typeB = 'float' ;
205
209
206
210
} else if ( builder . isVector ( typeB ) ) {
@@ -209,7 +213,9 @@ class OperatorNode extends TempNode {
209
213
typeB = builder . getVectorFromMatrix ( typeA ) ;
210
214
211
215
} else if ( builder . isMatrix ( typeB ) ) {
216
+
212
217
// matrix x matrix - keep both types
218
+
213
219
} else {
214
220
215
221
typeA = typeB = type ;
@@ -221,11 +227,13 @@ class OperatorNode extends TempNode {
221
227
if ( typeA === 'float' ) {
222
228
223
229
// Keep matrix type for typeB, but ensure typeA stays float
230
+
224
231
typeA = 'float' ;
225
232
226
233
} else if ( builder . isVector ( typeA ) ) {
227
234
228
235
// vector x matrix
236
+
229
237
typeA = builder . getVectorFromMatrix ( typeB ) ;
230
238
231
239
} else {
@@ -256,50 +264,90 @@ class OperatorNode extends TempNode {
256
264
257
265
if ( output !== 'void' ) {
258
266
259
- if ( op === '<' && outputLength > 1 ) {
267
+ const isGLSL = builder . renderer . coordinateSystem === WebGLCoordinateSystem ;
268
+
269
+ if ( op === '==' ) {
270
+
271
+ if ( isGLSL ) {
272
+
273
+ if ( outputLength > 1 ) {
274
+
275
+ return builder . format ( `${ builder . getMethod ( 'equal' , output ) } ( ${ a } , ${ b } )` , type , output ) ;
276
+
277
+ } else {
278
+
279
+ return builder . format ( `( ${ a } ${ op } ${ b } )` , type , output ) ;
280
+
281
+ }
282
+
283
+ } else {
284
+
285
+ // WGSL
286
+
287
+ if ( outputLength > 1 || ! builder . isVector ( typeA ) ) {
288
+
289
+ return builder . format ( `( ${ a } == ${ b } )` , type , output ) ;
260
290
261
- if ( builder . useComparisonMethod ) {
291
+ } else {
292
+
293
+ return builder . format ( `all( ${ a } == ${ b } )` , type , output ) ;
294
+
295
+ }
296
+
297
+ }
298
+
299
+ } else if ( op === '<' && outputLength > 1 ) {
300
+
301
+ if ( isGLSL ) {
262
302
263
303
return builder . format ( `${ builder . getMethod ( 'lessThan' , output ) } ( ${ a } , ${ b } )` , type , output ) ;
264
304
265
305
} else {
266
306
307
+ // WGSL
308
+
267
309
return builder . format ( `( ${ a } < ${ b } )` , type , output ) ;
268
310
269
311
}
270
312
271
313
} else if ( op === '<=' && outputLength > 1 ) {
272
314
273
- if ( builder . useComparisonMethod ) {
315
+ if ( isGLSL ) {
274
316
275
317
return builder . format ( `${ builder . getMethod ( 'lessThanEqual' , output ) } ( ${ a } , ${ b } )` , type , output ) ;
276
318
277
319
} else {
278
320
321
+ // WGSL
322
+
279
323
return builder . format ( `( ${ a } <= ${ b } )` , type , output ) ;
280
324
281
325
}
282
326
283
327
} else if ( op === '>' && outputLength > 1 ) {
284
328
285
- if ( builder . useComparisonMethod ) {
329
+ if ( isGLSL ) {
286
330
287
331
return builder . format ( `${ builder . getMethod ( 'greaterThan' , output ) } ( ${ a } , ${ b } )` , type , output ) ;
288
332
289
333
} else {
290
334
335
+ // WGSL
336
+
291
337
return builder . format ( `( ${ a } > ${ b } )` , type , output ) ;
292
338
293
339
}
294
340
295
341
} else if ( op === '>=' && outputLength > 1 ) {
296
342
297
- if ( builder . useComparisonMethod ) {
343
+ if ( isGLSL ) {
298
344
299
345
return builder . format ( `${ builder . getMethod ( 'greaterThanEqual' , output ) } ( ${ a } , ${ b } )` , type , output ) ;
300
346
301
347
} else {
302
348
349
+ // WGSL
350
+
303
351
return builder . format ( `( ${ a } >= ${ b } )` , type , output ) ;
304
352
305
353
}
@@ -315,6 +363,7 @@ class OperatorNode extends TempNode {
315
363
} else {
316
364
317
365
// Handle matrix operations
366
+
318
367
if ( builder . isMatrix ( typeA ) && typeB === 'float' ) {
319
368
320
369
return builder . format ( `( ${ b } ${ op } ${ a } )` , type , output ) ;
0 commit comments