The sample program this time is on cross-fading. The reason for this is that many people have commented that I should be moving over to a few basic demo effects now that we have most of the basics of VGA programming.

DENTHOR, coder for ...
_____   _____   ____   __   __  ___  ___ ___  ___  __   _____
/  _  \ /  ___> |  _ \ |  |_|  | \  \/  / \  \/  / |  | /  _  \
|  _  | \___  \ |  __/ |   _   |  \    /   >    <  |  | |  _  |
\_/ \_/ <_____/ |__|   |__| |__|   |__|   /__/\__\ |__| \_/ \_/
The great South African Demo Team! Contact us for info/code exchange!  

Grant Smith, alias Denthor of Asphyxia, wrote up several articles on the creation of demo effects in the 90s. I reproduce them here, as they offer so much insight into the demo scene of the time.

These articles apply some formatting to Denthor's original ASCII files, plus a few typo fixes.

What is a “Crossfade”?

This is a simple question. When you are watching a TV program, you will often see one picture on the screen, which slowly fades to a new picture, with the new picture becoming more and more prominent and the old one becoming less and less prominent. This is a crossfade. Easy huh?

Perhaps, but it is not that easy to code on a computer…

In most demos, there is a crossfade of two colors, black and white, for example: The words ‘MYDEMOTEAM’ appears in large with letters, then crossfades to ‘PRESENTS’ in large white letters.

I decided to allow the programmer to have a bit of color to his crossfade, and the sample program can handle a many color crossfade.

How does a crossfade work?

Here comes the clever bit.

To do a crossfade, we load in two pictures, FROM and TO. Then, for every pixel in which they are different, put a new pixel in a third screen.

For example, wherever there is pixel color 9 on screen 1 and pixel color 45 on screen 2, put pixel color 1 on the third screen. You then repeat this for all combinations of pixels on screen one and two, and put the results into screen 3. Here it is in ASCII:

  Screen 1     Screen 2     Screen 3
   .1...        .3...        .1...
   .....        ..2..        ..2..
   ...8.    +   ...1.    =   ...3.
   .1...        ....2        .4..2

Note how the values on screen 3 are sequential? We keep a count for this… The two “2”’s on screen 3 are identical, so we do not use a new color for it…

We also keep two palettes … source and dest.

For the above example source[1] would be the palette of 1 in screen 1, and dest[1] would be the palette of 3 in screen 2 (Note that screen 1 and screen 2 have different palettes)

When we are finished with the picture, we flip screen 3 to the VGA and do the following: move the palette from source to dest or vice versa. That’s it. No fancy screen manipulations for the crossfade, we just change the palette. Cool, huh? It also means that you can be doing fun stuff in the foreground with unused palette colors without your program executing at two frames per second ;)

The sample program is fully documented, and you shouldn’t have a problem deciphering it… If you ever use this effect in a demo or game, greet me! :-)

Problems with crossfades

The main problem with crossfading is this: there may only be 256 colors on screen 3, in other words, only 256 combinations of colors. In the sample program, if you load up two pics with more than 256 combinations, the program gives an error message and exits to DOS. To sort this problem out, you can do two things: reduce the number of places where the two pictures intersect, or squeeze down the palette, using Autodesk Animator’s “SQUEEZE” command. This reduces the number of colors used by the picture, and therefore reduces the number of combinations. The picture does however lose a bit of quality.

The second problem with crossfading is this: it hogs most of the colors. Whatever you want to do in the foreground, make sure you do it with as few colors as possible.

In closing

So, what do you think? Should I continue with demo effects, or should I find more basic things to do? Perhaps I should stop and just do sound coding from now on? It is up to you, so leave me mail.

You will notice that the sample program can load in any .CEL files, you needn’t be restricted by the ones I have given you. Try crossfading a few of your own pictures and see how it turns out. The picture of the robot was draw by Fubar for our demo Psycho Neurosis, and I then squeezed down the palette somewhat in order for the crossfade to work. The word “ASPHYXIA” was drawn by me, also in Autodesk Animator.