Can I use the graphics card's GPU to create particles?

Started by
5 comments, last by 21st Century Moose 11 years, 10 months ago
Im wanting to draw as many particles as i possibly can, so can i somehow create the on the graphics card and update them there instead of doing any calculations on the cpu?

My gut tells me you can, but i dont know for sure lol.

And if you can how in D3D9?
Advertisement

Im wanting to draw as many particles as i possibly can, so can i somehow create the on the graphics card and update them there instead of doing any calculations on the cpu?

My gut tells me you can, but i dont know for sure lol.

And if you can how in D3D9?

For sure you can, but it depends somewhat on your requirements. Basicly you can move them along a precalcualted path (i.e. linear or bezier), the next step would be, to save all vertex data in video memory and update them on the GPU alone. What will be really hard is, if you want to add kind of collision detection with the world.

But with the limitation of D3D9 I would sugguest to stick to a pre-calculated path, the preculculated path could be a simple linear interpolation between two points by a vertex shader, or a 4 point bezier spline interpolation.
If you're using Direct3D 9, you should probably stick to the CPU. You can also look into Point Sprites.

If you're using Direct3D 10/11, you can use geometry shaders to create the particles on the GPU.
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "

If you're using Direct3D 9, you should probably stick to the CPU. You can also look into Point Sprites.

If you're using Direct3D 10/11, you can use geometry shaders to create the particles on the GPU.


I guess im going to have to start digging in directX 11 *sad face*

I guess im going to have to start digging in directX 11 *sad face*


these tutorials may benefit you,
this one in particular.

EDIT: I'm not sure he does it through the GPU but finding example code on geometry shaders shouldn't be too difficult
You can simulate particles on the GPU with D3D9, as long as the GPU supports either vertex texture fetch or render-to-vertex-buffer (a custom ATI extension). You just render to a grid of pixels/vertices representing particles, and in the pixel shader you update the state of each particle. Then in a separate step you can render them as point sprites. With D3D11 you can of course do this much more elegantly and efficiently with compute shaders.
You could put them all into a single static vertex buffer per emitter type, containing their initial properties (such as position - relative to 0|0|0, velocity, etc). One entry in this per particle. Create a second vertex buffer containing 4 sets of texture coordinates (one for each vertex of a quad). Set up a vertex declaration for this. Call your SetStreamSource and SetStreamSourceFreq appropriately. Send the emitter's position and time elapsed to your vertex shader as constants. Draw using instancing. Your vertex shader will add the emitter position to the particle position, then run the result through a standard gravity/velocity/time equation to get the position to draw at, and finally expand to a quad (you can get clever and use the texture coord buffer to help with this part). Write the result to your vertex shader output and the pixel shader runs as normal.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement