Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've been reading up on particle systems amongst other stuff and one interesting approach uses rendertargets to store a particle's position, velocity, lifetime, etc. A pretty neat summary is given here, for example: http://content.gpwiki.org/index.php/D3DBook:Dynamic_Particle_Systems#GPU_Based_Particle_Systems_.28D3D9.29

However, I'm wondering how to effectively use such a system? How would you create new particles, upload them to the GPU and how'd you determine what particles to draw? I mean, if you've got a 512x512 rendertarget storing particles, would you really just send a vertexbuffer with 262144 quads to the GPU and let the shader figure out which particles to draw and which to ignore?

Right now this sounds like a good idea for those bigger, continuous particle effects like weather or something... particle systems, which don't change often, can run for a while or where particle generation. I don't really see how they'd be performant enough to power dynamic one-off effects like explosions or something, because uploading new particles would basically require locking the rendertarget(s) and manipulating its (their) pixels, right?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Mario

As it is stated in the link you refer to, those particle systems have their limitations. As it is also mentioned, sometimes, stencil pre-pass is used to eliminate unused pixels.

Now to your questions:

How would you create new particles, upload them to the GPU and how'd you determine what particles to draw?

This can be done in pixel shader, you first read render target which stores particle info and determine if it is dead. If yes you just write to the output RT initialized particle (as usually done on the CPU as well). Of course, you are not able to add more particles in this case.

There are more possibilities in DX10/100 however. Using geometry shader, more sophisticated techniques can be used. E.g. geometery shader can read buffers data which store particle info and based on this output triangles or not. But you'll have to anyway pass through the whole array. However you can split this in two passes: 1) generate triangles and output them to Stream Output stage buffers. 2) Use DrawAuto to shade only the previously output data.

So, basically yes, you can make decisions inside your shader about which particles to draw.

There are other more GPGPU like techniques, and it can be done using just DX9. E.g. After some time most of the particles may be dead, so in order to not waste time on them you can sort your buffers (render targets). For such a basic case like dead/alive Histopyramid method will suffice. This can be especially useful for the effects like explosions, when many particles quickly die.

because uploading new particles would basically require locking the rendertarget(s) and manipulating its (their) pixels, right?

Yes, if you really want to do it on CPU. But you do not always need to, if you can generate your particles on GPU. Again in DX10/11, you can use Stream Output to generate your particles. In vertex shader you may use SV_VertexID semantics to determine current vertex ID and generate particle based on this ID. You can also generate your particles in pixel shader by output data to render target. This all depends on what you are doing. Some techniques could be more suitable than other.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.