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.

C/C++ > Screen Effects

#12137 - Wildginger - Fri Oct 31, 2003 3:51 pm

Hi all,

Does anyone have any screen effect functions that they would like to share?

I have the fade in and fade out functions that have been posted before, but was just wondering if there was any code floating about that made the background appear and disappear in any other way, such as Apex designs logo reducing to a dot in the middle of the screen etc, or fading out different pixels at a time to get a "speckled" effect.

Any help/code appreciated, just fancy applying some different effects apart from the normal fading.

Cheers,

Wildginger

#12144 - tepples - Fri Oct 31, 2003 8:43 pm

Reducing to the middle involves playing with the affine registers and is available in all modes but 0.

"Speckled" fading involves pseudorandom writes to the VRAM.

You can get a lot of effects through HDMA to the scroll registers (or affine registers for bitmaps or rot/scale BGs).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#12146 - RaBBi - Fri Oct 31, 2003 8:46 pm

what are exactly "affine" registers ?
_________________
Sorry for my poor english, but it would be worst for you to understand me if I speak in my native language, French ^^

#12148 - tepples - Fri Oct 31, 2003 8:53 pm

The "affine registers", as many GBA programmers call them, are the registers in the GBA's video chip that specify the affine map that is applied to screen pixels to get texel coordinates. Such an affine map can include translation, rotation, scaling, and shearing operations.

GBATEK description of GBA affine registers
CowBite Spec description of GBA affine registers

A DMA transfer triggered by horizontal blank (often called HDMA, especially by those with Super NES programming experience) can change the affine registers after every scanline to make all sorts of effects.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#12150 - DekuTree64 - Fri Oct 31, 2003 9:25 pm

The affine regs are BG2X, BG2Y, BG2PA, BG2PB BG2PC and BG2PD, and the same things except for BG3. They let you rotate/scale/skew the background layers for some very nice effects, such as the 3D looking ground in Mario Kart and F-Zero.
PA is the X scale, PB is X skew (it shifts the background horizontally as it goes down the screen, you can also simluate this for text BGs by changing the X scroll on HBlank), PC is the Y skew (shifts vertically each pixel along the screen, which can't be done any other way), and PD is the Y scale (which can be simulated by scrolling a text BG up/down each scanline). The GBA doesn't actually know how to rotate things itself, you just tell it to skew the BG both directions and scale it back to the right size and it appears to be rotated. You can calculate the skew/scale values easily with the equations in the PERN tutorials.
Then the X and Y regs are basically the same as the regular text BGHOFS and BGVOFS, but more accurate. They are 32 bits, with the lower 8 bits being the fractional portion of the scrolling distance, so if you set BG2X to 128, it will scroll 1/2 a pixel to the right. Of course you can only see whole pixels so it wouldn't look any different than 0, but when you rotate/scale it you can see the difference.
X and Y tell the coordinates in the map that will appear in the top left corner of the screen, then all the other pixels in the screen are calculated relative to that depending on PA, PB, PC and PD. So if you set X to 20 << 8, and Y to 30 << 8 (remember, lower 8 bits are fractional), then pixel 20, 30 of the map will be in the top left corner. Then if you set PB (horizontal skew) to 5 << 8 (PA/PB/PC/PD are 8 bit fractional too), it will scroll one more pixel to the right each line down the screen, pixel 0, 1 on the screen will show pixel 25, 31 of the map (because we went down one line, and then skewed 5 pixels over).
Then the scale regs tell how many pixels to move over each pixel across/down the screen, so they're normally set to 1 << 8, so each screen pixel to the right, you move one map pixel to the right, and each screen down, you move one map down, and therefore it looks perfectly normal. If you set PA (X scale) to 2 << 8, then each pixel across the screen, you move over 2 map pixels, so you're only drawing every other pixel of the map, so it looks zoomed out.
PC and PD (Y skew/scale) are the same, just going the other direction, so that's about it.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#12151 - crossraleigh - Fri Oct 31, 2003 9:45 pm

darkcloud has some windowing and moasic demos on his site: http://sinewave3.tripod.com/ScreenTutorial/screentutpg1.html. The AAS logo probably uses windowing.

There is the Swirl Effect demo by Thomas Carton: http://www.gbadev.org/download.php?section=demos&filename=swirl.zip. I think his "swirl" and your "speckled" work pretty much the same way.