Archived

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

nPawn

Fading out a 3D object using Alpha Blend?

Recommended Posts

I'm trying to slowly make a texture on a D3DXMESH object fade out using alphablending as time passes: LPDIRECT3DTEXTURE8 m_ptextureGreenPlasma; pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_DESTALPHA); pd3dDevice->SetTexture( 0, m_ptextureGreenPlasma); m_meshSphere1.DrawShape(x, y, z); m_ptextureGreenPlasma was loaded previously with D3DXCreateTextureFromFileEx(), and the mesh m_meshSphere1 was made with D3DXCreateSphere(), and this blending works great, but how do i go about making it fade out slowly? It seems I would need to slowly turn down the alpha value of the source texture, but i'm not sure how to change the textures alpha channel now? Or perhaps there's a better way to go about it? BTW this is DX 8.0 Edited by - nPawn on October 22, 2001 2:52:47 PM

Share this post


Link to post
Share on other sites
Look into the blend factor. you should be able to set it with SetTextureStageState and then arrange the states to include that in your texture blending operation. (Look at SetTextureStageState in general)

Share this post


Link to post
Share on other sites
Pardon my ignorance but I haven''t used the SetTextureStageState() function yet (so much to this 3D stuff, hehe) and i''m having a hard time finding what you are talking about in dozens of options, are you referring to D3DTSS_ALPHAARG0? It''s descriptions has baffled me more then helped =): "Settings for the alpha channel selector operand for triadic operations".

Would I do something like SetTextureStageState(D3DTSS_ALPHAARG0, 0xffffff77);

where the 77 is the alpha value i set?

Share this post


Link to post
Share on other sites
Sorry I don''t have source code handy...

Look at the MFCTex sample and in the docs:

D3DTA_TFACTOR
The texture argument is the texture factor set in a previous call to the IDirect3DDevice8::SetRenderState with the D3DRS_TEXTUREFACTOR render-state value. Permissions are read-only.

You''ll want to do something like this:
Set your alpha op to multiply (modulate)
set your alphaargs to texture and tfactor
set the tfactor as described above
render

Does that make sense? Play with MFCTex. It won''t be easy to see alpha ops, but if you get the feel for color ops, alpha will be the same.

Share this post


Link to post
Share on other sites
G''day!

Here''s a code bit to illustrate:

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

device->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
device->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );
device->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );

device->SetRenderState(D3DRS_TEXTUREFACTOR,0x77FFFFFF);

The texture factor is a D3DCOLOR and is ARGB, so the 77 is the alpha value.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
Thanks for the help, it''s working great, other than it''s also fading all my other textures now so i have to figure out how to turn that operation off, heh, but that shouldn''t be too hard to do. I appreciate all your help!

Share this post


Link to post
Share on other sites