Jump to content
  • Advertisement
Sign in to follow this  

[D3D9] texture stage problem

This topic is 3691 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. I'm trying to mix texture color with texture factor and running into some problems. Specifically, I want to use the color and alpha specified by texture factor if no texture is set, and modulate texture factor color and texture color if a texture is set.
//  Set texture.
dev->SetTexture( 1, myTexture );

//  Elsewhere:

//  Select TFACTOR and use this color if no texture is set.
dev->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2 );
dev->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_CURRENT );
dev->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR );
dev->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 );
dev->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_CURRENT );
dev->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );

//  Modulate selected TFACTOR from stage 0 by texture color if texture is set,
//  theoretically disabling stage 1 if no texture is set for stage 1.
dev->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE );
dev->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_CURRENT );
dev->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_TEXTURE );
dev->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
dev->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_CURRENT );
dev->SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );

//  Disable remaining stages.
dev->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE );
dev->SetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

So far, I've determined that I can modulate TFACTOR and texture in stage 0 (setting the texture at stage 0, in that case) and get what I want. This solution unfortunately will not work in the more general case, as it would disable stage 0 if no texture is set. Attempting to simply select texture color in stage 1 seems to fail. Could someone please point out where I'm going wrong? I'm convinced it's something stupidly simple. Cheers =)

Share this post

Link to post
Share on other sites
I'm not sure if you can get consistent results with a single setup. I remember back in DX8 if a stage tried to sample a texture, but no texture was present, some drivers would act as though it was white, some would act as though it was black, and some drivers would just abort the texture stages or shader at that point and return.

I don't think there are rules of how to act in that situation, and you may still see different drivers acting in different ways... sampling a texture that isn't there just isn't defined.

What you can do is just toggle the colorop and alphaop between modulate and selectarg2 depending on if the current object has a texture. That should work just fine on all hardware. A worse option is to replace the non-existent texture with a 1x1 white texture.

Share this post

Link to post
Share on other sites
My guess is that your problem has to do with the texture coordinates, since otherwise the texture stages look fine. If you don't have two sets of coordinates (one for each stage), you need to set D3DTSS_TEXCOORDINDEX of stage 1 to 0, so it takes the first texture coordinate set. (Remember to set it back to 1 in the end.)

Share this post

Link to post
Share on other sites
Thanks guys =)

The texture coordinates seem to be the issue as presently, I believe they're set using D3DFVF_TEX0 (doh!).

Good info on compatibility as well. I think I recall a MSDN page saying something about disable behavior if there's no texture set for a stage, and D3DTA_TEXTURE is a color arg. Then again, it's anyone's guess as to whether or not this is implemented.

Thanks again.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!