Jump to content
  • Advertisement
Sign in to follow this  
Karl G

Single-Pass Multitexturing

This topic is 5043 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

Hey guys. I know this topic has been addressed before, but the search is being dumb (sql timeout after blah blah seconds...etc) and I can't find any resources on it. Story is, I'm doing multitexturing in C++ using Direct3D 9.0c and I can't figure out all of the texture stage state settings. I'm trying to blend two textures over a single triangle in one pass, using the alpha value on each vertex to change how much each texture is applied, and mix the textures with the diffuse color of that vertex. This is what I've got right now, but the alpha blending doesn't affect the amount of each texture--they're just blended evenly.
            myD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );

            myD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1 );
            myD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );

            myD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
            myD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
            myD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_LERP );

            myD3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0 );

            myD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
            myD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE|D3DTA_COMPLEMENT );

            myD3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
            myD3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
            myD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_LERP );

            myD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
Edit: fixed a typo

Share this post


Link to post
Share on other sites
Advertisement
typically you want to mix diffuse via a modulate, and only after the textures are mixed.

0Color: D3DTOP_SELECTARG1, D3DTA_TEXTURE
0Alpha: D3DTOP_SELECTARG1, D3DTA_DIFFUSE
1Color: D3DTOP_BLENDCURRENTALPHA, D3DTA_TEXTURE, D3DTA_CURRENT
1Alpha: D3DTOP_SELECTARG1, D3DTA_DIFFUSE
2Color: D3DTOP_MODULATE, D3DTA_CURRENT, D3DTA_DIFFUSE
2Alpha: D3DTOP_SELECTARG1, D3DTA_DIFFUSE
3Color: D3DTOP_DISABLE
3Alpha: D3DTOP_DISABLE

Sorry it's not code, but I can be lazy.

edit: For blending in the texture stages alphablendenable doesn't need to be set. That's solely to enable blending with the frame buffer.

Share this post


Link to post
Share on other sites
Some of the operations are explained better in the .h files than in the documentation. Open up DXSDK\include\d3d9types.h and have a look around. If you're using visual studio, put your cursor on one of the D3DTOP_* symbols, and press F12. It should open up the .h and take you to the correct line automagically.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!