Why are models showing through other models?

Hi

I’m getting an annoying effect when rendering models on the screen and don’t have a clue whats causing it. I have 7 models rendered with their X positions .12f apart and their Z positions +.03f apart. This gives the models a layered stack effect like a stack of cards in a persons hands. But when i move the camera around sometimes a model that’s suppose to be behind another model starts to show in front of the other model even though it’s Z position is set further away.

Anyone know what’s causing this?

Thanks!

It depends. You mention it happens when you move the camera around. Do the objects show through each other in a jagged, toothy pattern which flickers when you move the camera?

Like this?

If so, then it’s Z-fighting. It doesn’t have to do with perspective distortion, but is an effect that occurs when you have insufficient depth buffer resolution to correctly distinguish very close distances between the camera and the objects when the objects are in normalized clip space.

The effect is especially pronounced when you have a very long distance between your near plane and far plane, like 10000. You typically fix it by reducing the far plane distance, or by increasing the distance between the problematic objects. If none of these are an option to you, you can use a shader that renders each object with a specific depth bias, or “z offset”, see this page for syntax.

I think this can be fixed by changing the camera’s sort mode to Orthographic.