Archived

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

tobymurray

alpha blending with 1-bit alpha component

Recommended Posts

tobymurray    115
Howdy all, a few months ago I wrote my third game, the first though in Direct3D 8. The game used textured billboarded sprites in a 3-D environment. Here's a scaled down screenshot to give you the idea: OK the thing is, I setup Direct3D using a 16-bit colour depth, using either D3DFORMAT_R5G6R5 or D3DFORMAT_X1R5G5B5. Since the alpha blending worked (eg. the shadows on the ground and the glass in the ship), I'm assuming that the format used must have been the latter (the code tried both and took the first one which worked - the R5G5R5 was tried first, followed by X1R5G5B5). But how could it work properly when only 1 bit of alpha was being used - wouldn't this equate to either fully transparent or fully opaque? The alpha blending was enabled and setup as normal to take the SRCALPHA for the source and the INVSRCALPHA for the destination. The Textures were 32-bit tga's and were loaded used D3DXCreateTextureFromFileEx() with a transparent colour key. Direct3D was setup to take the alpha soley from the texture (the vertices had no colour component) How did this work? At the time I took it for granted that it should work, but thinking about it now I can't see how it did. Any explanation would be great. Thanks Toby Gobsmacked - by Toby Murray [edited by - tobymurray on June 6, 2002 11:51:10 AM]

Share this post


Link to post
Share on other sites
IndirectX    122
The backbuffer format doesn't need alpha at all. The alpha values of texture pixels determine whether those pixels are copied to screen, and you have 8 bits of alpha in 32-bit TGA.

D3DFORMAT_X1R5G5B5 doesn't have alpha at all. D3DFORMAT_A1R5G5B5 does.

If you have 1 bit of alpha, each pixel can be either opaque or transparent, which is basically your color key.

[edited by - IndirectX on June 6, 2002 11:51:23 AM]

Share this post


Link to post
Share on other sites
tobymurray    115
thanks indirectx thats a fast reply.
One thing though - when it was blending with the pixels on screen, (ie. comparing the alpha in the texture with that of the pixel already on screen - in the case of the shadow on top of the other) where did the alpha value for the screen pixel come from - surely it would have been the 1-bit component? (right?)

thanks
Toby

Gobsmacked - by Toby Murray

Share this post


Link to post
Share on other sites
IndirectX    122
quote:
Original post by tobymurray
where did the alpha value for the screen pixel come from

From the texture. You're using INVSRC ALPHA, aren't you?

X means that bit is unused. Your backbuffer doesn't store alpha information.

[edited by - IndirectX on June 6, 2002 11:57:30 AM]

Share this post


Link to post
Share on other sites