• 13
• 18
• 19
• 27
• 10

# Texture Alpha blending

This topic is 3066 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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 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 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 on other sites
Quote:
 Original post by MelanikusOk... getting closerI 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 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