This series of posts is targeted to all of you aspiring voxel engine creators, as I will be explaining how my voxel engine (and countless others) work!
For this post, I’ll be talking about rendering a high load of cubes/blocks without all the processing power.
The most obvious method is just to store the cubes and then render each, but this wastes a lot of vertices, what if you can’t see a face of a block?
For example, a engine which does not use this this technology, known as face occlusion culling, might render five blocks in a row as the following:
See all the wasted faces/vertices?
This engine would run for a low amount of cubes, but once you start creating worlds composed of these cubes, the engine will come to a grinding halt.
Now, let’s say you cull occluding faces.
Now, you’ll get something like
We just saved 8 faces, and 32 (8×4) vertices! That might not seem like a lot, but once you’re creating vivid and enormous landscapes, this really helps.
So, how do we implement this technique?
It’s really quite simple.
Before you process, draw, or create the vertices of a block, you want to make sure that the face that you’re creating vertices for isn’t occluding with another block.
This means that you should check for a neighboring block, and if there is one, not draw the face.
if ( westBlock doesn’t exist ) createface(west);
if ( eastBlock doesn’t exist ) createface(east);
if ( northBlock doesn’t exist ) createface(north);
if ( southBlock doesn’t exist ) createface(south);
if ( topBlock doesn’t exist ) createface(top);
if ( bottomBlock doesn’t exist ) createface(bottom);
See how easy it is?