gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Good Screen Fade Effects

#1865 - darkcloud - Fri Jan 24, 2003 7:25 pm

Anyone know any good screen fade effects? I was thinking something like how Zelda Lttp fades during the switch from dark to light world (if you've played the game). The screen kinda becomes all wavy.
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.

#1867 - Splam - Fri Jan 24, 2003 7:42 pm

I suppose theres a lot you can do with the gba hardware. You've not only got the built in colour effect stuff like alpha blending etc but because you can alter the hardware registers on each line you can mess with pretty much anything you want (screen pos, colours etc) then you've got things like the window modes which you could use for doing crossfades or wipes of differing shapes. All that is before you even get into any processor intensive routines you could code yourself.

#1870 - darkcloud - Fri Jan 24, 2003 8:05 pm

Do you know any examples that show some of these things? I could just mess around with it myself, but I would rather look at someone else's code to at least get an idea exactly what I need to do.
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.

#1882 - arog - Fri Jan 24, 2003 11:47 pm

I borrowed some code for fading in to and out from black.
The sample code was made for HAM, but maybe you can
find something useful. Look at splash.h & splash.cpp:
http://www.aaronrogers.com/ham/Games/HAM_Hearts/ham_hearts.php

The code came from the author of Visual HAM:
http://www.console-dev.de/visualham/

Good Luck!

- Aaron Rogers
HAM Tutorial

#1884 - darkcloud - Fri Jan 24, 2003 11:53 pm

Thanks, but I'm kind of looking for something more "flashy". But thanks anyway.
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.

#1891 - XeroxBoy - Sat Jan 25, 2003 2:45 am

To do the screen warp thing, you'll need to use interupts (or DMA, I think) to change the value of the scroll register every scanline. Check the tutorial on Interupts at www.thepernproject.com

#1894 - Splam - Sat Jan 25, 2003 4:20 am

Yep, to "wobble" the screen (not seen the zelda one so I'm guessing what it looks like) the easiest way would be make a table of 160 xscroll values, set up a hdma with source address = that table, destination = bg?hofs (presuming you're using a normal tile screen), a 1x16bit length, destination set to reload and source to increment. You need to retrigger that on every Vblank (which will reset the source to the start of the table again). Then just move some kind of sine wave or whatever through the 160 long table OR make the table longer by the length of the wave and just increase the dma source address until it's done 1 wave then set it back to 0, then increment etc etc

To do a cross fade there are lots of ways but they require you to have both images of whatever will be fading in vram (remembering the number of backgrounds you have). You could use a WINDOW set to show 1 BG inside and 1 BG outside and simply move 1 sides coordinates across the screen (for a wipe effect). A more complex version of that would be to alter the X pos (and maybe Y pos too) of each side of the WINDOW on an hdma then you can have shaped fades (circles etc) which could also wobble as they moved.

#1899 - darkcloud - Sat Jan 25, 2003 5:49 am

Alright, thanks, I'm gonna try out the screen wave effect.
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.

#1940 - AnthC - Sun Jan 26, 2003 10:46 am

A nice fade is where you use another background and draw a circle onto it
Each frame you make the circle bigger and bigger, and yo can use this background to mask all the other ones off, getting a nice iris effect.
It was used to effect in games like Zoop and in some intros/demos on the Amiga.
Anth

#1945 - Splam - Sun Jan 26, 2003 1:56 pm

You can do that with the window method I mentioned :)

#1968 - headspin - Sun Jan 26, 2003 9:40 pm

It's funny cos I've just been working on this "wave effect" for a game I'm writing... here is some basic code I'm using now but there is a bug in there at the moment (I need to loop back to the start of the sine table because the index goes beyond the table's size), but you get the idea. It makes BG0 wavey.. (you will need to add the fade)

Code:
const u16 sinus_data[256] =
{
  128,  131,  134,  137,  140,  143,  146,  149,
  152,  155,  158,  161,  164,  167,  170,  173,
  176,  179,  182,  185,  187,  190,  193,  196,
  198,  201,  203,  206,  208,  211,  213,  215,
  217,  220,  222,  224,  226,  228,  230,  232,
  233,  235,  237,  238,  240,  241,  243,  244,
  245,  246,  247,  248,  249,  250,  251,  252,
  252,  253,  254,  254,  254,  255,  255,  255,
  255,  255,  255,  255,  254,  254,  254,  253,
  253,  252,  251,  251,  250,  249,  248,  247,
  246,  244,  243,  242,  240,  239,  237,  236,
  234,  232,  230,  228,  227,  225,  223,  220,
  218,  216,  214,  211,  209,  207,  204,  202,
  199,  196,  194,  191,  188,  186,  183,  180,
  177,  174,  171,  168,  165,  162,  159,  156,
  153,  150,  147,  144,  141,  138,  135,  132,
  129,  125,  122,  119,  116,  113,  110,  107,
  104,  101,  98,  95,  92,  89,  86,  83,
  80,  77,  74,  71,  69,  66,  63,  60,
  58,  55,  53,  50,  48,  45,  43,  41,
  38,  36,  34,  32,  30,  28,  26,  24,
  22,  21,  19,  17,  16,  14,  13,  12,
  10,  9,  8,  7,  6,  5,  4,  3,
  3,  2,  2,  1,  1,  0,  0,  0,
  0,  0,  0,  0,  0,  1,  1,  2,
  2,  3,  3,  4,  5,  6,  7,  8,
  9,  10,  11,  13,  14,  16,  17,  19,
  20,  22,  24,  26,  28,  30,  32,  34,
  36,  38,  40,  43,  45,  47,  50,  52,
  55,  58,  60,  63,  66,  68,  71,  74,
  77,  80,  83,  86,  88,  91,  94,  97,
  101,  104,  107,  110,  113,  116,  119,  122,

};

#define REG_DISPSTAT   *(u16*)0x4000004
#define REG_VCOUNT     *(vu16*)0x4000006
#define REG_BG0HOFS    *(u16*)0x4000010
#define REG_IE         *(u16*)0x4000200
#define REG_IF         *(u16*)0x4000202
#define REG_IME        *(u16*)0x4000208

#define INT_VBLANK 0x0001
#define INT_HBLANK 0x0002

u8 sinus_offset=0, sinus_count=0;

void wave_effect()
{
   REG_IME=0;
   REG_IE|=INT_HBLANK|INT_VBLANK;
   REG_DISPSTAT|=(1<<4) | (1<<3);
   REG_IME=1; //enable interrupt
}

void InterruptHandler(void)
{
  u16 temp_reg_if=REG_IF;
 
  REG_IME=0;

  *((u16*)0x03007ff8) = REG_IF;
 
  if(temp_reg_if & INT_HBLANK)
  {
      REG_IF |= INT_HBLANK;

      REG_BG0HOFS = (sinus_data[REG_VCOUNT+sinus_offset+sinus_count]-128) >> 3; // bit shifting makes a smaller wave
      sinus_offset++;
      if(REG_VCOUNT>=160) sinus_offset=0;

  }

  if(temp_reg_if & INT_VBLANK)
  {
      REG_IF |= INT_VBLANK;

      sinus_count++;
  }

  REG_IME=1;
}

main()
{
   REG_INTERUPT=(u32)&InterruptHandler;

   wave_effect();

   for(;;);
}

#1969 - darkcloud - Sun Jan 26, 2003 9:43 pm

Thanks for the code example headspin.
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.