Hiding faces you can't see

Hey guys im trying to create a voxel procedural generator but i ran into a problem and that is that if i have too many cubes in my scene my game starts lagging and my fps drops down to 3fps so my question is is there any good way to only render the faces of the cube that the player can see? i heard that should help ALOT!! thx

Are you sure the lag is due to rendering, and not something else? You should be running the profiler to determine the specific cause of the slow down. For all you know, you have a script on every one of your cubes that's running an Update method every frame.

Also, you'll want to make sure you have batching set up properly. The materials should have instancing enabled.

Unity does not deal with a massive amount of gameobjects well.For me 120k empties will crash it same as 120k cubes .If the amount of cubes is the case you need to employ a system of only loading the visible cubes at any given time.I.

Are you sure the lag is due to rendering, and not something else? You should be running the profiler to determine the specific cause of the slow down. For all you know, you have a script on every one of your cubes that's running an Update method every frame.

Also, you'll want to make sure you have batching set up properly. The materials should have instancing enabled.

Click to expand...

Yes it is the rendering that makes me have 15 fps my question is tho how can i make the faces that the player can't see transparent i don't think occlusion culling is going to help

my question is tho how can i make the faces that the player can't see transparent i don't think occlusion culling is going to help

Click to expand...

Faces that are angled away from the camera will not be rendered. Occlusion Culling will, as stated by dgoyette exclude objects that are obscured by nearer objects. What are these other faces you have that need removing?

Just to mention, trying to create something like a Minecraft world by building cubes is not really going to scale well. Here is a video showing why.

Occlusion Culling is usually the most efficient for static objects. It does also support dynamic culling but this one does only make sense if a consistent (static) environment exists.

Additionally, occlusion culling does benefit alot from a level layouts that are designed to hide alot. A world and/or a camera perspective that allows to see most of the objects at any time does not help a lot.

I'm also not sure whether an efficient runtime solution does exist, so baking does only help when the world is known at build-time.

There are other techniques that enable you to gain massive improvements though. Using tree strucures (custom containers) for spatial subdivision in order to deal with a chunk of the environment that is currently of interest (based on player and/or camera position).
For smaller world, you could keep the world in memory, and only apply the information for the chunks of interest.
For bigger worlds, you can load/unload those information on demand from/to a persistent storage.

On the other hand, there is also GPU instancing, which allows to efficiently draw great amounts of objects that share the same mesh and the same material. This might help if you approach a world similar to minecraft.

You could also try do the heavy work on the GPU directly. The environment could be generated asynchronously and when calculations are done, you could update it on Unity's main thread.

There are a lot of possibilities, I'm not sure how well they would combine in a complex scenario (some are excluding others by the nature of their implementation).