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

Started by
0 comments, last by eppo 11 years, 7 months ago
Hello,

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?

Ps:
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,
Michaël
Check my games out at:http://www.GamePlayHeaven.com
Advertisement
You say the second combination does work fine:

d3ddevice()->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_DESTCOLOR );
d3ddevice()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );

...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.

This topic is closed to new replies.

Advertisement