Sign in to follow this  

How to fade in/out a SRCBLEND->SRCALPHA, DESTBLEND->ONE sprite render

Recommended Posts


I'm trying to use a particly effect to create a nice colored glow, and I found the perfect combination:
d3ddevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
d3ddevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
particle image has no alpha (black background, white/grey particle.

The problem is that I can't get it to fade in/out. It seems to ignore the alpha value I pass in the last parameter of D3DXSprite::Draw().

I've tried numerous other combinations, and I can get the following combination to work with fade in/out:
d3ddevice()->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_DESTCOLOR );
d3ddevice()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
particle image has alpha (transparent background, white particle with semi transparancy)

But it just doesn't look as good.

Does anyone know how to get the alpha (fading) to work with my first setup?

The alpha (fading) code works fine for everything else, meaning my normal draws using:
d3ddevice()->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
d3ddevice()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
Work fine with the alpha stored in the final paramater of the D3DXSprite::Draw() function.

Many thanks in advance for any help/tips.

Kind regards,

Share this post

Link to post
Share on other sites
You say the second combination [i]does[/i] work fine:

[b]d3ddevice()->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_DESTCOLOR );[/b]
[b]d3ddevice()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );[/b]

...but here the alpha value isn't even used in the blending operation.

My take is you have the color and alpha values swapped in the D3DCOLOR struct (the one you pass as the last argument to the Draw method).

Edit: my mistake, D3DBLEND_DESTCOLOR does use the alpha value, but only multiplied with the src-blend's alpha value. Edited by eppo

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this