Jump to content
  • Advertisement
Sign in to follow this  
tuxbook

Alpha: Adjustable and partly transparent?

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

Hi All, I have adjustable alpha working using BLENDFACTOR like this:
unsigned char alpha = (int)(m_Alpha*255.0f);

union AlphaUnion
{
	DWORD dw;
	unsigned char bytes[4];
} alpha_full;

alpha_full.bytes[0] = alpha;
alpha_full.bytes[1] = alpha;
alpha_full.bytes[2] = alpha;
alpha_full.bytes[3] = alpha;

m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_Device->SetRenderState(D3DRS_BLENDFACTOR, alpha_full.dw);
m_Device->SetRenderState(D3DRS_SRCBLEND,  D3DBLEND_BLENDFACTOR);
m_Device->SetRenderState(D3DRS_DESTBLEND,  D3DBLEND_INVBLENDFACTOR);
But I also want to use the texture's alpha channel like this:
m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

m_Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
m_Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

m_Device->SetTextureStageState(0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1);
m_Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
Both methods require setting something different to the D3DRS BLEND flags. How can I have both adjustable alpha and use texture alpha? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You can modulate (multiply) the alpha in the texture stages. You can use the texture factor for that.

Share this post


Link to post
Share on other sites
Thanks, that worked great!

For anyone interested, here's the code.


m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

m_Device->SetRenderState(D3DRS_TEXTUREFACTOR, alpha_full.dw);

// Multiply texture alpha with adjustable alpha colour
m_Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
m_Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_Device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!