Voxel engine optimalisation

• 11-14-2012, 12:02 PM
Basaaa
Voxel engine optimalisation
Hi all,

For the last few days I have worked on my first OpenGL test project. It's a simple voxel engine in Java with the LWJGL library. I used chunks, just like Minecraft. Those chunks are 16*16*128. When I load the world, I loop over all the blocks in a chunk, creating a VBO with the coordinates, normal coordinates and texture coordinates of every single chunk. Now, when I render 1 chunk of 16*16*128, I get around 250 FPS (Yes, this renders actually all the cubes inside the chunk so 16*16*128 = 32768 quads). However, when I try to render 4 chunks, it already dropped to 40 FPS. What would be the best way to increase my FPS?

Thanks!
• 11-14-2012, 12:28 PM
Kopelrativ
Quote:

Originally Posted by Basaaa
Hi all,

For the last few days I have worked on my first OpenGL test project. It's a simple voxel engine in Java with the LWJGL library. I used chunks, just like Minecraft. Those chunks are 16*16*128. When I load the world, I loop over all the blocks in a chunk, creating a VBO with the coordinates, normal coordinates and texture coordinates of every single chunk. Now, when I render 1 chunk of 16*16*128, I get around 250 FPS (Yes, this renders actually all the cubes inside the chunk so 16*16*128 = 32768 quads). However, when I try to render 4 chunks, it already dropped to 40 FPS. What would be the best way to increase my FPS?

Thanks!

You should use a transformation phase. Transform from a chunk data into a list of visible surfaces. For example, it is no use to draw quads from cubes facing in a direction where there is another solid material.

Getting a good FPS from voxel based data is a challenge. You are going to need a lot of optimization and special hacks, depending on the number of chunks you want to show.
• 11-14-2012, 01:01 PM
Basaaa
Thank you for your answer. I'm gonna try to implement a few optimalisations.
Another quick question: can I remove faces in a VBO with glBufferSubData?
• 11-14-2012, 01:20 PM
Kopelrativ
Quote:

Originally Posted by Basaaa
Thank you for your answer. I'm gonna try to implement a few optimalisations.
Another quick question: can I remove faces in a VBO with glBufferSubData?

You can't remove data with glBufferSubData, you can only replace one set of data with another set.
• 11-14-2012, 11:44 PM
Basaaa
Hmm, I'm now switching the code from quads to triangles, but I simply can't get it to work.

Here is my vertex buffer:

Code :

```private float[] buffer_data { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f };```

And here I draw it:
Code :

```GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_id);   GL11.glVertexPointer(3, GL_FLOAT, 24, 0); GL11.glNormalPointer(GL_FLOAT, 24, 0); GL11.glTexCoordPointer(2, GL_FLOAT, 24, 0);   GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, tmp_buffer_array.length / 8);```

However, I get a triangle on the z axis (pointing towards me), and the texture coordinates aren't working. Anything wrong with the float array or drawing code? Quads work fine. What could be the problem here?
• 11-15-2012, 01:18 AM
uwi2k2
hi,

Code :

```GL11.glVertexPointer(3, GL_FLOAT, 24, 0); GL11.glNormalPointer(GL_FLOAT, 24, 0); GL11.glTexCoordPointer(2, GL_FLOAT, 24, 0);```

glNormalPointer(GL_FLOAT, 24, 0); << missing first parameter..
and - looks like you are missing the propper offset and stride for the glNormalPointer, glTexCoordPointer they are not starting with the 1 elementin your buffer data. so the last parameter needs to be 24, and 48 i would guss ..

cu
uwi
• 11-15-2012, 02:48 AM
Basaaa