Drawing particles with CPU instead of GPU (XNA)

Posted by Helix on Game Development See other posts from Game Development or by Helix
Published on 2011-02-01T18:03:25Z Indexed on 2011/02/01 23:35 UTC
Read the original article Hit count: 383

Filed under:

I'm trying out modifications to the following particle system. http://create.msdn.com/en-US/education/catalog/sample/particle_3d

I have a function such that when I press Space, all the particles have their positions and velocities set to 0.

for (int i = 0; i < particles.GetLength(0); i++)  
{  
    particles[i].Position = Vector3.Zero;      
    particles[i].Velocity = Vector3.Zero;  
}

However, when I press space, the particles are still moving. If I go to FireParticleSystem.cs I can turn settings.Gravity to 0 and the particles stop moving, but the particles are still not being shifted to (0,0,0).

As I understand it, the problem lies in the fact that the GPU is processing all the particle positions, and it's calculating where the particles should be based on their initial position, their initial velocity and multiplying by their age. Therefore, all I've been able to do is change the initial position and velocity of particles, but I'm unable to do it on the fly since the GPU is handling everything.

I want the CPU to calculate the positions of the particles individually. This is because I will be later implementing some sort of wind to push the particles around. How do I stop the GPU from taking over? I think it's something to do with VertexBuffers and the draw function, but I don't know how to modify it to make it work.

© Game Development or respective owner

Related posts about XNA