voxel engine devlog #2
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.