Archived

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

BrianH

D3D Alpha Blending & Texturing Question

Recommended Posts

BrianH    145
Hi all, Here is the scenario: First off, I am still using DX7. I want to be able to blend a textured polygon with the background (make it look transparent). Currently, I know how to do this for a polygon with no texture using D3DRENDERSTATE_ALPHABLENDENABLE. However, this has no effect if there is a texture applied (I am assuming texturing comes after this stage in the rendering pipeline). I have read posts and articles here suggesting that in order to do this I need to create a texture that has an alpha channel (ie R,G,B,A for each pixel). Now, what if I want to do neat effects like blending the polygon in from comlpetely transparent to completely opague? I would have to actually modify the texture? That does not sound efficient to me. What I would like to do would be to just set some texture blending state that specifies a transparency value for the entire geometry being rendered. Is this included in the texture blending operations in DX7? I dont know much of anything about these. I will continue to search but if anyone has a quick link or anything I would be most grateful. Thanks in advance, BrianH

Share this post


Link to post
Share on other sites
BrianH    145
Ok, I was looking in some books and in the DX7 docs and found stuff about texture stages and alpha blending and all that fun. It seemed like from what I read that I can use the alpha value in the current material''s diffuse color as my alpha value. Is this the code I want in order to produce the effect (see above post)?


lpd3dd->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
ld3dd->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
lpd3dd->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

lpd3dd->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 );
lpd3dd->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );


thanks,

BrianH

Share this post


Link to post
Share on other sites
ZeroBit    122
quote:

What I would like to do would be to just set some texture blending state that specifies a transparency value for the entire geometry being rendered. Is this included in the texture blending operations in DX7?


No, there is no transparency value in texture blending states.

There are several ways to create fade in / fade out effect.

1st. By modifying the material.
Set appropiate color operation for the texture (refering to diffuse color of the vertices) , therefore by raising/decreasing the RGB value of the material data, the result of d3d lighting calculation in diffuse color would goes brighter or dimmer, resulting the texture seem fading in / fading out.

2nd. By modifying the diffuse color in the vertices.
Just turn of d3d lighting calculation and manually change the diffuse color of the vertices to create fading in / out effect.

3rd. By modifying the alpha value of the texture (slow).

4th. By modifying the actual color value of the texture (even slower).

Share this post


Link to post
Share on other sites
BrianH    145
WOOOT!

Figured it out! At first I tried just those SetTextureStageState commands but it does not work. The problem turned out to be that I had to rememeber to enable alpha blending using the D3DRENDERSTATE_ALPHABLENDENABLE thing in SetRenderState. Yay. Now I can fade a polygon in by just changing the materials'' diffuse color value (the alpha part at least).

ZeroBit: Thanks for the reply, but I think maybe my question was unclear or you misread it. I did not want to fade in from dark to light, but from fully transparent to fully opague. Of course, I guess on a black background both would accomplish the same thing. But you were correct, I had to use the material color not just some specified alpha value in the blending stage.


BrianH

Share this post


Link to post
Share on other sites
ZeroBit    122
BrianH,

Remember that you can also achieve transparency by setting

D3DBLEND_SRCCOLOR and
D3DBLEND_INVSRCCOLOR

other than

D3DBLEND_SRCALPHA and
D3DBLEND_INVSRCALPHA

for the source and destination blend value.
So, if you had a black background on the source image, you still have the transparency effect, it wont be fully opaque.

Share this post


Link to post
Share on other sites
ekenslow    122
I found a pretty good tool for visualizing texture stage state changes, or at least the major texture stage states that ATI cards support, on the ATI web site. It seems to work OK on other cards, although it''s apparently pretty old (its readme says it''s written for DX 6). I believe there''s an OpenGL version of it on the ATI site as well.

MulTex for Direct3D


--
Eric

Share this post


Link to post
Share on other sites