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 > 16-bit sprite question

#148818 - JanoSicek - Thu Jan 10, 2008 7:35 pm

Hello.

I have read that for 16-bit bitmap sprites the ATTR2 palette values are used as Alpha value.

What does this mean? How can I use it and for what?
I haven't find any documentation for this.

Second question -- The effects on sprites (fade-in/fade-out/blend) work in what way? Can anyone point me to some documentation about this?

Also, can I use Window to fade-out a portion of tiled background? To make it darken and then put some text over it in another background?

Thanks for answers and links!

J.

#148844 - yellowstar - Fri Jan 11, 2008 4:01 am

JanoSicek wrote:

I have read that for 16-bit bitmap sprites the ATTR2 palette values are used as Alpha value.

What does this mean? How can I use it and for what?
I haven't find any documentation for this.

This applies to all palettes on DS/GBA.
The first palette index is the alpha index. Any pixels with this index are transparent.(Index zero)
So, you would have the pixels you don't want to be seen, set to index 0,
while the ones you want set to their respective values.

JanoSicek wrote:

Second question -- The effects on sprites (fade-in/fade-out/blend) work in what way? Can anyone point me to some documentation about this?

Also, can I use Window to fade-out a portion of tiled background? To make it darken and then put some text over it in another background?

I've never tried/learned about blending and such, so I can't help you with
that. Somebody else needs to help with that.
I probably would be able to figure it out by checking gbatek.(That's THE number ONE resource for DS homebrew programmers, and probably GBA too.)

@Windows Q:
Yes, but you'll have it do each bg seperately. Or flatten the image/project
in your image editor.(Or export each layer for the bgs)

#148853 - JanoSicek - Fri Jan 11, 2008 8:57 am

Thanks for the answers!
Here are my comments:

yellowstar wrote:
JanoSicek wrote:

I have read that for 16-bit bitmap sprites the ATTR2 palette values are used as Alpha value.

What does this mean? How can I use it and for what?
I haven't find any documentation for this.

This applies to all palettes on DS/GBA.
The first palette index is the alpha index. Any pixels with this index are transparent.(Index zero)
So, you would have the pixels you don't want to be seen, set to index 0,
while the ones you want set to their respective values.

IN GBAtek I found this:
GBAtek wrote:

also in that mode, the color bits (Attr 2, Bit 12-15) are used as Alpha-OAM value (instead of as palette setting).

Therefore my question was what happends when in bitmap mode I set the Alpha-OAM to some value, for example ... 7? I have no palette, as the sprite is 15-bit color, and the transparency is done by 16th bit of each pixel


yellowstar wrote:
@Windows Q:
Yes, but you'll have it do each bg seperately. Or flatten the image/project
in your image editor.(Or export each layer for the bgs)

Example of what I want to do:
I have layer 0,1,2,3 tiled backgrounds. 0 is on top
I want layers 1,2,3 to darken and 0 to not change

Can i set the layers to apply the effect as bg1,bg2,bg3 and effect as fade out? will this take the topmost pixel from these 3 bgs and fade it out, before possibly overlapping bg0 on top of it?

#148861 - eKid - Fri Jan 11, 2008 3:06 pm

When using bitmap sprites the Attr2 palette value becomes an alpha blending value. It is to be used together with BLEND_CR (blending control). The sprite will blend with the targets specified in the 'destination' of BLEND_CR. Bitmap sprites won't be affected by other special effects in BLEND_CR (such as fade-black/fade-white) they'll always use alpha blending.

I ran a few tests....
http://ekid.nintendev.com/bitmap_sprites.zip
Blending doesn't work properly in any emulator, you'll have to test on hardware.

Another small thing I noticed is that even when the blending targets are all disabled, if the alpha value is 0 the sprite will not be drawn (and drawn fully if nonzero).

#148870 - JanoSicek - Fri Jan 11, 2008 4:27 pm

eKid wrote:
When using bitmap sprites the Attr2 palette value becomes an alpha blending value. It is to be used together with BLEND_CR (blending control). The sprite will blend with the targets specified in the 'destination' of BLEND_CR. Bitmap sprites won't be affected by other special effects in BLEND_CR (such as fade-black/fade-white) they'll always use alpha blending.

I ran a few tests....
http://ekid.nintendev.com/bitmap_sprites.zip
Blending doesn't work properly in any emulator, you'll have to test on hardware.

Another small thing I noticed is that even when the blending targets are all disabled, if the alpha value is 0 the sprite will not be drawn (and drawn fully if nonzero).

If I undestand correctly:
If a sprite is TILE-BASED, then it will only blend if the blending bit for it is set, and all such sprites will be blended by the same factor.

If a sprite is BITMAP-BASED, then it will always blend by the factor set in this attribute...

Thanks

#148871 - eKid - Fri Jan 11, 2008 4:45 pm

JanoSicek wrote:

If I undestand correctly:
If a sprite is TILE-BASED, then it will only blend if the blending bit for it is set, and all such sprites will be blended by the same factor.

Right, unless the 'source' of BLEND_CR includes the sprite bit, then all sprites will have blending enabled.

JanoSicek wrote:

Also, can I use Window to fade-out a portion of tiled background? To make it darken and then put some text over it in another background?

Yes the windows can mask out special effects. I have a demo here that demonstrates this
http://ekid.nintendev.com/spotlight.zip

Basically what you want to do is set 'WIN_IN' to everything and 'WIN_OUT' to everything except special effects (a window must also be enabled in DISPLAY_CR). Then BLEND_CR can be set to 'fade to black' mode, and the darkness specified in BLEND_Y. This makes only the portion inside the window coordinates darkened.