Fading colors

=Palette fade=

Real-time
Palettes can be faded to white or black by respectively incrementing or decrementing each color component of each color individually. Of course, care has to be taken so that each value stops at 31 or 0.

Fading to a specific color can also be done this way, by comparing each color components with the target ones and incrementing/decrementing them accordingly (see example code).

Pre-computed
Real time fading is very flexible but also very CPU intensive. Another way to fade palettes is to pre-compute all the steps and store them into ROM for simple lookup. This method requires very little CPU but uses more ROM space.

=Simulated fade=





Since it has the highest priority on the screen, the fix layer can be used to fade the underlaying display by using dithered tiles as a mask. This can only be used if the fix doesn't have to show important information during fading.

This is also used in Metal Slug 3 for wiping transitions between levels sections.

=Real-time fading code=

RGB components can then be compared with a target palette in RAM and adjusted until they match, for example: