Skip to content

Is it possible to move 3 by 3 in the threads and output 3 values at a time inside a Float32Array ? #674

@itsKaspar

Description

@itsKaspar

I'm currently writting a particle system, and following advice I have flattened all my particle position arrays so that they look like [x,y,z,x,y,z,x,y,z,..]. Nevertheless, an issue that I am hitting is that sometimes I have to normalize vectors, or set their magnitude, which means that I'm often writting the code :

const o = this.thread.x % 3; // 0 if x, 1 if y, 2 if z

// get current position
const px = pos[this.thread.x - o + 0];
const py = pos[this.thread.x - o + 1];
const pz = pos[this.thread.x - o + 2]; 

Which is then followed by expensive operations that I had to do only once per thread when I was using a Vector3 Array as an input and output.

I gather that I can probably ignore 2 out of 3 threads with a simple %3 operation but if I do that I need to output 3 consecutive values in the same Float32Array at each thread % 3. Is there a way for a kernel to return multiple values at once. Something that would act the same way as this :

myFloat32Array.push(x)
myFloat32Array.push(y)
myFloat32Array.push(z)

Thanks a lot !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions