Archived

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

Roof Top Pew Wee

Selecting which texture's alpha to use.

Recommended Posts

I posted a similar question before, but I don't think I was clear enough. So let me try again. Say I'm going to draw a simple quad. For this quad, I've set two textures as follows: (*lpD3DDevice)->SetTexture( 0, *(m_textureHandler->textures[m_spriteInfo[ i].spriteTexture][0]) ); (*lpD3DDevice)->SetTexture( 1, *(m_textureHandler->textures[m_spriteInfo[ i].alphaChannelTexture][0]) ); Assume that I actually have textures loaded there, cuz I know that's not where the problem lies. By default, to my knowledge, the color for the first texture will be drawn and the color for textures 1 will not be drawn. My question is simple. How do I use the color from texture stage 0, but the alpha channel from texture stage 1? Currently the values I'm using in the setTextureStageState are: (*lpD3DDevice)->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); (*lpD3DDevice)->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); What my program's drawing is simply the texture in stage 0 as it would be without any modifications by the alpha from stage 1. I hope this is clear, and I appreciate any help. Thanks. --Vic-- [edited by - Roof Top Pew Wee on October 20, 2002 12:38:57 PM]

Share this post


Link to post
Share on other sites
What you haven''t posted probably tells more than what you have posted.

1) Ensure the texture coordinates for BOTH textures are indexed correctly. If both textures are intended to use the same set of texture coordinates you should do:

SetTSS( 0, D3DTSS_TEXCOORDINDEX, 0 );
SetTSS( 1, D3DTSS_TEXCOORDINDEX, 0 );


2) The multitexture pipeline is just that, the output of one stage MUST flow into the next stage. You cannot disable alpha or colour, or simply not set it in stage 0 and then expect to re-enable it in stage 1. Be explicit unless you''re sure what the values already are!:

// Stage0 colour = Select from texture 0
SetTSS( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
SetTSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTSS( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

// Stage1 colour = Select from output of stage 0 (current)
SetTSS( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG2 );
SetTSS( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTSS( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );

// End of colour operations, disable all further stages
SetTSS( 2, D3DTSS_COLOROP, D3DTOP_DISABLE );


// Stage0 alpha = Select ANYTHING, but select SOMETHING!
SetTSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 );
SetTSS( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
SetTSS( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

// Stage1 alpha = Select from texture 1, since it''s a select
// this overwrites what was done in stage 0
SetTSS( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
SetTSS( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
SetTSS( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT );

// End of alpha operations, disable all further stages
SetTSS( 2, D3DTSS_ALPHAOP, D3DTOP_DISABLE );



If only the search feature was working (sigh), I did a long post on the texture blending cascade a few months back explaining how it worked.



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

Share this post


Link to post
Share on other sites
Well, I found the answer before you posted. Here's my method, which isn't too far off from yours:

// first we draw the texture with the alpha channel that we are going to use, so that we have the alpha set down
(*lpD3DDevice)->SetTexture( 0, *(m_textureHandler->textures[m_spriteInfo[ i].alphaChannelTexture][0]) );
(*lpD3DDevice)->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
(*lpD3DDevice)->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);

// now we draw over the texture, but the alpha is already set down, so we use the alpha from the first.
(*lpD3DDevice)->SetTexture( 1, *(m_textureHandler->textures[m_spriteInfo[ i].spriteTexture][0]) );
(*lpD3DDevice)->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
(*lpD3DDevice)->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
(*lpD3DDevice)->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);

This doesn't take into account values that may already be set for other things, but I can solve all of those easily. This is just what I was trying to do.
Pretty basic. I thought I'd post the solution I found in case it might help someone else.

--Vic--


[edited by - Roof Top Pew Wee on October 20, 2002 6:23:21 PM]

Share this post


Link to post
Share on other sites