Voxel Engine

Custom voxel rendering engine with optimized meshing and lighting

Unity C# HLSL
View on GitHub

Lighting Demo

About This Project

A cubic voxel research project built in Unity to explore Minecraft-style voxel engines, multithreading, and RGB lighting. Despite their visual simplicity, voxel engines cover many aspects of computer science such as memory optimization, CPU optimization, data structures, and efficient rendering techniques. While it started as an informal way to dig into the fundamentals, the project has since evolved into a good reference for those curious about voxel engines and how to approach them.

Full RGB Lighting

The lighting engine supports full RGB color with both emission and tinting. Light propagates through translucent materials and blends naturally, giving you colored shadows and atmospheric effects. Sunlight propagates downward from the sky while block lights spread in all directions with proper falloff. A LUT is used to correct the color gamut and inconsistencies from the underlying RGB565, 16-bit format.

While initially based on flood-fill lighting as seen in Minecraft, simply adding two additional channels and decrementing each one led to inaccurate color blending and attenuation. The solution was to move to the RGB565 format as it more efficiently utilized the 16 bits available for lighting data and optimizes for greater sensitivity to green in human vision. Multiplicative blending and attenuation did the rest with the final result looking quite good while remaining light on memory.

Multithreaded Chunk Pipeline

Chunks progress through a state machine (terrain generation, lighting, meshing) with all the heavy lifting done on background threads. A custom thread pool with async/await support was used to keep the main thread responsive while processing multiple chunks simultaneously.

Recent work has been done to convert the chunk pipeline to the Unity job system and leverage their Burst compiler for better performance. This new architecture has allowed me to both simplify the pipeline and fix a number of bugs from the old implementation.

Optimized Cubic Meshing

The mesher generates efficient geometry with per-side textures, block orientations, and smooth lighting with ambient occlusion. Vertex data is tightly packed and lighting is baked directly into the mesh for fast rendering. DDA-based voxel raycasting allows for accurate and low-latency block placement and breaking compared to raycasts against chunk meshes.

Screenshots