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 > AlphaChannel-Textures with varying transparency in2D/3D

#117351 - syncope - Sun Feb 04, 2007 2:12 am

Hallo World !,

Ok I've serched and searched, here and in all the places I could make sense of.
Maybe the feature is just not well documented, but could it indeed not have been reverse engineered yet at all ?


Using an Alphachannel/Mask with soft AND strong Transparencies on an image >>

like so !
[Images not permitted - Click here to view it]
[Images not permitted - Click here to view it]
Doing this on a sprite
and a textured quad



I've certainly seen it plenty of times in commercial games, but perhaps I'm just imagining having seen it in homebrew also.
Electroplankton is full of it for example, in both 2D and 3D.
[Images not permitted - Click here to view it]
[I guess for the creatures which are made of polygons, as seen in screens 3, 4 and 8 - they used a transparency lookuptable or 1D texture, similar to the DS-style toonshading . Strong banding is noticable when looking at these on hardware.]


Without resorting to sortware blending, for which frankly I'm to inexperienced with programming, how can this be done ? Seems like the hardware supports it with ease.

Please feel free to take the supplied test graphics for a spin
http://www.filefactory.com/dlf/f/831df5/b/8/h/3fbd10f526948a2f/j/1170548934
[PNG & PCX files]

If this is just an oversight on my part, lets simlpy make this thread a place where concise approaches to to handling this issue can be found.

#117368 - Sausage Boy - Sun Feb 04, 2007 10:16 am

It's in fact very easy. Assuming you have 3D set up and working, you'll need to add this to your 3D code. The glEnable(GL_BLEND) needs to be ran every frame, I don't know about the other one.

Code:
glEnable(GL_BLEND);
glAlphaFunc(BLEND_ALPHA);


You'll also need a way to convert your textures to use the alpha format. You can either write a converter yourself, information about the formats can be found at GBATEK.

You can also use one of the existing texture converters, my texmex or the Nomad Texture Converter. Mine has a nice feature if you want to use your image editing program to reduce the palette, but still get all the alpha levels, search the board for texmex to find out how to use it. On the other hand, they have a nice GUI. Choose whichever you prefer.

Now, it's just a matter of loading those textures like regular paletted textures.


Edit: Oops, I lied about when to run the commands, fixed now.
_________________
"no offense, but this is the gayest game ever"

#117725 - syncope - Tue Feb 06, 2007 11:39 pm

Very cool, very resourcefull ! Thank you Sausage Boy.
looking into it now.

Anyone have a hunch or suggestions on how to compliment this with a Sprite-based 2D method ? Or if that's actually not possible/feasible.

[I'll post example-screenshots of that here, should I come across any]

#117730 - Lick - Wed Feb 07, 2007 12:18 am

As far as I know, with 2D sprites you can only change the 'transparency' of a layer. You could change it per scanline, but even then the result would differ from what you try to do, and it would be a lot of messy code.
You are better off doing it in 3D. (But beware of 3D hardware-related bugs in libnds.)
_________________
http://licklick.wordpress.com

#117746 - syncope - Wed Feb 07, 2007 2:25 am

Thanks again
[also for the word of warning]

#117805 - Sausage Boy - Wed Feb 07, 2007 6:03 pm

A good example of using the 3d hardware for 2d can be found in my Bear Attack. The point is to stay alive as long as possible. Note the smooth edges and nicely transparent explosions. If you stay alive long enough, you'll also see the entire screen covered with bears, something that just wouldn't be possible with the regular 2d hardware. Also, any game with a bear monitor simply wins (if you don't think it's working, you didn't survive long enough).

As for the source, what you might want to look at can be found in Userview.cpp (feel free to use the whole thing or parts of it, under whatever license you feel comfortable with). There's some good stuff in Factory.cpp as well, even though it's a horrible example of what you absolutely shouldn't do (put a little of everything in a class).
_________________
"no offense, but this is the gayest game ever"