Jump to content
  • Advertisement
  • Remove ads and support GameDev.net for only $3. Learn more: The New GDNet+: No Ads!

  • 09/14/99 06:15 PM
    Sign in to follow this  

    Fire Special FX

    Graphics and GPU Programming

    Myopic Rhino
    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


      Report Article
    Sign in to follow this  


    User Feedback


    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!