Particles on the gpu or cpu?

Started by
5 comments, last by Pilpel 8 years, 5 months ago

I'm was reading this tutorial early on today but then I recalled I once read about Transform Feedback in a book about opengl, which is a technique for rendering particles using the gpu.

So now I ask which technique should I study? Are cpu particles outdated or are they still relevant?

Is this a good tutorial for gpu particles?

Advertisement

For GPU particles you'll want to use compute shaders for the simulation, much easier and quicker than using a geometry shader.

There's an example here in the Hieroglyph engine.

Secondly, I'd have support for both. GPU particles are great for particle systems with many particles but you can't necessarily support all simulation types on the GPU alone.

Take 3D mesh collision for mesh particles for example, you might only be able to simulate these on the CPU depending on your engine tech/libs.


Are cpu particles outdated or are they still relevant?

Definitely not outdated.

If you have CPU time over, then put them on the CPU. if you have GPU time, put it on GPU.

One game could have both, depending on situation, and type of particles.

Having particles on the CPU would allow them to have consequences in the game. For instance, flying bits of hot metal could actually hurt characters.

Having particles on the CPU would allow them to have consequences in the game. For instance, flying bits of hot metal could actually hurt characters.

You can have that with gpu particles too but its get complicated quickly and there is frame or two latency to hide. This latency can be particularly pain with sound effects where you will notice it quickly if visuals and sounds are not in sync.

Why not have both smile.png As above, CPU particles give you more flexibility in writing the code, and are easier to make interactive with other gameplay code. GPU particles can give you extremely large numbers (millions) of particles, but interaction such as collision detection is a bit trickier.

There's 3 main ways of doing GPU particles:

  • update logic in pixel shader, stored in texture (new in GL2/D3D9 thanks to "vertex texture fetch" or deprecated "R2VB" on a handful of old ATI cards...).
  • update logic in vertex shader, stored in buffer (new in GL3/D3D10 thanks to stream out / transform feedback).
  • update logic in compute shader, stored in texture or buffer (new in GL4/D3D11 thanks to general purpose compute and UAV/SSBOs).

For CPU particles, you just need a fast way to stream dynamically generated vertex data from CPU->GPU, such as no-overwrite ring buffers or orphaning/discarding buffers. You'll almost certainly want to use SIMD and multi-core for your particle update code too cool.png

See:

https://developer.nvidia.com/sites/default/files/akamai/gamedev/files/gdc12/Efficient_Buffer_Management_McDonald.pdf

http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-AsynchronousBufferTransfers.pdf

I made a very simple cpu particle system. Some notes / questions, please reply if you feel like I'm doing something wrong.

1. I made three classes for this: ParticleContainer, ParticleEmitter, ParticleUpdater. I know the whole particle system has to work really fast so I neglected many error checking in ParticleContainer methods, and made every method and data member in it private. I also made ParticleEmitter, ParticleUpdater, and Renderer friend classes so only they have access. Note that ParticleContainer works the same way as in the tutorial I linked above - everytime a particle is killed, it swaps its position with the last alive particle.

Code link.

2. I really want to create polymorphic classes of ParticleEmitter. (e.g class WaterfallEmitter : public ParticleEmitter {};) However, I know that virtual methods operate slower. Any advice / workaround?

3. Can you explain me in short how to use the transform feedback for gpu particles? I know about this tutorial but I think the author made it much more complex than it should be.

I also really hate his coding style.

This topic is closed to new replies.

Advertisement