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 :
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 :
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 :
Thanks a lot !