Pattern for Fading out

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
User avatar
-Basti-
Posts: 40
Joined: Sun Sep 26, 2010 10:29 pm

Pattern for Fading out

Post by -Basti- »

Hello everyone,
I am looking for a pattern for fading out a whole background smoothly. I fooled around a bit with the color bits of PPU_MASK, but without any result.
Since the background I want to fade out only contians white letters on black ground, my next approach will be to change the color palette step by step
to darker greyish colors.
Anyway, I guess there is a more efficient way to fade out backgrounds. Can anybody help? I would appreciate example code in C since I did not make the step to assembly, yet.

Regards Sebastian
User avatar
pubby
Posts: 583
Joined: Thu Mar 31, 2016 11:15 am

Re: Pattern for Fading out

Post by pubby »

You can darken a palette entry by subtracting 16 from its value. If the result is negative, set it to black (0x0F).

Do this to each palette entry repeatedly and you have a fade-out effect.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Pattern for Fading out

Post by dougeff »

Yes. keep a copy of the active palette in RAM and keep changing it.

Or use the neslib, which has a brightness function. (and a delay function). have a loop which delays a bit, darken by 1, repeat till 0.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Pattern for Fading out

Post by tokumaru »

Fading on the NES is indeed accomplished by darkening/brightening the palette over time. The challenge is to do it smoothly when there are only 4 levels of brightness to work with. The color emphasis bits can be used to create intermediary steps if you turn all 3 bits on, since that darkens the palette slightly, but this trick backfires on RGB PPUs, where turning all 3 color emphasis bits on makes the screen completely white.

Another way to create smoother fading sequences is to animate the hue in addition to the brightness: slide towards blue when fading to black, towards yellow when fading to white.

One more technique that worked reasonably well for me is to stagger the brightness changes, instead of changing all colors at once: when fading out, only darken the $0x colors, making them black. On the next step, darken only colors $1x, making them $0x. Then darken $2x, then finally $3x, so what took just 1 frame with the typical "subtract $10" technique, takes 4 frames with the staggered method. The next round of updates has only 3 steps, since there are no $3x colors anymore, and each round has fewer steps, but in the end you have a 4 + 3 + 2 + 1 = 10-step fade sequence instead of a 4-step one, and it does look smoother (as long as the image contains colors of varied brightness levels).
Post Reply