Voxelium
- 3 Devlogs
- 23 Total hours
a VERY optimized voxel engine that (HOPEFULLY) looks like minecraft w shaders and really high render distance (128 chunks maybe) that doesnt kaboom your pc
a VERY optimized voxel engine that (HOPEFULLY) looks like minecraft w shaders and really high render distance (128 chunks maybe) that doesnt kaboom your pc
voxel engine devlog #3
Shadows, post processing, save files, and actual trees. GPU arena overflow funny moments it was not pleasant to deal with + graphics overhaul (added water)
Forward HDR & Shadows: Built a full pipeline with 3 cascade shadow maps, half-res SSAO, and Jimenez bloom. Shadows were super vertex-bound at first (5.12ms), but tightening the cascade splits chopped that straight down to 3.5ms.
Saving to Disk (.vxr Region Files): Chunks now compress using varints (a cave chunk shrinks from 65 KB down to 5.7 KB). We now only save edited chunks as a diff against the noise seed while everything else regenerates on the fly. I tested it by blowing up a wall, flying a few thousand blocks away to evict it, flying back, and it reloaded intact from disk.
Trees without neighbor lookups: Solved tree canopy generation across chunk borders by making them deferred. Each chunk calculates what parts of nearby tree roots fall inside its bounding box, avoiding goofy crossthread neighbor lookups.
Water meshing: Added water as a second mesh layer. Opaque faces draw against air or water (so you see the seabed), while water faces only emit against air.
Performance upgrades: High render distances were causing massive frame stalls because the GPU arena buffer was running at 92% capacity and triggering full GPU resets. Bumped the arena from 8M to 16M quads (128 MB) and nuked a hidden O(N) chunk scan sooooo hopefully smooth sailing from now
.
What now?: Full pipeline runs at ~4.5ms (~0.9ms with shaders off). Up next: smoothing out face lighting with per-corner ambient occlusion (AO) baked into the greedy mesh and looking into SSR for water.
Threading turned into rendering turned into lighting turned into an actual world with caves in it, all in one sitting. This was NOT the plan but here we are lol.
Threading: got gen + meshing off the main thread onto a real worker pool. Workers are just pure functions, voxels in results out through queues, so the only actual cross-thread headache was stopping a chunk from getting unloaded while another job was still reading it (fixed with a refcount). World output came out byte-identical to before which is exactly what I wanted, just moved where the work happens not what it produces. Worst case frame during a full re-stream is under 1ms now.
One draw call: this was the fun one. Went from 349 draw calls (one per chunk, kind of wacko ngl) down to 1. GPU buffer stays persistently mapped, culling got moved into a compute shader, and the indirect draw pulls its own visible count straight off the GPU so it never even touches the CPU. Same exact pixels as before, just the CPU isn’t sitting there doing a bunch of pointless work anymore.
Cave culling: engine now figures out which chunks you could actually see air through and just doesn’t draw the rest. Above ground that’s about 40% fewer chunks. My sealed test room underground was cutting 98%+ but that number came back down once real caves existed instead of one clean sealed box, which makes sense since it’s following actual connectivity now instead of a best case demo.
Lighting: sky + block light through BFS, baked straight into the mesh so there’s no separate lighting pass at render time. Threw in a glow block to test with. Removing a light source zeroes it out exactly and adding it back restores it exactly, verified both instead of assuming it just works.
Terrain + you can hit stuff now: swapped the flat test world for actual noise based terrain, caves carved with 3D noise instead of flat tunnels. Added raycasting so you can break/place blocks. Player movement runs on a fixed timestep so framerate literally cannot change how fast you move.
Next up: lighting is flat per face right now, want that smoothed per corner eventually. also got one frame time spike during heavy cave streaming I need to go check out before it turns into an actual problem once flying through caves is a thing.
Deadahh just wanted to put everything from the last few days into one initial devlog so I don’t have to keep yap too much.
Started with basic OpenGL 4.6 and GLFW, instead of using string lookups for shaders which is clown behavior, everything uses explicit locations. I also set up a headless smoke test so the CI can render offscreen, check its own pixels, and pass without popping up a window and being too goofy.
For debugging, I threw in an ImGui menu to track frames, draw calls, and memory without making the heap allocator crash out. Steady-state heap allocations are at zero right now + also flipped the depth buffer to reversed-D because standard depth buffers kaboom at long distances and make the textures Z-fight.
The first mesher I built was literally just a mesher. A regular mesher. There was nothing special about it. It just emitted 6 expanded vertices per face which took up way too much space (615 KB a chunk) and was slow.
I improved it and made a binary greedy mesher that packs an entire quad into a single 64-bit integer. It uses 64-bit bitwise column ops to merge faces instantly. 2.7x fewer triangles and 33x less memory. It’s so fast it takes like 0.05ms and I also ripped out VBOs completely for SSBO vertex pulling, meaning the GPU just reconstructs the geometry on the fly.
There was one issue where the greedy mesher left microscopic sub-pixel holes everywhere so I kept seeing pinhole cracks, so I just bloated every quad by 0.001 so they overlap and cover it up (surely this works well enough).
Having raw voxel arrays was eating my RAM alive, so I used palette compression. If a chunk is entirely air or entirely stone, it just stores one ID now. If it’s mixed, it bit-packs the indices, this dropped voxel memory by 20x. We’re streaming a 21x21x4 chunk radius (like 2,100 chunks) and it only takes 6.6 MB.
Added a chunk streaming manager so it loads in a ring around you. I had to put strict budgets on generation and meshing per frame, otherwise the game just freezes when you move too fast + CPU frustum culling means we only actually draw the chunks you’re looking at.
Right now the engine is in the state of being too good and being too bad at the same time. It’s doing like 349 individual draw calls per frame (one for every visible chunk). It works, but it’s got some quirks that I need to kaboom first.
Next up is building a persistent arena buffer and GPU-driven culling so we can collapse the entire world into ONE single draw call using indirect drawing.