attributeArray.element(x) returns [instanceIndex] element always. In fact it does not care about parameters at all, you can write attributeArray.element() it will do the same. Or even just attributeArray.
const count = 2
const posArray = attributeArray(new Float32Array(count * 3), 'vec3')
posArray.setPBO(true);
for (let i = 0; i < count; i++)
posArray.value.array[i*3] = i+1 //so every vector has x set as it's position +1
const computeWithoutChanges = Fn(() => {
const pos = posArray.toVar() //take element at index
posArray.element(instanceIndex).assign(pos) //assign to all elements
})().compute(count)
console.log("Array before: " + posArray.value.array) //array before compute is just fine
const renderer = new THREE.WebGPURenderer()
renderer.computeAsync(computeWithoutChanges)
.then(() => renderer.getArrayBufferAsync(posArray.value))
.then((buffer) =>
console.log("Array after: " + new Float32Array(buffer)))
posArray.element(1).assign(vec(1, 1, 1)) //explicitly asking to assign element 1
floods the array
In flocking example attributeArray.element is used liberally to access arbitrary elements of the buffer, what am I doing wrong?
EDIT: Can anyone confirm the example here three.js examples is working properly? For me with webgl2 fallback birds just converge in the center, no boid behaviour applied.