Particle Systems in Damut Dan
The Unreal Engine
The particle systems in Damut Dan are largely inspired by the particle systems in the Unreal Engine. Mine have a lot less features, but the two systems do have a few things in common.
Like Emitters in the Unreal Engine, my particle systems use the idea of 'steps' or 'scales'. These are essentially lists of values that act as animations for particle properties over time.
There might be a list of color steps, for instance, that describe the color of each particle over the course of its lifetime.
When to use Steps
Particle steps are effing awesome, but they're expensive. 'Animating' particle properties for thousands of particles every frame can really drag the frame rate down. That being the case, I had to be very selective about which particle properties could use steps, while allowing myself to convert properties to or from steps in the future, if need be.
Properties that are Difficult to Animate
Another potential problem with particle steps is that some properties are hard to animate. Take velocity for example. Now animating velocity by itself is not so hard, but applying acceleration (such as gravity), and external forces (wind, explosions), makes calculating the end result of a particle's animated velocity at a given time pretty complex, at least for a person with my math skills.
Effects and Systems
At a level higher than particle systems are 'particle effects'. A particle effect in Damut Dan is simply a collection of particle systems and data describing when and where to spawn and update those systems.
So an explosion effect might consist of an initial fiery explosion system, a spark-throwing system, and, later, a smoke billowing system.
This is really just provided as a convenience to the artist. We're going to want complex particle system combinations anyway, so we may as well make it a part of the creation process.
The idea of having the effect class was inspired largely by TGB's particle systems, although I think the Unreal Engine has a similar concept (along with probably a million other games and engines).
Another concept borrowed from the Unreal Engine was that of emitting shapes or volumes. These are basically just geometries that describe the area in which particles are emitted.
Currently, I support disks and rectangles. Disks are specified with an inner and outer radius, as well as a minimum and maximum angle. Rectangles are just specified with a width and height, although I may add an inner width/height or an angle if the need arises.
There are also 2 kinds of particle velocities - radial and linear. Linear velocity is described using normal vectors with a direction and a magnitude. Radial velocity, on the other hand, only specifies a magnitude. The direction of each particle's radial velocity is calculated by subtracting its starting position from the center of the emitting area. (I'm sorry if this doesn't actually have anything to do with the term 'radial'. It just sounded so cool.)
Radial velocity is typically used in tandem with disk emitting shapes - to allow particles to be thrown outward from the disk, or inward toward its center (using a negative magnitude), although there is no restriction on their usage.
Everything is not an Object?
I mentioned in my previous post, that I'm trying to represent everything on the screen as dynamic objects.
I thought of representing particles themselves as dynamic objects, but decided not to for performance reasons. It would be really awesome to have a level rain real cats and dogs using a particle system, but I don't know how often anyone would really use a crazy feature like that.
Dynamic objects are pretty large, and they do lots of things every frame. Spawning thousands of them every frame, just to represent smoke or sparks would be pretty asinine.
I might later add another parameter to the particle system template class that describes whether the system spawns normal particles or dynamic objects, thus allowing 90% of our particle systems to inherit the performance benefits you get when dealing with small particles, and at the same time give us the power to spawn fluttering butterflies as blood spurts. But that's on the wish list for now. (Did I mention I have overly high ambitions?)
And so on
I could probably say a lot more about the particle systems in Damut Dan, but... well, lets just say I'm doing you a favor.
In short, I've tried to create particle systems that allow as many features as possible at the lowest possible cost, and I've done so borrowing the creative knowledge of many other game developers.
I need my particle systems at a low cost because I want particle systems everywhere in Damut Dan. I want particle system-y explosions sending bloody gibs soaring across the screen, on fire, emitting smoke, splattering when they hit the walls. [inlove]