Changing the alpha of a point sprite

Started by
15 comments, last by Miksan 20 years, 6 months ago
Well, it still doesn't work...

I'll put the code again:

SetRenderState(D3DRS_LIGHTING, FALSE);SetRenderState(D3DRS_ZWRITEENABLE, FALSE);SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);SetRenderState(D3DRS_POINTSCALEENABLE, FALSE);SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1);SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);float size = 40.0f;SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&size));SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);


Now with full alpha (255) I've got my particles like this:
Not working
Here's the same situation, but I've disabled the alpha:
Working

With zero alpha, I can't see anything, which seems to be just what I'm lookin here. Though the particles render quite wrong... I think that the solution might be just one little switch somewhere...



[edited by - Miksan on October 23, 2003 1:22:42 PM]
Advertisement
If you are using additive blending (ONE:ONE) for the fire, then the correct way to fade a particle is to darken its colour, instead of decreasing its alpha value.

Forget about alpha-blending for a second and try this:

SetRenderState(D3DRS_LIGHTING, FALSE);
SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
SetRenderState(D3DRS_POINTSCALEENABLE, FALSE);
SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1);
SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);
SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);

float size = 40.0f;
SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&size));
SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);

Then use the alpha value you are calculating for each particle to multiply its colour, so as a particle gets older it gets darker.

In this case, you should REALLY use texture-alpha. Add an alpha-channel into your texture, and set Direct3D to use the texture''s alpha-channel.

--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..
Try some (or all) of these...

  p_Device->SetRenderState(D3DRS_ALPHATESTENABLE,         TRUE);  p_Device->SetRenderState(D3DRS_ALPHAREF,                0x01);  p_Device->SetRenderState(D3DRS_ALPHAFUNC,               D3DCMP_GREATEREQUAL);  p_Device->SetRenderState(D3DRS_COLORVERTEX,             TRUE);
quote:Original post by JoeyBlow2
Try some (or all) of these...
<hr height=1 noshade></SPAN></BLOCKQUOTE>Those are for alpha testing.
Here's a pic of the same lava fire version, but now I'm trying to fade the color as the particle gets older.

With color fade

When the particle is added, I calculate the fade constant, which is the original color value divided by the lifetime. Then I substract that constant from the fade variable every iteration. Fade is at the start 1.0. Fade is actually three dimensional vector for every color. Then I use this macro to place the color to the particles color variable:

m_particleVerts[iCount].color = D3DCOLOR_XRGB((int)((((*it)->color >> 16) & 0xFF) * (*it)->vFade.x), (int)((((*it)->color >> 8) & 0xFF) * (*it)->vFade.y), (int)(((*it)->color & 0xFF) * (*it)->vFade.z));

Obviously something is kicking my ass here.

quote:Original post by Pipo DeClown
In this case, you should REALLY use texture-alpha. Add an alpha-channel into your texture, and set Direct3D to use the texture's alpha-channel.


Could you explain a bit more?


edit: forgot to mention that the particle doesn't fade anywhere with this...

[edited by - Miksan on October 23, 2003 2:51:07 PM]
quote:Original post by Miksan
quote:Original post by Pipo DeClown
In this case, you should REALLY use texture-alpha. Add an alpha-channel into your texture, and set Direct3D to use the texture''s alpha-channel.

Could you explain a bit more?
Textures in certain format (ie PNG, TGA, DDS) can have its own alpha channel. However, this is for the texture itself and can''t be modified at runtime (correct me if I am wrong), though you still can use it for alpha blending.

If everything still doesn''t work, try this.

This topic is closed to new replies.

Advertisement