Fire Special FX

Published September 14, 1999 by Seumas McNally, posted by Myopic Rhino
Do you see issues with this article? Let us know.
Advertisement
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. :)

[size="5"]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.

[size="2"] Copyright 1998-1999 by Seumas McNally.
No reproduction may be made without the author's written consent.

Courtesy Of Longbow Digital Artists
Cancel Save
0 Likes 0 Comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement