Archived

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

darkawakenings

Using a Zbuffer/Depth Sorting - Transparency?

Recommended Posts

I just implemented a simple depth sorting mechanism with the following code: d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; (the above was in a present_parameters struct) pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); and i also clear the Zbuffer with pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(0,0,180,255), 1.0f, 0); before drawing. My Only problem is now some items that I used to be able to see through a transparent polygon are now completely blocked out by the polygon. The Polygon is still transparent, because I can still see some of the rendered images on the other side of the transparent tinted polygon. Just a couple are blocked out.

Share this post


Link to post
Share on other sites
1.) You have to disable depth writing when drawing transparent objects. You can do this with IDirect3DDeviceX::SetRenderState(D3DRS_ZWRITEENABLE,Value).

2.) You have to draw your transparent object after you''ve already drawn all your regular objects.

3.) They SHOULD be drawn from back to front in order to get correct scenes. This means you have to sort your transparent objects manually using the painter''s algorithm. Although this seems difficult, wrapping it up in a simple engine will get it done.

4.) I wouldn''t exactly say you''ve implemented a depth sorting mechanism, sinse in reality all the true work is being done behind the scenes in Direct3D. When you implement a polygon sorter for transparent object sorting, then you can proudly proclaim that. Yes you implemented it, but it''s just not something you proclaim

---
Brent Gunning | My Site

Share this post


Link to post
Share on other sites
Thanks, that helps, and good point, its easy to forget how much graphical help DirectX is giving!

So I guess its impossible to once again allow the computer to buffer for me with multiple transparencies, so ill be forced to write my own code. Then I will come back and proclaim myself!




[edited by - darkawakenings on July 28, 2003 9:55:54 PM]

Share this post


Link to post
Share on other sites