This week I’ve been working on a particle system for my Engine. As my artistic skills are somewhat lacking I’ve been planning on using alot of particle effects to try and make the game look good. I’m hoping by having good looking particle effects for everything from explosions to shooting stars in the background it can stop the game from looking bland. Due to this, having a versatile and efficient particle system is fairly important to the project.


The first thing I considered was that to have such a wide variety of particle effects they needed to be as customisable as possible. I decided upon a system where each particle effect would have multiple stages. The first stage would always be the “emission” stage, where a particle is created. There can be several types of emitter, for example a Box Emitter in which a particle is randomly created anywhere with a specified box in 3D space. Custom Emitters can easily be added. Each stage after this is referred to as a “Phase”. A phase it built out of multiple “affectors” which each act upon a differing property of the particle. For example there are Velocity Affectors which change the position of the particle by velocity, Scale Affectors which affect the scale of the particle and of course there are many others. In addition custom affectors can easily be defined allowing for very specific particle behaviours.


Of course a versatile particle system is only good if its efficient so I implemented a nice batch renderer for the particles. This used the cheap billboarding method of building the vertices of the quad using the “up” and “right” vectors pulled from the View Matrix. When run however, I was only managing to get about 50 particles only screen before heavy slow down began to occur. This took me a good amount of hair pulling to solve. In the end it turns out that DynamicVertexBuffers on anything other than PC’s (so this applys to Xbox as well as WP7) are very inefficient. I had been using DynamicVertexBuffers for any data that was changing on a frame by frame basis thinking that this was logically the most efficient way to do it. Instead SendData() was causing a large bottle neck. It seems that sending data each frame using DrawUserIndexedPrimitives is significantly more efficient. Where I had been getting 50-100 particles at 13-14 frames per second(with rendering the rest of my scene of course) I am now getting 1500-2000 at 23-25 FPS. A significant improvement :D.


The last thing I had to do here was to make particle effect development as easy as possible. I have plans to make a particle effect tool in the future, but for the time being simply making it data driven will have to do. After realising that simple config files would not really be a suitable method of representing this system I took the advice of a colleague at Tag and used a XML/Config hybrid. XML tags are used to break up each section and to retain customisablity but key-value lists are used to represent data for readability. This would look something like this:

 
<ParticleEffect>
    <Emitter Type=”Sphere” MaxParticles=”10″>
        Radius = 3
    </Emitter>
    <Phase MinLifetime = “1.0″ MaxLifetime=”2.0″>
    <Images>
        CircleImage
    </Images>
    <Affector Type = “Velocity”>
        MinVelocityX = 1.0
        MinVelocityY = 1.0
        MinVelocityZ = 1.0
        MaxVelocityX = 2.0
        MaxVelocityY = 2.0
        MaxVelocityZ = 2.0
    </Affector>
    </Phase>
</ParticleEffect>


Now that I’ve got all the basic functionality for the engine working my next task is tidying up the game code and starting to make the actual game. I’m hoping to have a basic example level created by next week. Finally, heres a screenshot of some random test particles :)