TLS: equals between u32, f32 or i32

Hey,

I’m trying to compare 2 u32 using the “equals” function with TSL:

const start = uint(0).toVar();
const plus = uint(0x2b);
const firstCharCode = src.element(start);
If(equals(firstCharCode, plus), () => { // Here
    start.assign(start.add(1));
})

But I’m getting the following error:

Error while parsing WGSL: :156:24 error: type mismatch for argument 1 in call to ‘tsl_equals_bool’, expected ‘bool’, got ‘u32’
if ( tsl_equals_bool( NodeBuffer_558.value[ nodeVar3 ].x, 43u ) ) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is the result of my search for a tsl_equals_u32 WGSL function:

Does that mean “equals” doesn’t work with u32, f32 or i32?
Did I miss something?

Do you mind demonstrating the issue with a live example? Use the following as a starter template: https://jsfiddle.net/z6mahj8x/1/

Hey,

Here’s an example: three.js dev template - module - JSFiddle - Code Playground

Maybe chaining could circumvent the issue? Does this work:

If(firstCharCode.equal(plus), () => { 
    start.assign(start.add(1));
})

Nop, same error.

That’s strange. Just tried it, some tetrahedrons are flying around, no error message:

When I try, I get that:

The tetrahedrons color is supposed to be red if everything works.

I edited the original jsfiddle btw.
The color node at the end of the code needed a f32 value in the range [0, 1] not a u32 in [0, 255].

When chaining it is equal, not equals

1 Like

You’re right!

When chaining with “equal” it does work.

But I had to change my Uint8Array to a regular Array too.
The code wasn’t working otherwise.
Is this intended that way?

Anyway, I can work with that. Thank you.

Here is the changes I made: three.js dev template - module - JSFiddle - Code Playground

I don’t know. I think the discrepancy between equals(x,y) and x.equal(y) is confusing and it may be good to file an issue in https://github.com/mrdoob/three.js/issues if this issue is not mentioned already.

1 Like