0
\$\begingroup\$

I make a voxel engine on LWJGL 3 (OpenGL binding for JVM). I store all object data in world class. World is subdivided into 32*32*32 chunks. Chunks use octree storage. The main part of all my rendering is cubes that share one mesh but have different transformation matrices and some other data. To render those i use one VAO per chunk, it contains only one cube mesh instance and has all cubes data (like transformations) stored in its VBOs. I construct each chunk VAO once and render it fully in one call - glDrawElementsInstanced. If i need to change some cube data in a chunk, i will reconstuct VAO from ground up or change individual buffer data. That should be pretty efficient, right ?

But I need some other stuff to be rendered, like complex mesh objects or effects or some debug stuff.

How should I render those objects ? Should I create a VAO for each mesh and then perform instanced rendering for each object with the same mesh ? Or should I batch all objects with their meshes into one VAO for each chunk and render it fully ?

I was trying to create a VAO recently, that contained one instance of each mesh and all object data. But i could not render it correctly. Because each time I needed to somehow switch object data VBO while rendering an instanced mesh. It didn't work.

Code for the last VAO: http://pastebin.com/WanNsR5L

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I don't think you should be instancing individual blocks. That's a lot of data you have to send back and forth to the GPU... it just isn't feasible, especially for a voxel engine.

I would construct a mesh from the chunk data and place it into a VBO. Every time there is a chunk update, discard the mesh and create a new one in it's place.

I feel that the "greedy meshing" algorithm is pretty easy to implement and its pretty fast, although it isn't always the most optimal. You can find more information on it here, and also more information on how to modify it to perform better: http://0fps.net/2012/06/30/meshing-in-a-minecraft-game/

Not only does meshing increase performance time, but it opens up a path to modularity. You can add different algorithms like dual contouring, marching cubes, etc, seamlessly without affecting any other code.

\$\endgroup\$
2
  • \$\begingroup\$ ok, I tried to make it work with the "stupid" way for 16k cubes, but the contruction of a VAO takes A LOT OF TIME, like a few minutes. pastebin.com/0xQJ9gDY \$\endgroup\$
    – Russoul
    Jul 12, 2015 at 15:56
  • \$\begingroup\$ Try running the algorithm on blocks that are adjacent to air. \$\endgroup\$
    – Avilius
    Jul 12, 2015 at 16:01

You must log in to answer this question.

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