Sign in to follow this  

Depth Buffer Issues? (Pic Inside)

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

Hey guys, I'm having a wierd depth buffer problem. I am drawing a simple city and buildings are sometimes (not always) showing up in the wrong order(farthest buildings show in front of closer buildings). Below is an image of the problem: http://www.seanazlin.com/images/wtf.jpg
You'll notice that bldg 3 shows up in front of bldg 1 and 2, and 2 shows up in front of 1. We should be seeing 1, 2, and then 3 from closest to farthest. In the center of the screen I have 2 towers that are also showing up in the wrong order. I'm thinking something is wrong with my render states. Here's what I am setting:
g_pdevice->SetRenderState(D3DRS_ZENABLE,  TRUE ); // Z-Buffer (Depth Buffer)
g_pdevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW ); 
g_pdevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pdevice->SetRenderState(D3DRS_AMBIENT,  D3DCOLOR_XRGB(180, 180, 180));
g_pdevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID);
...
g_pdevice->BeginScene();
g_city1.Render(g_pdevice);
g_pdevice->EndScene();


this isnt all of the source, but it is all of the render states. i've tried messing with everything and looking through the sdk with no success. Anyone have an idea of what's going wrong? -Sean

Share this post


Link to post
Share on other sites
Quote:
Original post by datadawgx
good call. I know not to set it to 0, but I was setting it to 0.001... and that turns out to be the prob. Setting it to 0.01 fixed it.

thanks. =)
I wouldn't even set it that low. If you're rendering on that sort of scale (Assuming the buildings are a few hundred to a few thousand units high), I'd set the front clipping plane to at least 1.0f. I don't remember the exact numbers, but something like 75% of the z-buffer accuracy is used in the first 25% of the range.

Share this post


Link to post
Share on other sites
You might also consider changing the z-near based on the environment. For example when indoors you might want to get very close to the wall and set it small, but since your site range is less indoor, you can set z-far smaller. When outdoors you'll bump them both up. This isn't perfect, but can provide benefit.


Share this post


Link to post
Share on other sites

This topic is 4224 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.

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