Previous Contents Next

Chapter 19   Rendering Natural Effects

19.1   Particle Systems

Particle systems are a method for modeling fuzzy objects such as fire, clouds, and water. Particle systems model an object as a cloud of primitive particles that define its volume. Over a period of time, particles are generated into the system, move and change form within the system, and die from the system. The resulting model is able to represent motion, changes of form, and dynamics that are not possible with classical surface-based representations. The particles can easily be motion blurred, and therefore do not exhibit temporal aliasing or strobing. Stochastic processes are used to generate and control the many particles within a particle system.

Modeling phenomena such as clouds, smoke, water, and fire has proved difficult with the existing techniques of computer image synthesis. These ``fuzzy'' objects do not have smooth, well-defined, and shiny surfaces; instead their surfaces are irregular, complex, and ill defined. We are interested in their dynamic and fluid changes in shape and appearance. They are not rigid objects nor can their motions be described by the simple affine transformations that are common in computer graphics.

A particle system is a collection of many minute particles that together represent a fuzzy object. Over a period of time, particles are generated into a system, move and change from within the system, and die from the system. To compute each frame in a motion sequence, the following sequence of steps is performed:

  1. new particles are generated into the system
  2. each new particle is assigned its individual attributes
  3. any particles that have existed within the system past their prescribed lifetime are extinguished
  4. the remaining particles are moved and transformed according to their dynamic attributes,
  5. an image of the living particles is rendered in a frame buffer.
The particle system can be programmed to execute any set of instructions at each step. Because it is procedural, this approach can incorporate any computational model that describes the appearance or dynamics of the object. For example, the motions and transformations of particles could be tied to the solution of a system of partial differential equations, or particle attributes could be assigned on the basis of statistical mechanics. We can, therefore, take advantage of models which have been developed in other scientific or engineering disciplines.

19.1.1   Particle Generation

Particles are generated into a particle system by means of controlled stochastic processes. One process determines the number of particles entering the system during each interval of time, that is, at a given frame. The number of particles generated is important because it strongly influences the density of the fuzzy

object. The model designer can choose to control the number of new particles in one of two ways. In the first method, the designer controls the mean number of particles generated at a frame and its variance. The actual number of particles generated at frame f is:

Nf=Meanf+Rand× Varf

where Rand is a procedure returning a uniformly distributed random number between -1.0 and +1.0, Meanf the mean number of particles, and Varf its variance. In the second method, the number of new particles depends on the screen size of the object. The model designer controls the mean number of particles generated per unit of screen area and its variance. The procedural particle system can determine the view parameters at a particular frame, calculate the approximate screen area that it covers, and set the number of new particles accordingly. The corresponding equation is:

