Archived

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

Problem with multitexturing (2 textures, both have alpha)

This topic is 5775 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''m trying to blend two textures in a single pass. I have a GeForce 2, which can do all this, and I have the two 32-bit textures checked out in DXTexTool - so I know their alpha channel is set correctly. The first stage (0), has full alpha, so, I want it''s output to be completely opaque (solid). Say I want this to be rock. The next stage (1) is grass, but it''s alpha channel is more complex, so I want to see rock through some areas, and completely grass in the other areas. So: iD3DDev8->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); iD3DDev8->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); iD3DDev8->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); iD3DDev8->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); iD3DDev8->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); iD3DDev8->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); iD3DDev8->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); iD3DDev8->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); iD3DDev8->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); iD3DDev8->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); iD3DDev8->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE ); iD3DDev8->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); iD3DDev8->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); For each stage, the colour is the texture RGB x vertex diffuse. The alpha grabs from the texture, and blends what''s currently being done in that stage, with the destination (i.e. what''s "already there" - "dest"). At stage 0 "dest" is just the black background, right? In my mind, when I get to stage 1 - what''s "already there" (in "dest") *should* be my solid rock - which was opaque, and done in stage 0. Why is it not? Or should it be? It seems that I can''t get the results of stage zero into "dest" - it just reads out the black from the back buffer. All I see is my grass layer (from stage 1) rendererd with alpha correctly, but instead of seeing rock where there''s no grass, I see the black background...I know this is not multi-pass, and the backbuffer isn''t altered until all blend stages are complete, but surely I *can* do this with multi-texturing??? Can somebody please help me out here? =( -Spiral

Share this post


Link to post
Share on other sites
Try using the MFC Texture example that comes with DXSDK with your textures and settings to see if it can do it right.

Edited by - Joeyblow2 on February 21, 2002 3:44:27 PM

Share this post


Link to post
Share on other sites
iD3DDev8->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
iD3DDev8->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);

HTH

quote:
Original post by SpiralGuru3d
Hey guys,

I''m trying to blend two textures in a single pass. I have a GeForce 2, which can do all this, and I have the two 32-bit textures checked out in DXTexTool - so I know their alpha channel is set correctly.

The first stage (0), has full alpha, so, I want it''s output to be completely opaque (solid). Say I want this to be rock.

The next stage (1) is grass, but it''s alpha channel is more complex, so I want to see rock through some areas, and completely grass in the other areas.

So:

iD3DDev8->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
iD3DDev8->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
iD3DDev8->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

iD3DDev8->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
iD3DDev8->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

iD3DDev8->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
iD3DDev8->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
iD3DDev8->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

iD3DDev8->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
iD3DDev8->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

iD3DDev8->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE );
iD3DDev8->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
iD3DDev8->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

For each stage, the colour is the texture RGB x vertex diffuse. The alpha grabs from the texture, and blends what''s currently being done in that stage, with the destination (i.e. what''s "already there" - "dest"). At stage 0 "dest" is just the black background, right?

In my mind, when I get to stage 1 - what''s "already there" (in "dest") *should* be my solid rock - which was opaque, and done in stage 0. Why is it not? Or should it be?

It seems that I can''t get the results of stage zero into "dest" - it just reads out the black from the back buffer.

All I see is my grass layer (from stage 1) rendererd with alpha correctly, but instead of seeing rock where there''s no grass, I see the black background...I know this is not multi-pass, and the backbuffer isn''t altered until all blend stages are complete, but surely I *can* do this with multi-texturing???

Can somebody please help me out here? =(

-Spiral


Share this post


Link to post
Share on other sites
Hmmm...

Now, it seems the first texture can''t have alpha. If it does, where *that* is transparent, nothing comes through in stage 1 either.

Damn it, so if I wanted a red cross (stage 1, and alphaed texture) over an icon background (stage 0, alphaed texture, just rounded corners say) - it wouldn''t entirely work right.

What is it about D3DTOP_BLENDTEXTUREALPHA that occludes stuff in stage 1 - the current for that texture stage state?

-Spiral

-- Give me a hard copy right there ---

Share this post


Link to post
Share on other sites
Look:

iD3DDev8->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
iD3DDev8->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

This means: In the second blending stage, ignore incoming alpha from the previous stage and only use the alpha from texture in the second blending stage.

Try:

iD3DDev8->SetTextureStageState( 1, D3DTSS_ALPHAOP, MODULATE);
iD3DDev8->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
iD3DDev8->SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT);

quote:
Original post by SpiralGuru3d
Hmmm...

Now, it seems the first texture can''t have alpha. If it does, where *that* is transparent, nothing comes through in stage 1 either.

Damn it, so if I wanted a red cross (stage 1, and alphaed texture) over an icon background (stage 0, alphaed texture, just rounded corners say) - it wouldn''t entirely work right.

What is it about D3DTOP_BLENDTEXTUREALPHA that occludes stuff in stage 1 - the current for that texture stage state?

-Spiral

-- Give me a hard copy right there ---


Share this post


Link to post
Share on other sites
Well, modulating alpha between layers doesn''t work - for an opaque pixel over a translucent one - you get 256 x 0 - so, nothing visible!

This works:

STSS( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
STSS( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

STSS( 1, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA );

STSS( 1, D3DTSS_ALPHAOP, D3DTOP_ADD );
STSS( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
STSS( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT);

So, additive alpha, naturally you get opaque pixels that are set over clear ones.

Now, that D3DTOP_BLENDTEXTUREALPHA in stage 1, I don''t understandm if you can help me with that I''d really appreciate it.

If I replace that with:

STSS( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
STSS( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );

I get the texture from stage 1 showing up where texture *should* show up in stage 0???

What is D3DTOP_BLENDTEXTUREALPHA''s equivalent, in sub-texture stage states?

Thanks!

-Spiral



-- Give me a hard copy right there ---

Share this post


Link to post
Share on other sites