How to keep a gameObject from rendering

I am building a game that uses an orbital camera around a planet. Im just wondering what the best way is to skip rendering of gameObjects that are on the other, non-visible side on the planet. The planet and all other objects are instantiated at runtime also.

This is for mobile platforms so saving drawcalls and lowering the poly count is the main goal here.

You can do a poor man’s occlusion culling test by casting rays from the camera position to each of the object positions. If the ray intersects the planet then the object is occluded by the planet.

However there are edge cases where this breaks - the object’s center may be occluded by the planet but part of the object may still be visible. You would still want to render the object in this case, but our current test would cull it.

You can handle this in a probably-good-enough way to by casting multiple rays for each object. If all of the rays collide with the planet then the object is occluded, otherwise at least part of the object is visible.

You can use the object/collider bounds to determine where to cast the rays.

Occlusion culling is a pretty big topic and there are probably much better and/or more accurate ways of doing this, but this should be a simple way to get you started.

The exact notion here is “OcclusionCulling”.

The cameras in Unity do it by default. In the Camera component, the “Occlusion Culling” check box is checked.

alt text

See the doc for more information about Occlusion Culling :