models clipping through themselves in game

Hi everyone, I have a simple game which I am testing in which the character has a WoW style zoom. Each model in the game, including the level, are created by me in blender. close up, the models behave themselves;

5932-1.jpg

zooming out a bit, the models begin to clip, and by the time I’m zoomed out to the full amount, the models look like complete garbage.

5934-3.jpg

Is this a common problem? I’ve struggled to find a solution to the problem. is it a problem with blender? the models look perfectly fine in the unity editor

This looks like a problem with the depth buffer (sometimes called the z-buffer), which is used to allow close objects to obscure far ones. The depth buffer is usually set up in a logarithmic fashion so most of the depth buffer precision is close to the camera, leaving less precision available further away.

The distribution of depth buffer values is controlled by the camera’s near and far clipping planes. By default Unity has the near clipping plane set to 0.3, and the far plane set to 1000. Because of the logarithmic nature of how the depth buffer values are distributed, most of the precision is going to be spent closer to the camera.

As a result of this, objects far away have fewer differences in depth that can be used, so objects that are close together (your model and the floor) will experience “z-fighting”, where part of object A obscures object B in one frame, and is reversed in the next, making things look really ugly.

The simplest way to deal with this is to move the near clipping plane further out, and bring the far plane in. Try using 1 and 500. The disadvantage of moving the near plane further away is that you won’t be able to get as close to the objects before they get clipped away. But, you have to find a balance that works for your game.

If you need the near clipping plane to remain closer to the camera, then another option is to use fog to hide objects that are further away so the depth fighting isn’t visible.

There are some other techniques, but they’re very complex and involve rendering with multiple cameras and manually depth sorting your objects, which can get very difficult or impossible in certain situations. Or you can rewrite all of the shaders to manually calculate what goes into the depth buffer to move the precision where you need it most.

It seems to me that the issue come from clipping between the robot and the ground, not only the robot.