
        
                  -= Demo Programming Series =-
                      by Sten Roger Sandvik
     
                  I - HOW TO CREATE PLASMA EFFECTS
     
                     (c) 1994 by X3M Productions
        


  Hey all out there, and welcome to part one of the X3M demo programming
  series. In this and all of the following demo programming series, I'll
  take it for granted that you know how to program the VGA controller,
  and some knowledge about X-mode.

  This time we'll discuss a psychadelic effect that is used in many demos.
  Yepp! You got it... Plasmas! Oki, no sence in wasting time here talking
  about bullshit... let's go to work!


   The Workings of Plasmas

    In this text I will only cover the real type of plasma. No sills here,
    only state-of-the-art realtime plasma calculations!

    When you look at the method realtime plasmas is created, you'll see that
    it's merely an intersection of a number of cosinus waves. In this example
    we'll use 4 cosinus waves, which makes a very cool effect. The color of
    a particular point is calculated using this formula:

        color = costbl[cos_1]+costbl[cos_2]+costbl[cos_3]+costbl[cos_4]

    The trick is getting the four indexes of that cosinus table to create
    something that looks neat. We use two of the indexes for vertical
    movement, and the remaining two for horizontal movement.

    This means that by changing these valuse we can move along the plasma.
    To draw an individual screen, we pass the values of the four to another
    four so that we do not disturb the original values. For every pixel on
    the x-axis, we add values to the first two indexes, then displaying the
    next pixel. For every row down, we add values to the second two indexes.

    By altering the original four values, we can get all sorts of neat
    movement and cycling of the plasma. The reason we use a cosinus function
    is as follows:

        - Nice curvature.
        - Adding two or more together it's posible to get circular
          pictures.


 Fading

    When you look at the sample demo, you'll see that when it fades in and out
    the colors all reach their destination at the same time. This is wery
    clever, if I may say so ? Well, in other words, they do not all increment
    by one until they hit the right color. If you should do it this way the
    fading looks extremely unproffesional.


 How to do a step-crossfade

    Each red, green and blue values can be between 0 and 63. Have the palette
    we want to get to in TOPAL and the temporary palette in TEMPPAL. For each
    step, from 0 to 63 do the following:

        TEMPPAL[loop].red   = TOPAL[loop].red   * step / 64;
        TEMPPAL[loop].green = TOPAL[loop].green * step / 64;
        TEMPPAL[loop].blue  = TOPAL[loop].blue  * step / 64;

    That means if we are halfway through the crossfade (step=32) and the red
    value is meant to get to 16, then naturally the color would be value
    would be 8, which is half the way. This means all colors will fade in/out
    with the same ratios.


 Palette rotating

    The palette rotating is very simple, so here is a brief description on
    how to do it.

        - Move color 0 into a temporary variable.
        - Move color 1 into color 0
        - Move color 2 into color 1
          .
          .
        - Move color 255 into color 254
        - Move temporary color into color 255


 About the sample demo

    The plasma sample demo code is written in pascal, and is (I think) self
    explanitory. I have also done an assembly version that you can look at,
    but the pascal code illustrates the plasma principle very clearly.

    Well if you have any questions about anything (Uhh... well about
    programming), just leave me a note. Be seein' YA!

                                                 E-mail -> srs@alkymi.unit.no


 ZIP file contents:

    PLASMA.TXT          - The file you are looking at NOW!
    PLASMA.PAS          - Pascal version of the sample code
    PLASMA.EXE          - Executable version of the pascal version (Huh ?)
    COSTBL.INC          - Cosinus table file for the assembler version
    PLASMEFF.ASM        - Assembler version of the sample code (FAST!)
    PLASMEFF.EXE        - Executable version of the assembler version!

