Skip to main content
gamedev.net
🔒 Locked

Alpha Blending Opacity Control

Started by noaktree Feb 18, 2005 at 12:57 PM 4 replies 2k views
Original Post
noaktree
noaktree
Greetings, DirectX has me a bit confused. I want to do alpha blending on an object that has a D3DMATERIAL9 struct applied and may or may not have a texture applied as well. The blending should be controlled by a number n=0…1 or n=0…100. The picture below (rendered with MAX) shows a sphere with different opacity levels applied to it: I have attempted to control the alpha blending in this way but have yet to find a solution using various rendering states and blending operations as well as modifying diffuse and alpha colors. The blending must be transitionally smooth from opaque to completely transparent. This seems like it should be simple to do...yet? I’d really appreciate some help solving this problem. Thanks, Neil
game development is liek a state of mind man.. it's liek when you liek... think... and then you liek make it fun++

- Yes I'm drunk.
matthughson
matthughson
Try this:

// Make it so the object can fade away
d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

Depending on how your alpha args are set up this can make it some the object will fade based on the alpha values of its diffuse material.

Hope this helps,

Matt Hughson
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
noaktree
noaktree
Thanks!

Ok I have added:

d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

I am adjusting the material diffuse alpha in real time.

What blending states and operation should I use to guarantee a smooth fade?

d3dDevice->SetRenderState(D3DRS_SRCBLEND, ?);
d3dDevice->SetRenderState(D3DRS_DESTBLEND, ?);
d3dDevice->SetRenderState(D3DRS_BLENDOP, ?);

Edit :
Quote:
Depending on how your alpha args are set up this can make it some the object will fade based on the alpha values of its diffuse material.
How should they be set up then?
game development is liek a state of mind man.. it's liek when you liek... think... and then you liek make it fun++

- Yes I'm drunk.
matthughson
matthughson
Give this a try:

d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

Matt Hughson
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
matthughson
matthughson
Also, this is what I have for those render states you asked about:

d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
d3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
d3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
d3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);

Matt Hughson
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
noaktree
noaktree
Aye!! That's the rub! [smile]
So simple yet I'm so dumb! [smile]

Thanks - points ++ for the help.
game development is liek a state of mind man.. it's liek when you liek... think... and then you liek make it fun++

- Yes I'm drunk.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.