I'm working on my first game engine, and trying to implement a GPU particle system. I've implemented one on the CPU before, but now I'm trying to make it more efficient. My problem, specifically, is with spawning particles on a lifetime.
Since I'm working with framebuffer textures for the particle engine, it's very parallel, but at the cost of not being able to return to the CPU, right? I have a first pass in drawing a quad that handles the calculations for that specific particle system (there will probably have to be a second quad for the sake of sorting), and then I run a glDrawArraysInstanced
One idea I had was to use a boolean or an int for when I need to create a particle, representing either the need to create a particle or the amount of particles to spawn, both initialized by the CPU. So if I find one particle (pixel) that's lifetime (let's say the alpha value of the first fbo texture) is less than zero, and I know I'm supposed to create it, how do I disable the creation for the rest of the particles, or decrement the number of particles to be burst? I've heard of things like transform feedback, but I don't know if that's the best way. And stateless particles sound limiting - not all particles have a 1:1 spawning rate.
To repeat the question briefly: What is the best way to spawn GPU particles?
If I could have the number of particles on the CPU, by the way, I could set the amount to draw in glDrawArraysInstanced, so if you could include that in your answer, I would be grateful.