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.

DS development > Antialiasing with 2 scaled backgrounds

#154372 - ingramb - Tue Apr 15, 2008 8:58 am

I have a scaled tile background that I want to antialias. I think I've seen references to a technique that emulators have used that involves adding a second background with the same image, and offsetting it slightly.

So I have 2 tile backgrounds on top of a 3d background. I want to blend the tile backgrounds together, and then have that on top of the 3d background. I can't seem to get the blend settings right.

I've tried:
BLEND_CR = BLEND_ALPHA | BLEND_SRC_BG2 | BLEND_SRC_BG3 BLEND_DST_BG0;
BLEND_AB = (8 << 0) | (16 << 8);
BG0_CR = BG_PRIORITY_1... //3d background
BG2_CR = BG_PRIORITY_0... //blended tiles
BG3_CR = BG_PRIORITY_0... //blended tiles
This doesn't work. I am not understanding how the blending hardware works. Help?

[EDIT]
Background 2 and 3 use different extended palette slots implicitly. That was my blending problem. So it kind of works now. What is the most effective way to do the antialiasing?

#154391 - Lazy1 - Tue Apr 15, 2008 4:38 pm

This thread may help you:
http://forum.gbadev.org/viewtopic.php?t=12628&highlight=jitter

There are quite a few good methods in there on how to smooth out the hardware scaling.
What I do is offset the X scroll register back and forth by 1 every hblank, this smooths a scaled 320x200 display very nicely.

The only drawback is you may notice some _slight_ flicker but that's only if you're really looking for it.

#154399 - Cydrak - Tue Apr 15, 2008 6:20 pm

Careful if you're using emulators--the hardware is unusual. In particular it only blends once.

The rule of thumb: transparency doesn't exist. So for every screen pixel, it picks the "top two" things: a visible, opaque SRC and a covered, opaque DST directly below it. If both match, it blends. Speaking of which, BLEND_ALPHA is kinda misleading. If you really want that, the weights should sum to 16, since the blend is just additive. (Am I the only one who wishes they were signed...? Whatever happened to that cool SNES subtraction mode?)

I would try:
BLEND_CR = BLEND_ALPHA | BLEND_SRC_BG2 | BLEND_DST_BG3;
BLEND_AB = (8 << 0) | (8 << 8); // half and half
BG2_CR = BG_PRIORITY_0... //blended tiles
BG3_CR = BG_PRIORITY_1... //blended tiles
BG0_CR = BG_PRIORITY_2... //3d background

You can also add BLEND_SRC_BG3 and BLEND_DST_BG0, this *ought* to antialias along the transparent edges (blend over BG0, where BG2 and BG3 are not blending with each other), but I haven't specifically tried it so I could be wrong...

#154408 - ingramb - Tue Apr 15, 2008 8:17 pm

Lazy1: Thanks, lot's of useful information there
Cydrak: Yeah, those numbers are the ones that worked for me once I realized BG2 and BG3 use different extended palette slots. I'll try your other suggestion after work.

Thanks guys!

Now another question...I'm just rendering 2d quads onto the 3d layer. Are there any tricks antialias this when it scales down? I imagine you could use the 3d capture hardware to blend 2 offset frames together, but I don't have the vram or the cycles for this. Is there anything else that will work?

#154511 - M3d10n - Thu Apr 17, 2008 3:00 am

You could jitter the texture coordinates using the texture matrix half a texel on each vblank, and let the LCD ghosting do the blending for you. If your texture is low-contrast, the flickering is pretty much unnoticeable.