I’ve implemented particles already in my game but now I’m at a point where I’m using it very inefficient. My particles do not reemit themselves as the book covers but are triggered based on time and/or movement. Currently, I’m doing this by reading out the particle buffer, looping over each particle, separate them based on alive/dead, then render the alive particles. All on the CPU. I’m only repositioning each alive particle on the GPU. With my game progressing this is the #1 bottleneck.
To improve performance I want to move this functionality to the GPU. The book states the use of two buffers on page 489. But unfortunately, does not continue with that concept.
More complex particle systems would maintain a live buffer and a dead buffer. As particles die, they move from live to dead, and as the system requires new particles, it recovers them from dead
Is there an example available that goes deeper into this? I’m at the point of having a live buffer, dead buffer, and a buffer that stores the live/dead count. I already know how to read and write to a buffer from the compute shader. But I’m not sure how to efficiently remove this from the CPU. I would still need to read out the life/dead count to use in the following code:
encoder.drawPrimitives(type: .point, vertexStart: 0, vertexCount: 1, instanceCount: amountOfParticlesAlive)
Am I missing something or overthinking this? Any help or additional documentation to this topic would be greatly appreciated. Thank you.