Search code examples
voxelvoxels

How to render voxel in an efficient way


For now, I use a 3D array to represent my voxels in different chunks. I want to render voxels which can be visible by the player, but the way I do it is totally not efficient:

I iterate over the whole 10*10*10 chunk and check on every voxel if there is a neighbor equal to Air. Then I render separatly each faces which can be visible. So I mostly check every voxels 6 times. And I do this for all chunks.

Is there a better way to proceed or an algorithm to reduce iterating?

I basicly don't know if it is better to work with 3D Array or Octree...

Thank.


Solution

  • I've been thinking through this problem recently, and since nobody has answered you I thought I'd mention some of the ideas I've come across.

    Firstly, it's work noting that you only need to calculate which faces to render once, since that only changes if you remove or add a voxel, and then you only need to recalculate the voxels immediately around the place where you made the change. Just use a flag to mark for rendering and cache that until something changes. If you aren't already doing this, this will give you a big performance boost over calculating every frame.

    I also recommend looking into this extremely fast raycasting algorithm:

    https://github.com/HKUST-Aerial-Robotics/FIESTA/blob/master/src/raycast.cpp

    You can use it for fast collision testing, and also for cull-testing. You can cast at grid nodes to see if any part of a face is visible.