Posted on 25/02/2015

Finally implemented proper frustum culling into Terrablox. Now, it works perfectly as intended; it knows precisely whether a chunk is inside the camera projection and I even check against the maxHeight inside a chunk, so even if you're inside that chunk area, if you're looking away from it's actually visible areas if counts as outside the projection. It's pretty neat. But the way it checks for visibility atm is actually slowing it down more, it does the check for every chunk in existence, which in the below example is 1024, but even then 757 are visible and that's still a big number. Without culling this world runs at >400 FPS, with it runs at 80. Wut...

So, the processing to lower the drawing is costing A LOT more than the drawing ever did. I did have ideas for optimizing the culling; like only drawing from the current chunk and moving to it's neighbors, using culling to check if the loop should continue. And I think I can get it a little faster by pre-defining a lot of things that I input to the culling function that don't actually change, like chunk position. But even then, the difference between these numbers doesn't bode too well.

I think the usual way to solve this problem is with octrees. While I know how they work I've never had the opportunity to implement them in anything before. But basically the idea is to look at groups of chunks contained in bigger boxes, if the bigger box is totally in view then we know all contained chunks are visible and we don't need to check them individually. If a group box is only partially in view then we know some of the contained chunks may be visible and we check them. And we can have boxes inside boxes to make even broader checks. I don't think implementing this will take long, but I hope for a good result when it is!