Alpha blending 3 polygons?

Started by
2 comments, last by raccoonone 18 years, 2 months ago
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?
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.
--------------------------Most of what I know came from Frank D. Luna's DirectX books
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]

My project`s facebook page is “DreamLand Page”

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.

This topic is closed to new replies.

Advertisement