As many others I want to code a game with a voxel based terrain. The data is represented by voxels which are rendered using triangles. I head of two different approaches and want to combine them.

First, I could once divide the space in chunks of a fixed size like many games do. What I could do now is to generate a polygon shape for each chunk and store that in a vertex buffer object (vbo). Each time a voxel changes, the polygon and vbo of its chunk is recreated. Additionally it is easy to dynamically load and reload parts of the terrain.

Another approach would be to use octrees and divide the space in eight cubes which are divided again and again. So I could efficiently render the terrain because I don't have to go deeper in a solid cube and can draw that as a single one (with a repeated texture).

What I like to use for my game is an octree datastructure. But I can't imagine how to use vbos with that. How is that done, or is this impossible?


1 Answer 1


You might want to take a look at sparse voxel octrees and you should be able to find some implementations.

You want a dynamic VBO. Every frame, you work out which boxes in the octree you want to draw, calculate the position of the box's corners, add them to the dynamic vbo as vertices and create a supporting index buffer to detail which points join to which other points to make the triangles for the box.

You can add texture information to each box and create separate lists for each texture. You can also use one giant texture sheet and one giant VBO, it just means generating the texture coordinates for each vertex a bit differently.

You can also do some culling tricks here to avoid adding points and indices for parts you can't see (don't add polygons for visible boxes touching other visible, non-transparent boxes on all sides, don't add box faces which touch other visible boxes etc).

You can use a different octree for each chunk and you don't need to rebuild the vertex buffer if you didn't change the octree in the last frame, but if you are using heavy culling in the tree then you need to rebuild when the camera moves.

  • \$\begingroup\$ For which octree node should I create a vbo? There must be either a way to dynamically find the level where the vbo is created or a fixed depth. What would you suggest? \$\endgroup\$
    – danijar
    Dec 10, 2012 at 22:16
  • \$\begingroup\$ To start you want to just go down until you find a valid block, so that's essentially a fixed depth. But just stop if the current octree node is outside the view frustum. Later you can add the performance tweaks, like grouping blocks with the same texture together into a larger octree node for rendering. \$\endgroup\$ Dec 11, 2012 at 9:37
  • \$\begingroup\$ So your advise is to create vbos for single blocks? I though of calculating the polygon mesh of a chunk and store that in a vbo. But using an octree there is no fixed chunk. By the way, I don't go deeper if a node is filled to capacity of the same blocks. \$\endgroup\$
    – danijar
    Dec 11, 2012 at 10:04
  • \$\begingroup\$ As I stated in my answer you want to just use one dynamic vbo and fill it with information for each block in the octree you want to see. You could also have one vbo per texture or one per octree if your prefer. The only way to know which is best is to profile it. \$\endgroup\$ Dec 11, 2012 at 10:34
  • \$\begingroup\$ Thanks. Last question, can I just modify a dynamic vbo without uploading all vertices again? \$\endgroup\$
    – danijar
    Dec 11, 2012 at 11:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .