A 3D Voxel Engine built from scratch in modern C++ and OpenGL. This project serves as an architectural playground to transition from traditional CPU-bound simulations to a fully GPU-Driven rendering pipeline based on AZDO (Approaching Zero Driver Overhead) principles.
The primary goal is to handle massive amounts of volumetric data efficiently by combining memory data locality, persistent CPU multithreading, and state-of-the-art graphics API rendering techniques.
While inspired by classic voxel aesthetics (Minecraft), this project serves as a foundational base for low-level graphics programming. It was built from scratch in modern C++ to bypass high-level abstractions, focusing entirely on direct memory management, multithreading, and modern GPU pipelines.
- Language: C++23
- Graphics API: OpenGL 4.6 (Core Profile)
- Libraries: GLFW (Window & Input), GLAD (Extension Loader), Dear ImGui (UI & Profiling).
- Fully GPU-Driven Pipeline (AZDO): Evolved the rendering architecture from traditional
glDrawArraysand CPU-bottlenecked Instanced Rendering to a modern Multi-Draw Indirect (MDI) approach. The entire visible world is dispatched to the GPU in a single draw call (glMultiDrawArraysIndirect), completely eliminating the CPU-to-driver bottleneck. - Shader Storage Buffer Objects (SSBOs): Leveraged massive VRAM buffers (SSBOs) to store global vertex data, colors, and per-chunk world positions. Utilizing
gl_DrawIDand Programmable Vertex Pulling natively in GLSL 4.60, the GPU autonomously fetches the data it needs without CPU intervention. - Custom VRAM Pool Allocator: Implemented a fixed-slot memory allocator to manage the Mega-Buffers dynamically. This allows asynchronous chunk meshes of varying sizes to be uploaded and freed from VRAM instantly, preventing memory fragmentation without the overhead of a complex dynamic
malloc. - Asynchronous Procedural Generation: A custom Persistent Thread Pool offloads terrain generation (Perlin Noise) and mesh building from the main thread, ensuring zero stuttering during continuous chunk loading.
- Hidden Face Culling & Meshing: The meshing algorithm was rewritten from naive block instancing to local-space face meshing. It only generates geometry for voxel faces exposed to air, drastically reducing the vertex count sent to the VRAM.
- Data-Oriented Chunks: Volumetric data is packed into 1D flat arrays (e.g., 32x32x32 blocks) maximizing CPU cache locality and improving traversal speeds during the meshing phase.
- Phase 1: Foundation - 3D Context, Shaders, and rendering the first Cube.
- Phase 2: Space & Vision - Fly-Camera implementation, MVP Matrices, and Depth Buffering.
- Phase 3: Data Structure - Designing the 32x32x32 Chunk class and Naive Meshing.
- Phase 4: Multithreading - Integrating the Persistent Thread Pool for procedural terrain generation.
- Phase 5: Geometry Optimization - Implementing Hidden Face Culling to reduce vertex payload.
- Phase 6: GPU-Driven Architecture - Transitioning to Multi-Draw Indirect Rendering, Programmable Vertex Pulling, and SSBOs.
Phase 1: Initial core rendering pipeline and basic voxel placement.
- Phase 7: Normal Mapping & Lighting - Compute vertex normals and implement Lambertian diffuse shading.
- Phase 8: Ambient Occlusion - Procedural SSAO-like shading based on voxel density.
- Phase 9: Shadow Mapping - Implementation of depth-map buffers for directional light shadows.
- Phase 10: Cascaded Shadow Maps - Optimizing shadow resolution for infinite terrain distances.
Phase 2: Day/Night cycle, with cascaded shadowmaps.
- Phase 11: Raycast Interaction - Voxel selection and block destruction mechanics.
- Phase 12: Emissive Logic - Dynamic light sources (voxels that act as lamps/torches).
- Phase 13: GPU Particles - Offload voxel debris/explosion physics to a dedicated Compute Buffer.
- Phase 14: Post-Processing - Implementation of Bloom (for the emissive blocks) and Tonemapping.
Phase 3: Terrain generation and LOD transitions.
- Phase 15: Screen Space Reflections (SSR) - 2D raymarching across the Depth Buffer to compute real-time reflections for water and wet surfaces.
- Phase 16: Atmospheric Sky & Clouds - Procedural sky rendering and volumetric clouds using 3D Noise and Signed Distance Fields (SDFs).
- Phase 17: Volumetric Lighting (God Rays) - Raymarching through the Cascaded Shadow Maps to simulate physical light scattering and crepuscular rays.
- Phase 18: Atmospheric Depth Fog - Implementation of a screen-space exponential fog relying on the depth buffer to seamlessly mas
- Phase 19: Level of Detail (LOD) & Massive Scale - Implementing distance-based procedural chunk simplification during the meshing stage.
- Phase 20: Voxel Global Illumination (VXGI) - The final frontier. Simulating real-time indirect light bouncing using 3D Textures and spatial mipmapping.
Phase 4: VXGI - voxel cone tracing
- CMake (3.15 or higher)
- A C++23 compatible compiler (GCC, Clang, or MSVC)
- Git (for fetching dependencies like GLFW and Dear ImGui)
- Clone the repository:
git clone [https://github.com/agusdropout/VoxelEngine.git](https://github.com/agusdropout/VoxelEngine.git) cd VoxelEngine
Generate the build files and compile:
mkdir build
cd build
cmake ..
cmake --build . --config Release# From the build folder, go back to the root directory
cd ..
# Run the executable (Windows)
.\build\Debug\VoxelEngine.exe
# Note: Path may vary slightly depending on your compiler (e.g., .\build\VoxelEngine.exe)
# Run the executable (Linux/macOS)
./build/VoxelEngineThe architectural development of this graphics engine is founded upon the following academic research and industry educational resources:
- A Fast Voxel Traversal Algorithm for Ray Tracing (John Amanatides & Andrew Woo, 1987) - Essential algorithm implemented for ray intersection in spatial grids, enabling high-precision selection physics (raycasting). Read Research
- Interactive Indirect Illumination Using Voxel Cone Tracing (Cyril Crassin et al., NVIDIA, 2011) - Technical paper establishing the fundamental mathematical basis for real-time global illumination simulation (VXGI) and volumetric ambient occlusion on the GPU. Read Research
- LearnOpenGL (Joey de Vries) - Comprehensive pedagogical resource for mastering the modern OpenGL pipeline, including texturing techniques, cascaded shadow maps, and post-processing. Visit Portal
- Approaching Zero Driver Overhead (AZDO) (Cass Everitt et al., GDC 2014) - Architectural presentation driving renderer optimization through the intensive use of Multi-Draw Indirect and Shader Storage Buffer Objects (SSBOs).
- Open Source Ecosystem - The interactive simulation relies on established open-source tools, including GLFW (window context), GLAD (hardware extension loading), GLM (graphics mathematics), and Dear ImGui (real-time profiling interface).