- Home /
How can I stop the drawcall of an object if it is not in view of the camera, without using occlusion culling?
I am generating a cubic voxel world, and am using prefabs for the blocks. Each prefab has six planes with its own material. Because they are instantiated in runtime I cannot (to my knowledge) use occlusion culling on them. I originally tried turning off the renderer if it was not visible, however this failed because I could not detect if it was visible with the renderer turned off, and therefor could not turn the renderer back on.
Is there a way for me to stop the drawcalls on these planes without using the renderer class, or at least a better way? Thank you!
Answer by Bunny83 · Jul 12, 2017 at 11:35 PM
Any objects which are not "in-view" of the camera aren't rendered at all by Unity. However "in-view" doesn't necessarily mean that an object can be seen. Everything in front of the camera is in view.
If you have performance problems that can't be solved with any sort of occlusion culling.
Voxel worlds have to be created in chunks. In each chunk you will only create those faces which are adjacent to a transparent / air block. Any face that is adjacent to a solid block can't be seen.
Minecraft uses chunks that have a size of 16 x 16 x h blocks. Each chunk is further splitted into regions of 16 x 16 x 16 blocks. However the worst case (all blocks are transparent blocks and thus visible) would exceed the possible vertex limit in Unity. That means you would need to use smaller chunk regions.
A usual minecraft world (with a visible chunk radius of 8 in each direction) has about 4 million blocks. However only those adjacent to a transparent block are actually created. So much less triangles are created.
There are endless examples how to write a minecraft like voxel engine in Unity. While the overall concept is rather simple, implementing such an engine from scratch is quite a task.
I already knew most of this, but none the less, thank you. +1
Your answer
Follow this Question
Related Questions
Renderer on object disabled after level reload 1 Answer
Why isnt renderer.isVisible not working? 1 Answer
Multiple Cars not working 1 Answer
Checking if GameObject is rendered by specific camera 1 Answer
Distribute terrain in zones 3 Answers