CSG (Constructive Solid Geometry)
Home -->
Programming Projects -->
Fractal Block Engine -->
Procedural World Generation -->
CSG (Constructive Solid Geometry)
The Idea
One exciting aspect of block games is their capacity
for CSG (Constructive Solid Geometry).
That is, we can take the union, intersection,
and differences of basic primitives.
Or, we can generate terrain using Perlin noise
but then carve out spheres all over the place.
The possibilities are almost endless.
Let's say we want to generate a world with many
spheres of blocks in it.
Let's say that each sphere of blocks has
radius 10 blocks.
Since a chunk is 16x16x16 blocks,
when generating a chunk,
we want to iterate over the 3x3x3 surrounding chunks
and for each chunk,
see if it contains the center of a sphere.
Then, once we have all the nearby sphere primitives,
we iterate over all 16x16x16 blocks in the chunk.
We set a block to be solid precisely when it is
close enough to one of the spheres.
Note that we can be clever and for each primitive P
in one of the surrounding 3x3x3 chunks,
determine if P intersects the chunk being generated.
If it does not intersect the chunk, we can ignore it.
How would we deal with spheres that have a radius of 20?
We could iterate over the surrounding 5x5x5 chunks.
However we think it is better to store these large radius 20
spheres in virtual chunks that are each 2x2x2 normal chunks.
Then we only have to iterate over the surrounding
3x3x3 virtual 2x2x2 chunks.
See here about virtual chunks.
Big Spheres
Here are spheres which are too large to fit
in individual chunks.
Level of Detail (LOD)
Here is an enormous sphere which is being
shown in two levels of detail.
See here
for another example how we can use
level of detail.
Adding and Subtracting
Here is the enormous sphere from before,
but now we are subtracting out smaller
spheres.