Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Occluding Automatically?

Discussion in 'General Graphics' started by Littlenorwegian, Feb 18, 2017.

  1. Littlenorwegian

    Littlenorwegian

    Joined:
    Oct 19, 2012
    Posts:
    143
    Hello!

    I'm having a weird issue.
    https://dl.dropboxusercontent.com/u/11238180/CombustionVids/Occluding.mp4
    As you can see the goggles and ears of this mouse character disappears at the edge of the screen.

    Occlusion has been disabled on the camera. And I've even cleared the occlusion bake.

    I'm just curious what can be causing this sort of pop-in. And how I fix so it doesn't happen.
    Any ideas?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,217
    What are the eyes / ears? Are they a secondary skinned mesh component & asset? I'm also guessing that component has "Update When Offscreen" disabled, and the bond pose is the character standing upright.

    All of these together are causing the issue you're seeing, which is frustum culling, not occlusion. Unity generates an axis aligned bounding box (AABB) for each mesh on import, that is a box aligned to the mesh's local orientation that fully encapsulates all of the vertices of the mesh, and it's this box that's used to determine if something is on screen or not to be rendered even before occlusion. For skinned meshes this can end up working slightly differently since the mesh deforms and moves the basic AABB won't suffice.

    To deal with this they handle bounds in two different possible ways.

    One option is to change the bounds in real time to match the animation, but that means it needs to always update the animation as something which isn't in view may become in view via animation. This is what the Update Off Screen option is for.
    As a side note, I don't know how this is accomplished, especially when GPU skinning is used, but my best guess is it's actually giving each bone an approximate bounds and using the bounds of those bounds. It might also just not work when GPU skinning is enabled, I haven't tested...

    The other option, which I think is the default option, is the bounding box of a skinned mesh is expanded to include the extents of the animation as well, so if you have a character with animations that move them far off of their center, the bounds will include this! However this doesn't always work, like what you're seeing, and your "ears & goggles" mesh is keeping its initial unanimated bounds. Basically as far as Unity is concerned that mesh is off screen, so it stops trying to render it.

    The official documentation talks a bit about it here:
    https://docs.unity3d.com/Manual/class-SkinnedMeshRenderer.html

    The solution I would suggest is to expand the bounds via script. The simpliest method might be to expand the bounds of the ears mesh to include down as far as the feet are likely to be. You could be a little more accurate by getting the bounds of the "main" skinned mesh component and using the extents of both meshes' bounds as the new bounds. Or you could turn on Update Off Screen if you aren't worried about having several characters updating off screen. Or if they're not actually animated you could make them non-skinned mesh components and just attach them to the bone's gameobject.