Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Miksan

Changing the alpha of a point sprite

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

I have set my rendered like this: SetRenderState(D3DRS_LIGHTING, false); SetRenderState(D3DRS_ZWRITEENABLE, false); SetRenderState(D3DRS_ALPHABLENDENABLE, true); SetRenderState(D3DRS_POINTSPRITEENABLE, true); SetRenderState(D3DRS_POINTSCALEENABLE, true); SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); float size = 100.0; SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&size)); The point sprite''s vertex is like this: #define PARTICLEVERTEX_FVF (D3DFVF_XYZ | D3DFVF_DIFFUSE) struct PARTICLEVERTEX { D3DVECTOR vPosition; D3DCOLOR color; }; Now how do I get this to work? color = D3DCOLOR_ARGB(255, 255, 255, 255); // Fully opaque point sprite color = D3DCOLOR_ARGB(0, 255, 255, 255); // Fully transparent point sprite The problem is that the point sprites visibility isn''t affected at all when changing the alpha value. I''d like to simulate the particle''s lifetime with the alpha value. Thanks for suggestions!

Share this post


Link to post
Share on other sites
Advertisement
You need to set the src and destblends correctly.
D3DBLEND_SRC and D3DBLEND_INVSRC iirc, which i probably
don''t, since i haven''t done this for a year or something like that

Share this post


Link to post
Share on other sites
Try to remember, please

SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);

That gives some quite funny results... There is such many combinations, that I won''t ever find the right one...

Share this post


Link to post
Share on other sites
quote:
Original post by Miksan
Try to remember, please

SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);

That gives some quite funny results... There is such many combinations, that I won't ever find the right one...


Use D3DBLEND_SRCALPHA for D3DBLEND_SRCCOLOR.
Use D3DBLEND_INVSRCALPHA for D3DBLEND_INVSRCCOLOR.

And you should set the Alpha Texturestates to use Argument1 and set Argument1 to diffuse:
SetTextureStageState( 0, D3DTTS_ALPHAOP, D3DTOP_SELECTARG1 );
SetTextureStageState( 0, D3DTTS_ALPHAARG1, D3DTA_DIFFUSE );


--
You're Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..

[edited by - Pipo DeClown on October 23, 2003 10:08:13 AM]

Share this post


Link to post
Share on other sites
I still don't get it. Here's what I tried:


SetRenderState(D3DRS_LIGHTING, false);
SetRenderState(D3DRS_ZWRITEENABLE, false);
SetRenderState(D3DRS_POINTSPRITEENABLE, true);
SetRenderState(D3DRS_POINTSCALEENABLE, false);
SetRenderState(D3DRS_ALPHABLENDENABLE, true);
SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCALPHA);

SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);

float size = 50.0f;
SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&size));


Here are the results:

D3DCOLOR_RGBA(255, 255, 255, 255): Alpha 255
D3DCOLOR_RGBA(255, 255, 255, 0): Alpha 0

What should I do?

[edited by - Miksan on October 23, 2003 10:54:20 AM]

Share this post


Link to post
Share on other sites
SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

is what you want I think.

Try to think of it in terms of a blending equation. The end result will be (SrcBlend*SrcColor) + (DestBlend*DestColor).

Share this post


Link to post
Share on other sites
I''m sorry, but even that doesn''t work. I''m quite newbie in these things, so I''m not able think it out myself. I''ve been trying with some variations, but it feels weird cause I really don''t know what am I doing...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Don''t ever use "true and false" in place of "TRUE and FALSE". You''ll get unexpected results sometimes.

Share this post


Link to post
Share on other sites
You need to tell DirectX where to get its colors from. The vertex or the material. Just because you have diffuse color in the vertex buffer doesn''t mean DirectX is going to use that one, you need to tell it specifically with these commands:


p_Device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1);
p_Device->SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR2);
p_Device->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
p_Device->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);



(Since you do not an emissive color in the vertex, you would change that renderstate to be material)

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Don''t ever use "true and false" in place of "TRUE and FALSE". You''ll get unexpected results sometimes.


You sure? Cause I''d like to know more about this.

--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!