Archived

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

Multitexturing (SetTextureState)

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

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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) ;

Share this post


Link to post
Share on other sites
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 );

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think it should work if you use the same setup on stage 1 that
you have on stage 0.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 );

Share this post


Link to post
Share on other sites