Is it possible to get an attributeArray calculated using a compute shader back to the CPU?
Yes, it’s pretty easy with await renderer.getArrayBufferAsync
Please excuse me for being too comfortable at the moment to quickly provide a simple example. I usually make short code pens for this.
What you need is a storageBufferAttribute. You can use this in a tsl and wgsl compute, vertex and fragment shader and always access any elements (better then ordinary attributes). As mentioned, you can then read it back simply with await renderer.getArrayBufferAsync
//in your code initialize and use it in your compute shader to set elementValues or set directly with [element1, element2, element3, ...]. For vec3 elementSize is 3
this.someStorageBuffer = new THREE.StorageBufferAttribute( new Float32Array( size ) , elementSize );
//in your async update function
this.readStorageBackToCPU = new Float32Array( await this.renderer.getArrayBufferAsync( this.someStorageBuffer ) );
Before reading back, make sure that the storage buffer has always been filled in the compute shader or initialize it on the CPU side with .fill(0) and add it to the shader so that the values end up in the GPU, otherwise there will be an error message when you read it back.
I hope this helps. I’m very busy with my project at the moment. Otherwise, as mentioned, I would have quickly made a code pen for it. I hope this helps too.
Thanks Attila, perfect solution.