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.
- 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 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 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.
- 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/your_username/VoxelEngine.git](https://github.com/your_username/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/VoxelEngine