This project is read-only.

Particle System

Mar 25, 2009 at 8:01 PM
Hey - firstly thanks for all the work you've put into this framework - it's a great abstraction over XNA.  
I've been learning how to use the particle system (which is superb) but can't figure out how to change the number of particles emitted at run time.  I can use the 16 global variables to adjust particle properties once they have been emitted but don't seem to be able to change the number emitted - it looks as though the loop count can only be set in the XML.  Is there a way to set this from the application?
Many thanks.
Mar 26, 2009 at 12:37 AM
Hi. The way to do this would be using Triggers (which are used for the 'particle bursts' in tutorial 23).
They are similar to a frame emitter, but triggered by the application at will.
There are also Toggles, but these can only be turned on and off.

One of the limitations of the particle system, is that is pre-allocates it's textures and resources. So it can't increase it's capacity at runtime. For this reason there are limits to how much flexibility can be provided for dynamic particle emitting.

Apr 1, 2009 at 3:29 AM
I have been trying to learn how to use the particle system you have created and honestly its a very impressive xml abstraction over GPU shader particles. I am a little overwhelmed at the moment though. Maybe someone here can give me little a nudge in the right direction.

I would like to implement bullets/projectiles using the particle system. I know that I will need to use triggers similar to those in tutorial 23. I don't know how to go about it though.

Is it possible to get/set the position of a single particle from code outside the XML file? Lets say I wanted to check if the bullet has collided with anything in the world. How would I get its position? What if it does collide with something... how do I "kill" the particle and its smoke trail? Should the bullet/missile/projectile be defined in a different xml file than its trail?   

Any comments would be awesome!
Apr 3, 2009 at 7:14 PM
After a bit of looking around, I don't think its possible to interact with a trigger particle after it has been fired...  I cannot find any method of sending a user value to an active particle system. =(

Apr 3, 2009 at 10:29 PM
It is by design that you cannot read back data from a particle system. This pretty much cannot be done efficiently with a gpu system.
And no, once a particle is fired you cannot interact with it. This is also intended as it would make certain parts of the system significantly more complex.

So, for the bullet example, you'd simply have to use something else. Say, a SpriteElement if it's 2D. This isn't such a bad situation, and would actually be more efficient for a number of reasons (assuming particle systems were read/write).

You can always use the particle system for the impacts effects and other things that don't need to be tracked.

Apr 3, 2009 at 11:34 PM
Thanks for the reply!
I absolutely understand that reading back textures from the GPU is costly. It would be nice if I could send a few global floats to the shader though...

A projectile system could still be implemented on the GPU using your particle system. Some modifications would need to be made though.

For instance the application could keep track of position/velocity of each bullet. Each time the particle system logic is updated on the GPU the CPU can update the projectile position as well and since bullets usually travel in a straight line this would mean that the application could do collision detection. On a collision the CPU could kill the projectile on the GPU causing its vapour trail to die as well. Yes this is a little dirty but you would not need to send textures back and forth. 

Also, GPU collision detection is not impossible... but my past experiances with it have been rather unpleasent. Heres a nice article if anyone is intrested:

Like I have said before, your work is outstanding and I would love to use it but I really need a projectile system and I am not sure if I would be better off starting from scratch or using xen.
Apr 4, 2009 at 9:00 PM
I too will need a projectile system sooner or later, and this is how i imagined it:
A particle system is clearly a visual thing. It should have nothing to do with position updates or collision.
I will likely have a bullet/projectile class that wraps a collision primitive registered with a physics system, and have a particle system attached to it with a trigger that will keep triggering particles each frame at the projectile's current location as long as the object is alive.
I am not there yet so i dont know if this works, but it should.
Apr 5, 2009 at 3:33 AM
Yes that is the intended way to do it. You are correct in that particle systems are there for visual effects, they are not intended to be used for calculating things.
Just make sure you don't create a particle system instance of every single bullet! :-)
Apr 5, 2009 at 5:27 AM

I thought about doing the same thing but one limitation is that you are restricted in how you can use velocity billboards since the particle(s) are not actually moving very much...  I guess we'll just need to be creative.
Apr 5, 2009 at 5:35 AM
Edited Apr 5, 2009 at 9:15 AM

Using a particle system to display things like bullets, which are heavily game controlled, is not a good idea. If you find yourself trying to control individual particles, then chances are there is a better way to do it.
Using another drawing method is far more practical in such a case. Remember that a ParticleSystem simply provides data, it does not draw the particles.

However, having particles firing from the bullet's position (eg; a trail of particles behind the bullet) would work quite well.
Game specific problems like these almost always have several possible solutions, each with pros and cons.