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 > Alpha blending

#1651 - dragor - Tue Jan 21, 2003 2:24 am

I have a question about doing alpha blending. I'm using mode 0 and I'm using two background layers, 0 and 2. Background 0 has priority 3 and background 1 has priority 1. I'm also using a layer of sprites. I would like to place a shadow using a sprite. The shadow should be behind background 2 but in front of background 0. That is, if the sprite is the same location as a non transparent tile from background 2, the shadow should not be seen. But if the shadow is in the same location as a non transparent tile from background 0, the shadow and background should be blended together.
_________________
Sum Ergo Cogito

#1654 - Arek the Absolute - Tue Jan 21, 2003 2:45 am

This seems simple... or I'm totally missing your point...

In any case, you want a sprite to be transparent, and you want background 0 to blend in with it, right? All you need to do then, is set bit 8 of REG_BLDMOD to 1. If I remember correctly, you don't want to set bit 4, because that would make EVERY sprite blend, not just the ones you want.

Of course, you'll also have to set REG_COLEV to determine the extent of the blending... And for whatever sprite you want to be translucent, you'll have to make sure attribute 0 of the desired sprite is set for translucency...
_________________
-Arek the Absolute

#1655 - dragor - Tue Jan 21, 2003 3:40 am

Currently I'm writing 0x0100 to REG_BLDMOD, which sets blending with background 0, and this works. I get a nice blending with background 0 and the sprite. But the problem is that the shadow sprite won't blend at all with background 2. My sprite is just a black square and on background 2, I see a big black square. I want background 2 to show up as if the sprite wasn't even there.

This method I'm using for shadowing coule be totally nuts too. The documentation that I've found on doing blending is not very well written and leaves me with some questions. If anyone can direct me to a good doc on doing blending, or can show me a better method than the one I'm trying, that'd be fantastic.

Thanks
_________________
Sum Ergo Cogito

#1656 - Arek the Absolute - Tue Jan 21, 2003 3:52 am

If that's the case, try setting bit 10 in addition to bit 8. (remember, also, that I'm assuming the first bit is bit 0, not 1). This would make it so that the sprite blends with BG2 as well. However, because the sprite is underneath the background, it shouldn't blend at all, and there should be no black mark over the sprite. Sorry I missed that detail.

-Also, I'm afraid I can't think of any good documents on alpha blending in particular. I will say though, that the best general purpose docs out there that I've run across, anyway, are http://www.thepernproject.com and http://www.cs.rit.edu/%7Etjh8300/CowBite/CowBiteSpec.htm

Between what the two of them say, you can probably get a pretty good sense of how alpha blending works.
_________________
-Arek the Absolute

#1693 - dragor - Tue Jan 21, 2003 6:10 pm

I've tried setting bit 10 and it doesn't work either. I think the technique I'm using isn't going to work. I'll just do it another way. At least I know it'll work, even if it isn't exactly what I want. I know those sites you listed well :) They are extremely helpful.
_________________
Sum Ergo Cogito

#1709 - DekuTree64 - Tue Jan 21, 2003 8:44 pm

Are you sure you have your sprite priority set right? It should be 2 or 3 to keep from showing above BG2. The method sounds fine to me. It's probably some simple thing that's just hard to notice

#1714 - dragor - Tue Jan 21, 2003 10:10 pm

Ok I got it working the original way. The problem was with the priority. It was getting changed unexpectedly. Thanks for the hint dekutree
_________________
Sum Ergo Cogito