Jump to content

  • Log In with Google      Sign In   
  • Create Account


Like
0Likes
Dislike

Fire Special FX

By Seumas McNally | Published Sep 14 1999 12:15 PM in Graphics Programming and Theory

If you find this article contains errors or problems rendering it unreadable (missing images or files, mangled code, improper text formatting, etc) please contact the editor so corrections can be made. Thank you for helping us improve this resource

Pixel buffer "burn" or "fire" effects are fairly straightforward. In a nutshell they are a mutated box filter applied every frame to a bitmap with a ramping palette proceeding from black at 0 to some desired "hot" color at 255. For each pixel (skipping a few towards each edge), add the values of the pixel itself, plus the pixels to the right, to the left, and below, then divide by 4, subtract a fade-out constant, and write the value back into the buffer. Notice that the pixel above is ignored, which causes the blurring to propogate upwards, creating an effect that looks like fire or steam. Here is some C sample code (untested and probably incomplete):

Assumptions: Data is unsigned char pointer to bitmap, Width and Height are dimensions, and Pitch is bytes between rows (often just Width). DONTBURN is number of edge pixels to skip. BURNFADE is speed to fade out buffer.

int pixel;
unsigned char *line; //Pointer to start of current line.
for(y = DONTBURN; y < Height - DONTBURN; y++)
{
   line = Data + y * Pitch;
   for(x = DONTBURN; x < Width - DONTBURN; x++)
   {
  	pixel = ((line[x] + line[x - 1] + line[x + 1] +
          	line[x + Pitch]) >>2) - BURNFADE;
  	line[x] = (pixel < 0 ? 0 : pixel); //Don't write < 0.
   }
}

This is highly simplified, and doesn't include handy optimizations such as using 32-bit integer or 64-bit FPU reads to quickly skip over burning large chunks of the buffer that are all 0. That's left as an exercise for the performance programmer. :)

April 13th Update:

Here are a couple of other interesting things that Particle Fire does to achieve its effects. The "sparklies" in the darker flame are produced by simply iterating over each line of the buffer, selecting one random X pixel along that line, testing it to see if it is darker than a certian threshold, and if it is, it brightening it by writing a slightly lighter color into the buffer. The wall of flame along the bottom or top is produced by simply setting pixels in the furthest top or bottom burnable line of the buffer each frame. Two algorithms are used, a mostly random one where each pixel can change up or down by a random amount each frame, and a more ordered 1-dimensional Perlin Noise functions that produces a much "smoother" flame.

Copyright 1998-1999 by Seumas McNally.
No reproduction may be made without the author's written consent.


Courtesy Of Longbow Digital Artists





Comments

Note: Please offer only positive, constructive comments - we are looking to promote a positive atmosphere where collaboration is valued above all else.




PARTNERS