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 1616128. 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 1616128, I get around 250 FPS (Yes, this renders actually all the cubes inside the chunk so 1616128 = 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!

[QUOTE=Basaaa;1244498]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 1616128. 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 1616128, I get around 250 FPS (Yes, this renders actually all the cubes inside the chunk so 1616128 = 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![/QUOTE]

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.

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?

[QUOTE=Basaaa;1244501]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?[/QUOTE]

You can’t remove data with glBufferSubData, you can only replace one set of data with another set.

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:


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:


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?

hi,

        
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

Thank you for your reply.

Is seems that I actually am not missing an argument in glNormalPointer, as this works fine with quads. Also, could you explain how the last parameter works? (pointer_buffer_offset). I still can’t get it to work properly.

Thanks!