Sign in to follow this  
StratBoy61

Simple (?) Alphablending question... SOLVED

Recommended Posts

StratBoy61    232
Hello, I have one sphere and one box. I created them using the DirectX CreateSphere and CreateBox functions. Now, I decided that the box's height would be zero. I display it many times, tiled on the ground, so it gives the aspect of a grid. Both box and sphere objects are both D3DRS_ALPHABLENDENABLE = TRUE and both D3DRS_SRCBLEND and D3DRS_DESTBLEND = D3DBLEND_SRCALPHA. Image 1 Image 2 Now, why the heck is the portion of the sphere which is *under* the grid, displayed when the grid is D3DFILL_WIREFRAME (Image 1), and not visible when the grid is D3DFILL_SOLID (Image 2). The sphere is always D3DFILL_SOLID, and I can see the grid through it. Why cannot I see the part of the sphere through the solid grid ? Another question is : What should I do if I want the grid to be D3DFILL_WIREFRAME and *not* display the part of the sphere that is below it (Like Image 2 but with wireframe grid)? Thank you in advance Cheers StratBoy61 [Edited by - StratBoy61 on March 17, 2006 2:01:16 PM]

Share this post


Link to post
Share on other sites
StratBoy61    232
Quote:
Original post by Namethatnobodyelsetook
The grid is drawing to the Z buffer. The sphere's lower pixels are being Z rejected because the ground plane is considered closer.

Thank you for your answer.
However, it does not make more sense to me. The ground plane is supposed to be transparent, so I should see through it, no ? What does it have to do with Z buffer here ?
Also, do you mean that if I move the sphere closer to the viewpoint than the grid is, it will then no longer be transparent ?
Image 3
I am sorry but I am really lost here...

-edit-

Well, I started rendering the sphere before the ground, and now I can no longer see through it... So does it mean that when one wants to deal with transparency, one has to make sure the object are rendered in a certain order from the viewpoint ?
Image 4
So what do I do if I want to be able to see through both objects, the sphere and the ground ?
Also, what can I do if I want the lower part of the sphere *not* to be displayed while using D3DFILL_WIREFRAME ?

Share this post


Link to post
Share on other sites
Muhammad Haggag    1358
Quote:
Original post by StratBoy61
Thank you for your answer.
However, it does not make more sense to me. The ground plane is supposed to be transparent, so I should see through it, no ? What does it have to do with Z buffer here ?
[...]
-edit-
Well, I started rendering the sphere before the ground, and now I can no longer see through it... So does it mean that when one wants to deal with transparency, one has to make sure the object are rendered in a certain order from the viewpoint ?

Transparency (via alpha-blending) is order-dependent. You have to draw the objects far-to-near. You can read up on order-independent transparency if you like.

Share this post


Link to post
Share on other sites
CodeReaver    131
Quote:
Original post by StratBoy61
So what do I do if I want to be able to see through both objects, the sphere and the ground?


You could use something like pD3DDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS) or try experimenting with a few of these:

D3DCMP_NEVER
D3DCMP_LESS
D3DCMP_EQUAL
D3DCMP_LESSEQUAL
D3DCMP_GREATER
D3DCMP_NOTEQUAL
D3DCMP_GREATEREQUAL
D3DCMP_ALWAYS

But it depends on the situation which will work best.

More info here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/d3dcmpfunc.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/Changing_Depth_Buffer_Comparison_Functions.asp

The order independant transparancy that Muhammad Haggag mentioned would probably work better but might be more complicated. I can't check, though because google doesn't seem to be working for me right now.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this