Multitexturing (SetTextureState)

Started by
8 comments, last by datadawgx 20 years, 1 month ago
I''m trying to take two 128x128 32-bit bitmaps (.PNGs) and, using each images own transparency, mix them together without blending the color info onto a single quad. another way of putting it is: imagine two textured quads. each has a 32 bit bitmap. each uses its bitmap''s alpha and color info. no diffuse or anything like that. now imagine drawing one quad, and seeing one texture, and then drawing the other quad right on top of the first. i want to reproduce that effect on a single quad with two textures. how would i setup my texture states to do that? ive been reading/looking/experimenting for about 4 hours now and im getting frustrated. here''s the stages im trying. the results are the first texture shows up, but the second doesnt at all.

pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
pID3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
pID3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );

pID3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA );
pID3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );

pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_ADD );
pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

pID3DDevice->SetTexture( 0, pTexture1 );
pID3DDevice->SetTexture( 1, pTexture2 );
Advertisement
What does ValidateDevice have to say about that setup?

well i tried it and i think the HRESULT says 0 for all values. hmm im not confident im using the function right. im using a radeon 9600 so i think i get at least 6 passes. arent i only using two?
Stage1 needs a COLORARG2 to blend with, and an ALPHAARG2 to add with. You probably want D3DTA_CURRENT for both of these.

Your card must also support multitexturing.

You should also "finish" your states with a disable. Both color and alpha ops should disable at the same stage.

STSS(2, D3DTSS_COLOROP, D3DTOP_DISABLE) ;
STSS(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE) ;
thx for the swift advice guys. so i changed my states to this, and it''s still not working. the first texture shows right, but the second texture doesnt show up at all.

pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );pID3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );pID3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );pID3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA );pID3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );pID3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_ADD );pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1 , D3DTA_TEXTURE );pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2 , D3DTA_CURRENT );pID3DDevice->SetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_DISABLE );pID3DDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE );
Where is the alpha information?

This is currently trying to blend with the alpha that''s in the texture in stage 1. If you want the alpha from stage 0''s texture, then change BLENDTEXTUREALPHA to BLENDCURRENTALPHA.
I think it should work if you use the same setup on stage 1 that
you have on stage 0.
Also, ensure you set SetTSS(1, D3DTSS_TEXCOORDINDEX, 0), to tell D3D to use the same UV (UV set 0) on stage1. If you leave it as the default of 1, and you don''t have a second set of UVs, it''s just use the corner pixel of the second bitmap across the entire surface.
quote:Original post by Anonymous Poster
I think it should work if you use the same setup on stage 1 that
you have on stage 0.

No, that will make all pixels come from stage 1 only, with no blending in of stage 0. Nothing in stage 0 is trying to blend with a previous stage... putting that in stage 1 would make stage 0 pointless.
It works! Namethatnobodyelsetook was right on target. Adding in pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0) fixed the problem and the textures show up perfectly. awesome, thx dude.

here''s the textures stages that work. thanx to everyone who replied.
pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );pID3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );pID3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );pID3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );pID3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA );pID3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );pID3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1 , D3DTA_TEXTURE );pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2 , D3DTA_CURRENT );pID3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_ADD );pID3DDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0);pID3DDevice->SetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_DISABLE );pID3DDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE );

This topic is closed to new replies.

Advertisement