Sign in to follow this  
Karl G

Single-Pass Multitexturing

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this