Skip to main content
GameDev.net gamedev.net
🔒 Locked

Depth Buffer Issues? (Pic Inside)

Started by datadawgx May 22, 2006 at 8:27 PM 5 replies 950+ views
Original Post
datadawgx
datadawgx
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
ViLiO
ViLiO
Having a znear of 0.0 could cause this problem. What is your device's projection matrix set to?

Regards,
ViLiO
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
datadawgx
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. =)
Evil Steve
Evil Steve
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.
QuadMV
QuadMV
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.


3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.
Thergothon
Thergothon
EDIT: beaten. didnt realise you fixed it already.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.