0

I managed to make myself a basic voxel engine that uses Perlin Noise to generate a array of models. Everything has gone well, but as soon as I turn the world size up to 200x200 blocks I get HUGE lag. I believe this is happening because I am rendering every block separately. How can I fix this? I have heard of using chunks but I cant really get my head around them. I will post code on request :D Any insights?

1 Answer 1

1

Rendering each voxel individually is obviously the cause of lag. To fix this you should render "chunks" of voxels at once rather than each voxel individually.

Chunks are small arrays of voxels. A mesh and a vertex buffer are usually generated to each chunks, so that you can render each chunk.

// Simple Chunk with the size 32x32x32 voxels.
struct Chunk {
    // Constants:
    static constexpr int c_dim = 32;

    // Voxel array:
    unsigned char voxels[c_dim*c_dim*c_dim];

    // Vertex buffer:
    GLuint vbo;
    GLuint drawCount;
};

The world is then made up of multiple chunks using map/unordered_map.

class World {
public:
    ...
private:
    // a string containing "x|y|z" is an easy way of expressing the key.
    std::map<std::string, Chunk*> m_chunks;
};

/r/VoxelGameDev/ has bunch of resources about developing voxel engines. Here is a list articles/resources: https://www.reddit.com/r/VoxelGameDev/wiki/index

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.