Problem with geometry sorting

Started by
7 comments, last by LordFallout 16 years, 3 months ago
For some reason certain farther back parts of my geometry show up infront of closer parts of my geometry, its not a uniform problem, the sections that appear in front are different whenever i move. I uploaded an image, anybody any idea what might cause such an problem?? Im doing the texturing in a effects file, i dont think that makes any difference but thought i would mention it in case. Image Hosted by ImageShack.us The brown bits should be behind the green bits.
Advertisement
Looks like a Z-buffer problem to me. What bit depth is your Z-buffer? 16 bits or lower is usually bad for sorting like this. Also, what are the values for your near and far clip planes? Having a close near clip plane is bad, because the Z range isn't linear; something like 70% of the Z-buffer range is used in the first 30% of the scene. Similarly, having too big of a difference between near and far clip planes can cause problems, you certainly shouldn't be setting your far clip to anything more than 10000.0f (And the lower the better).
Sorry if this is a stupid question, but are you using the depth buffer? I ask because from the title of your post one might think you are sorting the geometry yourself (if you are - why?).
Quote:Original post by Evil Steve
Looks like a Z-buffer problem to me. What bit depth is your Z-buffer? 16 bits or lower is usually bad for sorting like this. Also, what are the values for your near and far clip planes? Having a close near clip plane is bad, because the Z range isn't linear; something like 70% of the Z-buffer range is used in the first 30% of the scene. Similarly, having too big of a difference between near and far clip planes can cause problems, you certainly shouldn't be setting your far clip to anything more than 10000.0f (And the lower the better).


My near is 0.1f and my far is 5000.0f, if i want to visualize a massive terrain, how would i do that with such a restriction This section of terrain goes out of view with the 5000.0f and it seems very small too me.

Quote:Original post by Gage64Sorry if this is a stupid question, but are you using the depth buffer? I ask because from the title of your post one might think you are sorting the geometry yourself (if you are - why?).


I am not sorting the geometry myself i am using the depth buffer, it just seemed to look like a sorting problem, hence the title.

Is there a state i can set in the effect file to use the depth buffer? im currently setting it using SetRenderState

Edit: I dont want to fisualize anything

[Edited by - LordFallout on January 14, 2008 9:03:44 AM]
The 5000.0f far plane isn't a problem, what matters is the ratio of far / near. The easiest way for you to solve it is to increase the near plane - you want it as far forward as possible without it causing obvious clipping problems from your gameplay camera positions. Changing your near plane to 1.0 for example would give you 10 times better z-buffer precision, and you might be able to move it further than that without any obvious side effects.

A 24-bit Z-Buffer is also much much better than a 16-bit one. I'd recommend using D3DFMT_D24X8 (or D3DFMT_D24S8 if you want stencil) on any card that supports it.

Just in case, you should also make sure that both z-writes and tests are enabled, and that the comparison function is correct. If those are wrong the rendering will be incorrect whatever the precision of the z-buffer.
Just uploaded another picture trying to shed some more light on the problem,
Its a strange problem and looks a lot worse in this image, its hard too tell whats going on, like one of those images you have to stare at for 5 minutes too see something, if you look too long you can see it :)

Image Hosted by ImageShack.us
Out of curiosity, does it work ok if you set your near clip plane to 1.0f? And what bit depth is your depth buffer? A 24-bit depth buffer (Which is what you really should be using) shouldn't really have any major problems. You shouldn't need to make any Z-buffer related SetRenderState() calls if you're getting D3D to create the Z-buffer along with your swap chain (Using the AutoDepthStencilFormat member of the present params).

There are ways to render massive terrains, such as changing the clip volume mid-render, but I'm not sure of the specifics, perhaps someone else has more details.
i had the AutoDepthStencilFormat set to D3DFMT_D16 which i've since changed to D3DFMT_D24X8, with the near plane set to 1.0f i still get the visual artifacts, they dont get better either, perhaps the problem lies elsewhere. o.o I was pretty sure that was the problem however the terrain looks perfect from some angles then when you move to a different position the error reproduces itself, its the same visual problems everytime i load the app.
I fixed the problem, it was just a problem with the near far plane like you suggested, although i didnt notice the settings wherent setting properly, cheers for your help :) with 24 bit depth buffer could i increase the far plane beyond 10,000 without mad visual effects.

This topic is closed to new replies.

Advertisement