Archived

This topic is now archived and is closed to further replies.

flaXen

Alpha channel on 16bit textures

Recommended Posts

I''m using DX8/D3D and I support both 32 and 16bit textures in my game. Specifying an alpha value in 32bit is easy, but how can I do it with 16bit textures w/o losing color depth? The 32bit textures use D3DFMT_A8R8G8B8, 16bit uses D3DFMT_R5G6B5. Can I maintain an 8bit alpha texture apart from the texture? If so, how do I apply it with the real texture to achieve alpha blending? Thanks in advance! -- Dan (flaXen)

Share this post


Link to post
Share on other sites
If you can use multi-texturing load the alpha data into the D3DFMT_A8 and set this as you second texture stage. Then set the texture stages up something (if memory serves) like as follows:-

  
DXDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_CURRENT);
DXDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );


Make sure the card supports D3DFMT_A8 though!

Another option is to use

D3DFMT_A1R5G5B5 - on/off (0/255) alpha
D3DFMT_A4R4G4B4 - 16 shade alpha.

The first is best as it preserves more colours better.
The second is the only option if you want more alpha information.

To convert to these formats you can use the following macros:
  
#define MAKE_ARGB_1555(r,g,b,a) ((u16)(((a&0x01) << 15) | ((r>>3) << 10) | ((g>>3) << 5) | (b>>3)))

#define MAKE_ARGB_4444(r,g,b,a) ((u16)(((a>>4) << 12) | ((r>>4) << 8) | ((g>>4) << 4) | (b>>4)))


Hope this is of some help


[The views stated herein do not necessarily represent the view of the company Eurocom ]

Eurocom Entertainment Software
www.Eurocom.co.uk

The Jackal

Share this post


Link to post
Share on other sites
Thank you very much! This is most helpful!

Here is an additional quirk. I already use A1R5G5B5 so that I can achieve the equivelant of an alpha key. Can I multitexture the alpha channel and texture together while using the alpha key as-is? Or would it be wiser to use R5G6B5 and use the alpha texture for transparency? As it stands, my game loads either 16 or 32bit textures. The 16bit ones get converted into 15bit.

Thanks again!
-- Dan (flaXen)

Share this post


Link to post
Share on other sites
I think using ARGB1555 and the sepeerate alpha might be the better way to go, but have the all the alpha set to 255 for the 1555ARGB. This is since when using 565RGB overlayed over many other 565RGB semi transparent textures you will start to notice a green tinge. This is due to the green having an extra bit. (well thats what I''ve noticed on GForce 1,2,3 cards

[The views stated herein do not necessarily represent the view of the company Eurocom ]

Eurocom Entertainment Software
www.Eurocom.co.uk

The Jackal

Share this post


Link to post
Share on other sites