Archived

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

toroso

Draw primitive with alpha blending causes problems with transparency

Recommended Posts

Hi all! I want to change the color of my texture when drawing it using alpha blending technique. I can''t seem to get it right though, as I always get one out of two errors: 1) Transparency doesn''t work 2) The backgruond color influences the alpha blending Here are some snippets from my code: pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); These properties work perfect if the background color is set to black. A white pixel in my texture becomes red if I set the diffuse color in my vertex buffer to red. However, if I have a blue background, the same pixel will become purple! That is, the background color is part of the blending. If I instead change the D3DRS_DESTBLEND to for instance D3DBLEND_ZERO, the pixel does become red as it should, but instead the transparency information is neglected. Any information that would help me solve this is appreciated.

Share this post


Link to post
Share on other sites
You have to draw all solid faces of your world first, then you have to render your transparent stuff and set zwrite to 0 before rendering transparent stuff (don''t forget to set zwrite to 1 when rendering solid stuff)

It''s normal that the color of your object mixes with the background color, because this is what alpha-blending do, it mixes the color of your object with the color of the stuff wich is already there -> your background!

Share this post


Link to post
Share on other sites
I may be missing something here. but shouldnt you be setting the texture stage state to enable alpha operation

  
pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);



:::Al:::
[Triple Buffer] - Resource leak imminent. Memory status: Fragile

Share this post


Link to post
Share on other sites
Lupin:
As I understand your answer I should draw things starting from the front and go backwards...?

I''m actually working in 2D, and that''s why the question is a bit basic. I''m used to drawing the background first and then adding things on top of it. But since 2D in DirectX 8 is a special case of 3D, I probably should do things as they are done in 3D.


alfmga:
Sorry about my poor lingo. I actually don''t want to modulate the alpha channel, only the RGB channels.

Share this post


Link to post
Share on other sites
ALPHA-blending could ONLY manipulate the ALPHA-channel, RGB is unchanged.

ALPHA-blending means to turn something into an transparent object, you could blend transparent and solid objects together to one object to get an solid object wich looks like it has changed RGB values, but Alpha-blending only changes the alpha-values of your object

Share this post


Link to post
Share on other sites