PDA

View Full Version : Voxel engine optimalisation

Basaaa
11-14-2012, 12:02 PM
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!

Kopelrativ
11-14-2012, 12:28 PM
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.

Basaaa
11-14-2012, 01:01 PM
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?

Kopelrativ
11-14-2012, 01:20 PM
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.

Basaaa
11-14-2012, 11:44 PM
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?

uwi2k2
11-15-2012, 01:18 AM
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

Basaaa
11-15-2012, 02:48 AM