hn.today

Software occlusion culling in Block Game

enikofox.com52 points4 comments
Screenshot of Software occlusion culling in Block Game

Eniko Fox implemented a CPU-based occlusion culling system for a voxel block game to help weak integrated GPUs run much faster. The system renders cube occluders into a low-resolution (256x128) depth buffer on a background thread, culling whole 16x16x16 chunks when their projected bounds are fully occluded. Chunks are preprocessed into a five-level mipmap of occluding subchunks (8x8x8 down to single blocks); opaque subchunks with visible faces become occluders gathered by distance rules and frustum checks. The pipeline is thread-safe by copying chunk positions and indices before the background pass, and conservative measures - shrinking occluders by one pixel and treating chunks with near-plane corners as visible - prevent false positives at low resolution.

Key implementation details drove the performance: occluders are rasterized by computing per-row min/max x extents from transformed cube corners and filling depth using the furthest corner depth, while occlusion candidates check against the nearest depth per pixel. Transform work was reduced by using a 3x3 view rotation plus additive translation and linear view-space depth instead of full 4x4 projection and 1/w divides, cutting arithmetic significantly. The result typically halves CPU rendering cost after frustum culling, removes 50-60% of chunks in open scenes and up to 95% in caves, and yields large frame-rate gains on low-end hardware, with a few edge cases where the cheap assumptions break down.

Read on enikofox.com4 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.