A common trick in NES games is to fade a palette to black, and back, by progressively ANDing the correct palette values with a bitmask such as 3F, 2F, 1F and 0F.
An example of such game is Simon's Quest, as shown in the screenshot below.
This algorithm is cheap and easy to implement. However, it is restricted into fading through from/to black, which is why the game fades through black.
However, if one wants to fade between two arbitrary palettes, things are not so easy. Has anyone attempted it?
I can think of an algorithm, which is not cheap:
Precalculate a 64x64x4 array of values and place it in a vacant ROM page. It takes 16384 bytes (4000h). Key 1 is the source palette value, key 2 is the target palette value, and key 3 is the degree of interpolation (20%, 40%, 60%, 80%). An program populates the array by determining which NES color index most closely resembles the given mixture of NES colors.
Fading the palette is a matter of reprogramming the palette six times:
First, with the source palette (srccolor) (is optional).
Then four times with table[srccolor][dstcolor][i] for each color in the screen palette.
And finally with the target palette (dstcolor).
Resourcewise, it is not cheap.
It could be made smoother by including fewer degrees of interpolation (such as one: 50% or two: 33% and 67%): This would take 1000h or 2000h bytes respectively. Additional degrees of interpolation could be synthesized at runtime by flickering between the previous and the next value in the table. Such flickering might not look nice, though.
Are there other, perhaps better algorithms for arbitrary palette fades on NES?
(Screenshot is from my Finnish translation, captured in my emulator in a three-way-fields-merge NTSC mode.)
An example of such game is Simon's Quest, as shown in the screenshot below.
This algorithm is cheap and easy to implement. However, it is restricted into fading through from/to black, which is why the game fades through black.
However, if one wants to fade between two arbitrary palettes, things are not so easy. Has anyone attempted it?
I can think of an algorithm, which is not cheap:
Precalculate a 64x64x4 array of values and place it in a vacant ROM page. It takes 16384 bytes (4000h). Key 1 is the source palette value, key 2 is the target palette value, and key 3 is the degree of interpolation (20%, 40%, 60%, 80%). An program populates the array by determining which NES color index most closely resembles the given mixture of NES colors.
Fading the palette is a matter of reprogramming the palette six times:
First, with the source palette (srccolor) (is optional).
Then four times with table[srccolor][dstcolor][i] for each color in the screen palette.
And finally with the target palette (dstcolor).
Resourcewise, it is not cheap.
It could be made smoother by including fewer degrees of interpolation (such as one: 50% or two: 33% and 67%): This would take 1000h or 2000h bytes respectively. Additional degrees of interpolation could be synthesized at runtime by flickering between the previous and the next value in the table. Such flickering might not look nice, though.
Are there other, perhaps better algorithms for arbitrary palette fades on NES?
(Screenshot is from my Finnish translation, captured in my emulator in a three-way-fields-merge NTSC mode.)