4.7. Particles

Particles are a special kind of graphical effect. Conceptually they are cubes in the game world, i.e., they have a 3D position and size, but their orientation is constrained to face the direction of the camera (and optionally to be rotated around the vector to the camera). Although they are conceptually 3D, they are rendered with textured 2D quads that face the camera. The shader uses the screen depth to soften their intersection with other geometry in the scene.

Particles are typically used to render certain types of volumetric gas-like effects like smoke, clouds, kicked up dirt, flames, and explosions. Each particle is a fixed, roughly spherical shape, but with a cloud of particles, the overall shape can be roughly approximated.

Although the term "particles" implies that there should be a large number of small particles, typically this is not the case. Particles are reasonably heavy to render and you don't want to have too many behind each other in the case of alpha particles because that causes a lot of overdraw.

Use just enough particles to represent your 3D shape. The key to particles is to use a great looking (preferably animated) texture, and then write enough behaviour into that particle class, that a cloud of particles together resemble what you want.

There are a number of particles defined in /common, which you can spawn in your own code. Typically a particle is created at a given location, possibly with customised values for some other parameters , and then from that point on it is in charge of its own destiny, including destroying itself. Particle behaviour can be arbitrarily complex, performing physics tests or interacting with objects in the scene. They can even spawn more particles.

(TODO: The particles API needs some cleanup before it is worth documenting.)

To create your own particles, define a Particle Class in Lua scripting, which provides the references textures, default fields, and provides a stepCallback to implement the behaviour of the particle.

Particle texture coordinates are used to implement animation. When defining a particle, a list of coordinates are given, one for each frame.

Particles have a number of other attributes that define their appearance: colour, alpha, position, angle, and size.