Loading...
Loading...
A voxel game engine built from scratch in C++20, inspired by Minecraft. The core architecture splits engine subsystems (graphics, rendering, scene, atmosphere, settings) from game logic, with a state machine driving the full lifecycle: title screen, settings, world loading, and gameplay. The world generates infinite terrain using 3D Perlin noise with smoothstep biome blending (Plains, Mountains), carves spaghetti cave networks with natural water flooding, distributes ores at depth-appropriate strata, and cuts rivers using cellular noise. Rendering runs a multi-pass OpenGL 4.6 pipeline: shadow map depth pass with texel-boundary stabilization, half-resolution SSAO with a 64-sample hemisphere kernel and box blur, the main forward-lit pass with per-vertex AO and biome tinting, transparent water, volumetric clouds (2D and 3D modes), and instanced weather particles. Chunk generation and meshing happen on a thread pool, with GPU uploads capped at 4 per frame on the main thread. Blocks and textures are data-driven via a JSON-backed registry.
The threading problem drove the biggest architectural decision: mesh generation is split so ChunkMeshBuilder does all geometry work (iterating 65k blocks, checking 6 faces each, computing per-vertex AO) on worker threads, then hands off the vertex data via std::move to a queue. The main thread picks up finished meshes in ProcessPendingMeshes, capped at 4 GPU uploads per frame to avoid stalls. The render pipeline runs passes in a fixed order — shadow depth, SSAO at half-res, sky (depth-write off), opaque geometry, block selection wireframe, transparent water, then weather particles — with each pass managing its own FBO, blend state, and cull-face toggling. Shadow stabilization snaps the orthographic projection to texel boundaries. The cave carver uses an ICaveCarver interface so the strategy is pluggable, and the current SpaghettiCaveCarver applies altitude-based fade-out with surface protection to avoid breaking terrain above.
The engine runs at 60+ FPS with a 20-chunk render distance, handling infinite terrain generation, caves, ores, and rivers without noticeable pop-in thanks to the rate-limited async pipeline. The multi-pass renderer produces pretty convincing lighting — shadow maps, SSAO, and per-vertex AO combine well, and the day/night cycle with 8 lunar phases and volumetric clouds adds a lot of atmosphere. The modular architecture kept things maintainable as the codebase grew to ~340k lines of C++ and ~25k lines of GLSL. The test suite runs automatically on every push via GitHub Actions, covering the non-GPU subsystems.