Hi all,
I’m working on a small voxel engine. To check if performance is correct, I currently render a scene somewhat similar to Minecraft. My problem is, I think my framerate is lower than what it should be, when compared with what the game achieve on the same computer.
My scene is divided into 16 * 16 chunks, and each chunk contains 16 * 128 * 16 voxels. AFAIK this is the same setup than Minecraft.
I also use the same technique: I construct a mesh for each chunk, discarding all the quads that are between adjacent non-empty cubes. There is no occlusion culling, nor frustum culling (those are planned, but first I want to get the base of the engine right).
I use one VAO and two VBOs for each chunk; one contains 4 vertices per quad (12 floats), the other contains 4 (identical) one-byte color index. The actual color is fetched in the fragment shader from a 1D texture.
There is only one big index buffer, used for all VBOs.
All of these buffers are constructed only once.
Here’s my render code:
glUseProgram(program);
for(int i = 0; i < world_width; ++i){
for(int j = 0; j < world_depth; ++j){
mat4 mvp = chunks[i][j]->get_model_matrix() * view_projection_matrix;
glUniformMatrix4fv(uniform_mvp_matrix, 1, GL_FALSE, mvp.c_ptr());
glBindVertexArray(chunks[i][j]->vertex_array);
glDrawElements(GL_TRIANGLES, chunks[i][j]->nb_quads * 6, GL_UNSIGNED_INT, 0);
}
}
As for the content of the scene, it’s generated from a simple Perlin noise, so that a large proportion of cubes are adjacent. The size of the scene take into account the fact that I don’t have frustum culling (in Minecraft on “far” setting there is 33*33 chunks around the player).
I made a short video to give you a better idea of what I’m rendering:
[http://youtu.be/jij3T3rIoDg](http://youtu.be/jij3T3rIoDg)
The framerate is barely 40 fps (on a radeon 4850), where as in Minecraft I get at least 60 fps (with occlusion culling deactivated), often more. Also, I think the scenes in the game are more complex (i.e. smaller homogeneous zones). I’ve seen other videos of similar coding attempts, with much better framerate.
So I think there’s a problem with my implementation, but I have a hard time figuring what. It’s not the shaders, since they are very basic (no lighting), and changing them to even more basic don’t improve anything.
Any idea on how I could find out the cause of the low framerate?