Advertisement Jump to content
Sign in to follow this  

Manual Alpha Blend + Additive Blend

This topic is 4967 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've run into a bit of a problem with my render/texture states. A while back I implemented the ability to manually fade out textures via the diffuse component of its material. It's worked fine ever since. Recently I added the ability to turn on addative blending on for textures. That worked fine as well. That is until I tried using them both at once. If I try to fade a texture out while it is being addativly blended, it becomes basically a binary alpha blend; that is it's either full on (when its alpha is greater than zero) or completely transparent (less than or equal to zero). Here is is the code I use for setting up those states:
	// Make it so the object can fade away
	m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
	m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
	m_pD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
	m_pD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
        // Turn on additive blending

I imagive the problem is that one is over riding the other, but I'm not sure how I might fix it. Any suggestions? Thanks guys, Matt Hughson

Share this post

Link to post
Share on other sites
Sorry, but your setup makes no sense [smile]

Why do you use the same setting on both of your texture blending stages? If you don't use D3DTA_CURRENT as argument on stage 1 then you're discarding the data from stage 0.

Remember, all texture blending stages will be blended with each other to produce the final texture to use in the rendering.

Also, by setting both the source and destination blending factor to one you exclude the your final texture alpha value from the blending algorithm, so it shouldn't affect the visibility at all. What happens with negative alpha seems like unexpected behavior by the device.

Try this setup instead using one stage (haven't tried it but...)

m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); /* Default */
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); /* Default */
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_CURRENT ); /* Default, translates to D3DTA_DIFFUSE for stage 0 */

m_pD3DDevice->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_ADD ); /* Default */
m_pD3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
m_pD3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );

If you want to add another texture stage then make sure you keep alphaarg2 at the default value so that the previous stage result is not excluded from the blending.

Stay sharp.

[EDIT] The binary alpha blend you speak of sounds a lot like what happens if alpha testing (D3DRS_ALPHATESTENABLE render state) is turned on and set to reject pixels with alpha equal to or below 0. This is not on by default so if it is on it has to have been turned on manually.

Share this post

Link to post
Share on other sites
Original post by staaf
Sorry, but your setup makes no sense [smile]

That doesn't surprise me really. I'm still pretty new to DirectX, and had that code pretty much handed to me, so I never really took the time to figure it our completly.

Thanks for the suggestions though, I'll give it a try tommorow probably.

Matt Hughson

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!