Archived

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

Blue*Omega

Alpha Mask

Recommended Posts

Kinda silly question, but here it goes anyways: Is there any way to use a texture as an alpha mask? Like with a sprite, instead of color keying or using a built in alpha channel loading up one texture for the sprite and one greyscale texture for the trasnparency. I''ve found lots and lots of ways to do this so far, and every single f#$%!&* one of them uses shaders! Now, don''t get me wrong... I have nothing agains shaders, as they''re quite cool, but I don''t want to force my users to buy a a GeForce3+ to run a sprite based game ^_^ For refernce purpouses I''m using DirectX 9. Any help is much appreciated, thanks!

Share this post


Link to post
Share on other sites

// get colour from texture in stage 0
SetTSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); // or whatever you need for colour
SetTSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTSS( 0, D3DTSS_COLORARG2, D3DTA_CURRENT ); // or whatever you need for colour

// do anything valid with stage 0 alpha
SetTSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); // unused, but pipe must have
SetTSS( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); // something valid here so it stays
SetTSS( 0, D3DTSS_ALPHAARG2, D3DTA_CURRENT ); // open for the next stage

// pass colour through this stage
SetTSS( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG2 ); // select colour from texture in stage 0
SetTSS( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTSS( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );

// select the alpha from the texture in this stage (overrides stage 0 alpha)
SetTSS( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); // select alpha from texture in stage 1
SetTSS( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
SetTSS( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT );

// end of setup
SetTSS( 2, D3DTSS_COLOROP, D3DTOP_DISABLE ); // close the pipe.
SetTSS( 2, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

// specify where the texture coordinates come from
// for each of our maps
SetTSS( 0, D3DTSS_TEXCOORDINDEX, blah );
SetTSS( 1, D3DTSS_TEXCOORDINDEX, blah );

// set the colour and RGB textures
SetTexture( 0, colour_map );
SetTexture( 1, opacity_map );

// set up alpha blend, e.g.
SetRS( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
SetRS( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
SetRS( D3DRS_ALPHABLENDENABLE, TRUE );



With the above setup, the opacity must be in the alpha channel of the texture, so
you need either an ARGB texture or a format like A8 (if supported on your target h/w)


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites