Day 36, Constructive Solid Geometry
The final pre-defined feature of the project is done, Constructive Solid Geometry, implementing the boolean set operations union
, intersection
, and difference
for solid geometries. This way we can use the basic geometric surface shapes to create more advanced shapes, without resorting to approximating by thousands of triangles.
The CSG union operation joins the surface of two shapes, such that the outer geometry is preserved, but the overlapping geometry on the inside is removed, constructing a new surface.
The CSG intersection operation does the opposite of the union, preserving only the overlapping geometry. That’s why the colors switch sides, because the remaining surface geometries belong to the opposite side spheres.
The last of the operations, CSG difference, removes the intersection from the left sphere, again leaving the surface of the right sphere exposed in the cut.
With some clever arrangement of CSG operations we can create some pretty complex geometry from just some cylinders and spheres.
Next related
Cache is King
Cut teapot rendering time in half with some clever caching.
Previous related
Day 33, Domain-Specific Language
Not a single feature improvement today, but instead a bit of quality of life improvements.