• Advertisement
Sign in to follow this  

Alpha blending 3 polygons?

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

I just added items into my game, but ran into a problem with DirectX. I'm using Z-buffering, and alpha blending.
pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
//Set alpha blending
pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
The zbuffers are set so that the ground is drawn first (0.99f), then items (0.2f) and players on the top (0.01f). Everything works fine when there's an item on the ground, or just a player. But when a player is standing on top of an item, the item disappears and it just shows the ground and the player. I created the device with AutoDepthStencil also.
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.EnableAutoDepthStencil = TRUE;
Is there something else that I need to set if I want 3 polygons in the same place, that are all alpha blended?

Share this post


Link to post
Share on other sites
Advertisement
You may be getting something called z-fighting. This can happen if the depth of the second item draw is the same as the first. The depth may be the y-axis value for your object. Try turning off z-buffering to see what happens.

Share this post


Link to post
Share on other sites
Hi there!
You didn't mentioned a thing about wich object is transparent and wich is not.

When drawing alpha blended objects you must follow a couple of rules:
The transparent object must be rendered after all solid objects have been rendered.
When having more than one transparent object, all transparent objects must be rendered in a back to front order. ( The object that is furthest is rendered first and the one that is the closest is rendered last.)

Do a search on GameDev for 'alpha blending'. You will get a lot of threads om this subject.

[Edited by - Calin on January 24, 2006 8:03:06 AM]

Share this post


Link to post
Share on other sites
Ah, yes, that was the problem. I wasn't drawing the transperent objects in back to front order. I thought since I had enabled Z-buffer I could render them in whatever order I wanted.

Share this post


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

  • Advertisement