Nf=(Mean
 
saf
+Rand× Var
 
saf
ScreenArea

where Meansaf is the mean per screen area, Varsaf its variance, and ScreenArea the particle system's screen area. This method controls the level of detail of the particle system and, therefore, the time required to render its image. For example, there is no need to generate 100,000 particles in an object that covers 4 pixels on the screen.

To enable a particle system to grow or shrink in intensity, the designer is able to vary over time the mean number of particles generated per frame.

19.1.2   Particle Attributes

For each new particle generated, the particle system must determine values for the following attributes:

  1. initial position
  2. initial velocity (both speed and direction)
  3. initial size
  4. initial color
  5. initial transparency
  6. shape
  7. lifetime
Several parameters of a particle system control the initial position of its particles. A particle system has a position in three-dimensional space that defines its origin. Two angles of rotation about a coordinate system through this origin give it an orientation. A particle system also has a generation shape which defines a region about its origin into which newly born particles are randomly placed, such as a sphere of radius r, a circle of radius r in the x-y plane of its coordinate system, and a rectangle in the x-y plane of its coordinate system.

The generation shape of a particle system also describes the initial direction in which new particles move. In a spherical generation shape, particles move outward away from the origin of the particle system. In a circular or rectangular shape, particles move upward from the x-y plane, but are allowed to vary from the vertical according to an "ejection" angle.

To determine a particle's initial color, a particle system is given an average color, and the maximum deviation from that color. Particle transparency and particle size are also determined by mean values and maximum variations.

19.1.3   Particle Dynamics

Individual particles within a particle system move in three-dimensional space and also change over time in color, transparency, and size. To move a particle from one frame to the next is a simple matter of adding its velocity vector to its position vector. To add more complexity, a particle system also uses an acceleration factor to modify the velocity of its particles from frame to frame. With this parameter the model designer can simulate gravity and cause particles to move in parabolic arcs rather than in straight lines.

A particle's color changes over time as prescribed by the rate-of-color-change parameter. The transparency and size of particles are controlled in exactly the same way.

19.1.4   Particle Extinction

When it is generated, a particle is given a lifetime measured in frames. As each frame is computed, this lifetime is decremented. A particle is killed when its

lifetime reaches zero. If the intensity of a particle, calculated from its color and transparency, drops below a specified threshold, the particle can also be killed.

19.1.5   Particle Rendering

Once the position and appearance parameters of all particles have been calculated for a frame, the rendering algorithm makes a picture. The general particle-rendering problem is as complicated as the rendering of objects composed of the more common graphical primitives, such as polygons and curved surfaces. Particles can obscure other particles that are behind them in screen depth. They can be transparent and can cast shadows on other particles. Furthermore, particles can coexist in a scene with objects modeled by surface-based primitives, and these objects can intersect with the particles.

19.1.6   Particle Hierarchy

Particles can themselves be particle systems. When the parent particle system is transformed, so are all of its descendant particle systems and their particles. A hierarchy can be used to exert global control on a complicated fuzzy object that is composed of many particle systems. For example, a cloud might be composed of many particle systems, each representing a billowing region of water particles. A parent particle system could group these all together and control the cloud's global movement and appearance as influenced by the wind and terrain.

19.2   Rendering Fire and Explosions

A particle system can be used to model fire effects. All particles must be predominantly red in color with a touch of green. Particles are treated as point light sources and that colors are added, not matted, into a pixel. When many particles covered a pixel, as was the case near the center and base of an explosion, the red component was quickly clamped at full intensity and the green component increased to a point where the resulting color was orange and even yellow.

Thus, the heart of the explosion had a hot yellow-orange glow which faded off to shades of red elsewhere. Actually, a small blue component causes pixels covered by very many particles to appear white. The rate at which a particle's color changes simulates the cooling of a glowing piece of some hypothetical material.

Particles are killed when their lifetimes expire or when their intensity falls below the minimum intensity parameter.

Particle systems can be used to model fireworks. The fireworks differ in that the control parameters of the particle systems vary more widely, and streaking is more predominate.

The rendering routine for a fire particle is illustrated in Code Example 22. Particles are rendered as spheres, becoming increasingly transparent as their lifetimes come to an end. The blending is also used to combine the light from particles occupying the same pixel. Movement is according to the initial motion vector, with an additional upwards acceleration. The resultant fire is illustrated in Figure 19.1.



Figure 19.1: Particle System Fire



Code Example
*  

class FireParticle : public Particle

  {

     public:

      virtual void Move ()

         {

           x += vx;

           y += vy;

           z += vz;

           vy += 0.000001;

         }

       virtual void Draw ()

         {

           glEnable (GL_BLEND);

           glBlendFunc (GL_SRC_ALPHA, GL_ONE);

           GLUquadricObj * obj = gluNewQuadric ();

           glPushMatrix ();

             glTranslatef (x, y, z);

             glColor4f (r, g, b, (double) (lifetime) / 200.0);

             gluSphere (obj, 0.01, 4, 4);

           glPopMatrix ();

           gluDeleteQuadric (obj);

         }

  };

19.3   Plants

19.3.1   Grass

To model grass, use an explosive type of particle system.Instead of drawing particles as little streaks, the parabolic trajectory of each particle over its entire lifetime is drawn. Thus, the time-domain motion of the particle is used to make a static shape. Grass-like green and dark green colors are assigned to the particles which are shaded on the basis of the scene's light sources. Each particle becomes a simple representation of a blade of grass and the particle system as a whole becomes a clump of grass. Particle systems randomly placed on a surface and overlapping one another are used to model a bed or patch of grass.

Variations on the particles motion, and rendering functions to produce a simple grass rendering are shown in Code Example 23. Clearing of the buffer is disabled, to allow the entire trajectory of the particle to form one of the blades. A gravity like acceleration is applied to make the leaves bend downwards, with a restriction added to prevent them passing through the ground. Line width is varied to allow the leaves to taper towards the tips.


Code Example
*  

class GrassParticle : public Particle

  {

     double ox;

     double oy;

     double oz;

     double init;

 

     GrassParticle () : Particle ()

       {

         init = 0;

       }

     virtual void Move ()

        {

          init = 1;

          ox = x;

          oy = y;

          oz = z;

 

          x += vx;

          y += vy;

          z += vz;

          vy -= 0.00002;

 

          if ((vy < 0) && (y < -0.5))

            lifetime = 0;

        }

      virtual void Draw ()

        {

          if (init)

            {

              glEnable (GL_LINE_SMOOTH);

              glColor3f (r, g, b);

              glLineWidth ((double) lifetime / 30.0);

              glBegin (GL_LINES);

                glVertex3f (ox, oy, oz);

                glVertex3f (x, y, z);

             glEnd ();

           }

        }

  };

The appearance of the grass clumps can be adjusted by changing the number of particles, and the area over which they are generated. Several variations are shown in Figure 19.2.




Figure 19.2: Grass produced using a particle system.


19.4   Unscripted Motion

When modelling large complex natural situations, it becomes tedious to have to specify the trajectory of every one of thousands (or millions) of entities. Instead, some form of rule based behaviour can be implemented which attempts to duplicate the natural behaviour of a class of organism.

19.4.1   Flocking

Flocking occurs in nature and is exhibited by birds, fish and some insects. The sight of a migrating flock of birds is one we are all familiar with. A flock of birds gives the appearance of a larger entity and dissuades attackers. If a flock or swarm is attacked, the survivors can scatter and regroup at a safe distance. This scattering can confuse predators and prevent them from capturing more than one or two members of the flock. The three rules that implement flocking are:

  1. Cohesion: Each boid shall steer to move toward the average position of local flockmates.
  2. Alignment: The boids will align to the direction their neighbours are travelling.
  3. Separation: All boids in the flock will maintain a separation distance from their siblings.
The effect of these rules when implemented in multiple mobile agents is to cause flocking or swarming. Removing or disabling one of the rules removes the apparent cooperation between swarm entities and makes flocking impossible.

For each detectable neighbour or barrier

  If that neighbour is a sibling 

  (of the same colour) then 

    the target point is a weighted 

    average of alignment and either 

    attraction, or repulsion if 

    the boid is too close.

  Else if the neighbour is of another 

  colour or a Barrier, 

    the target point is in the opposite 

    direction to the other Bird or Barrier 

When all the detectable boids have been accounted 

for, take a weighted average of the various 

target points.

Move towards this point. 

19.4.2   Motion Control

Motion controllers can be used to convert a sequence of primitive movements (move forward, turn left) into goal directed behaviour. Motion control will respond to stimuli in the environment, such as movement toward food and light sources, and away from predators. Motion control can be affected by the organisms state of mind: variables such as hunger, libido and fear will be used to weight the effect of environmental stimuli. Individuals can develop by setting thresholds and rate changes for each organism.


Previous Contents Next