Advertisement Jump to content
Sign in to follow this  

need a little help on my particle

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

ive implemented a simple explosion partice and i want to fade the alpha of each particle for every frame but the fading part is not working heres how i implement it
void CParticle::Update( float elapsed )
	m_vPos += m_vVelocity * elapsed;
	m_fAlpha -=  m_fAlphaDecay * elapsed;
	m_color = D3DCOLOR_COLORVALUE(m_fRed,m_fGreen,m_fBlue,m_fAlpha);

and heres my RenderState for the particle
	m_pGfx->GetDevice()->SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);
	m_pGfx->GetDevice()->SetRenderState(D3DRS_POINTSIZE, FtoDW(m_iParticleSize));
	m_pGfx->GetDevice()->SetRenderState(D3DRS_POINTSCALE_A, FtoDW(0.0f));
	m_pGfx->GetDevice()->SetRenderState(D3DRS_POINTSCALE_B, FtoDW(0.0f));
	m_pGfx->GetDevice()->SetRenderState(D3DRS_POINTSCALE_C, FtoDW(1.0f));

	m_pGfx->GetDevice()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	m_pGfx->GetDevice()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
	m_pGfx->GetDevice()->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);	
	m_pGfx->GetDevice()->SetRenderState(D3DRS_ZWRITEENABLE, FALSE );

what seems to be wrong with this? during update of the particle you can see that i decrease the alpha value per frame and create a new color from it but it doesnt seem to work

Share this post

Link to post
Share on other sites
Alpha blending uses additive blending by default so the alpha of the final rendered pixel is (sourceAlpha + destAlpha). In your case destAlpha is 1.0 so the final alpha is at least 1.0, i.e. always fully visible. Try setting the D3DRS_DESTBLEND render state to D3DBLEND_ZERO. Then the final alpha will be (sourceAlpha + 0.0), i.e. the sourceAlpha.

If you don't want additive blending you can change it through the D3DRS_BLENDOP render state.

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!