Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity Camera Clipping Issue

I'm having an issue with my camera, it is clipping one of my 3D models (cf images below).

enter image description here enter image description here

My camera Near Clipping Planes is already at its lowest value and all my shaders have an opaque rendering mode.

It only does that with the 3D models I generated with Fuse CC. The one I did with Blender don't clip! Any ideas? Thanks!

like image 475
drn Avatar asked May 01 '17 15:05

drn


2 Answers

The actual problem seems to be that your models' bounds are not correct. Frustrum culling allows your GPU to skip rendering models that are out of sight by testing their bounds against the camera frustrum. This is important if you want good rendering performance. So just disabling it is not the best idea, if it is only to work around a simple issue like incorrect bounds.

If you select your mesh renderer in the scene, you should see it surrounded by a wireframe cube. That cube visualizes your meshs bounds. You should see them fit quite well on your Blender models, and be way off on your Fuse CC models.

Once you've verified that your Fuse CC models' bounds are off, you can try and fix them manually or by changing the import settings.

Reasons why the bounds can be off:

  • You are importing the model without animations. If Unity does not know how the model will be animated, it will most likely set the bounds too tight
  • You are using Vertex shaders that distort the model in a way that makes it reach out of its bounds
  • You are programmatically moving bones around at runtime, either by IK, Ragdolls or similar

All of these can be fixed by adjusting the bounds on your mesh in the editor so that they leave enough room for your runtime animations/modifications.

The bounds are chosen well, when all of the following are true:

  • The mesh never reaches out of bounds (as visualized by the wireframe cube)
  • The bounds are as tight as possible without violating the first rule
like image 195
Thomas Hilbert Avatar answered Oct 03 '22 22:10

Thomas Hilbert


Thanks to Draco18s who led me to frustrum culling. I found this post that demonstrates how to deactivate frustrum culling on a particular gameobject and my issue is solved! The script is a little bit out of date so here is the updated version.

// Update is called once per frame
void Update () {
    // boundsTarget is the center of the camera's frustum, in world coordinates:
    Vector3 camPosition = Camera.main.transform.position;
    Vector3 normCamForward = Vector3.Normalize(Camera.main.transform.forward);
    float boundsDistance = (Camera.main.farClipPlane - Camera.main.nearClipPlane) / 2 + Camera.main.nearClipPlane;
    Vector3 boundsTarget = camPosition + (normCamForward * boundsDistance);

    // The game object's transform will be applied to the mesh's bounds for frustum culling checking.
    // We need to "undo" this transform by making the boundsTarget relative to the game object's transform:
    Vector3 realtiveBoundsTarget = this.transform.InverseTransformPoint(boundsTarget);

    // Set the bounds of the mesh to be a 1x1x1 cube (actually doesn't matter what the size is)
    SkinnedMeshRenderer mesh = this.GetComponent<SkinnedMeshRenderer>();
    mesh.localBounds = new Bounds(realtiveBoundsTarget, Vector3.one);
}

Place this script on the GameObject which is causing problem.

Note: Replace SkinnedMeshRenderer by the mesh renderer type your gameobject is having.

like image 39
drn Avatar answered Oct 03 '22 22:10

drn