Search code examples
opengllwjglvoxeloctreemultidimensional-array

Clarification about octrees and how they work in a Voxel world


I read about octrees and I didn't fully understand how they world work/be implemented in a voxel world where the octree's purpose is to lower the amount of voxels you would render by connecting repeating voxels to one big "voxel".

Here are the questions I want clarification about:

  • What type of data structure would you use? How could turn a 3-D array of voxels into and array that has different sized voxels that take multiple locations in the array?
  • What are the nodes and what are they used for?
  • Does the octree connect the voxels so there are ONLY square shapes or could it be a rectangle or a L shape or an entire Y column of voxels or what?
  • Do the octrees really improve performance of a voxel game? If so usually by how much?

Solution

  • Quick answers:

    • A tree:
      Each node has 8 children, top-back-left, top-back-right, etc. down to a certain level
      The code for this can get quite complex, especially if the voxels can change at runtime.
    • The type of voxel (colour, material, a list of items)
    • yep. Cubes only
      More specifically 1x1, 2x2, 4x4, 8x8 etc. It must be an entire node.
      If you really want to you could define some sort of patterns, but its no longer a octdtree.
    • yeah, but it depends on your data. Imagine describing 256 identical blocks individually, or describing it once (like air in Minecraft)

    I'd start with trying to understand quadtrees first. You can do that on paper, or make a test program with it. You'll answer these questions yourself if you experiment