Clearing the Depth Buffer and Proto Chunks

Home --> Programming Projects --> Fractal Block Engine --> Rendering --> Coordinate Systems

To Clear the Depth Buffer or Not

In Fractal Block World there are several layers of detail which are visible. We render the coarsest level of detail, clear the depth buffer, render the next finest level of detail, clear the depth buffer again, etc.

For anyone making a similar engine, we recommend figuring out how to use a single depth buffer without clearing it in the middle of rendering.

Not clearing the depth buffer has advantages. For example, we could render front to back. Also, not clearing the depth buffer allows us to make many simplifications.

The point of this page is to describe some of the complications that arise when we clear the depth buffer mid render.

Rendering Protochunks

Suppose that we are NOT clearing the depth buffer mid render. Consider a block B2 which is rendered normally as part of a chunk C1. When the block B2 is subdivided into a chunk C2 and that chunk is populated, we remove that block B2 from being rendered in C1. For rendering purposes, C2 appears as an empty block when we render C1. However we also render C2 separately.

Now consider the situation where we ARE clearing the depth buffer mid render. Suppose we have a chunk C0 with two blocks B1 and B2, where B1 is blocking B2. That is, the player is looking at B2 but B1 is blocking it. We run into a problem when B2 is subdivided into a chunk C2 and populated before B1. In this situation, B1 is rendered first, the depth buffer is cleared, then C2 is rendered later but this will be on top of B1.

The solution we chose for this is to turn B1 and B2 into chunks C1 and C2 at the same time. A the instant they are turned into chunks they are still unpopulated. A chunk that is not populated (a protochunk) is rendered as a single block. However it is rendered along with all other chunks on that level. So now C1 and C2 are both protochunks and if C2 is populated first, then C2 will be rendered as a chunk and C1 will be rendered as a block. However the rendering of the chunk C2 and the block C1 will be done without clearing the depth buffer in between.