Jump to content
  • Advertisement
Sign in to follow this  
Melanikus

Texture Alpha blending

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

Hey guys, I made this particle system and I'm using point sprites with alpha, I was wondering what was the correct set of parameters to set. My alpha-blending function is set to device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA); device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_DESTALPHA); My point sprites are being blended, but not using the texture's alpha channel, so I set up device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA ); device->SetTextureStageState(0, D3DTSS_ALPHAARG1,D3DTA_TEXTURE); device->SetTextureStageState(0, D3DTSS_ALPHAARG2,D3DTA_TEXTURE); And no luck... I'm not familiar with DirectX's SetTextureStageState =/

Share this post


Link to post
Share on other sites
Advertisement
You probably want:

device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

// Or:
device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);

Share this post


Link to post
Share on other sites
Yeah, those texture stage things are for multitexture blending, the thing is, when I calculate the alpha blending I'm not getting the texture's alpha =/

(A tga with alpha channel on it)

Share this post


Link to post
Share on other sites
Ok... getting closer

I disable ZWRITEENABLE and it looks perfect, but of course, it's based on draw order, so no good, the thing is, I'm not blending with stuff behind the particle, I think it's because I'm discarding pixels on ZFail... how can I change that? I cannot just disable write (because it'll then use draw order) and I cannot enable it (because it'll discard any other particle without blending) isn't alpha blending supposed to change this to store Z pixels?

Share this post


Link to post
Share on other sites
Quote:
Original post by Melanikus
Ok... getting closer

I disable ZWRITEENABLE and it looks perfect, but of course, it's based on draw order, so no good, the thing is, I'm not blending with stuff behind the particle, I think it's because I'm discarding pixels on ZFail... how can I change that? I cannot just disable write (because it'll then use draw order) and I cannot enable it (because it'll discard any other particle without blending) isn't alpha blending supposed to change this to store Z pixels?
Generally you render all opaque geometry with Z-writes on, and then you render alpha'd geometry in back-to-front order, with Z-writes disabled but Z-test enabled.
You need to render in back-to-front order so that the alpha blending works correctly; alpha'd objects need to alpha against what's behind them, not a blank backbuffer.

Share this post


Link to post
Share on other sites
Indeed... I thought it was more like, draw everything and blend later, but that would require N color buffers for each geometry/alpha geometry pair I think...

Anyway, even tho I have this hierarchical graph for rendering everything I already have a similar solution, every light that is created sends a message to my renderer to tell it to add it to the scene and turn it on, opposed to draw the graph and switch it on when a light node comes up, I can use this same system to send a message to post draw any particle systems I have...

Thanks for your time! really appreciate it, problem solved

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!