Raytracing for CSGs

For the final project in the Ray Tracing class, I implemented Constructive Solid Geometry (CSG) and wrote a report detailing the implementation. The 3D framework was created from scratch throughout the Ray Tracing course using C++ and GLFW. All computation were don CPU side.

Small introduction

Constructive Solid Geometry (CSG) is a technique in computer graphics used to build complex shapes by combining simple geometric primitives using Boolean operations like union, intersection, and difference. In this project, I implemented CSG using ray casting, a method of tracing rays from the viewer’s perspective into a scene to determine visible surfaces. The implementation builds upon a basic ray tracer, enabling it to handle hierarchical CSG trees and perform efficient set operations between intersected shapes.

Steps followed

1. Modified intersection tests to retrieve entry and exit points (spans) for primitives.
2. Implemented a parser to build CSG trees, where internal nodes represent Boolean operations and leaves represent geometric primitives.
3. Designed span-combination logic based on Boolean rules for union, intersection, and difference.

4. Ensured correct handling of normals by adjusting direction based on the ray.
5. Associated materials with intersection points for accurate shading.
6. Rendered various CSG combinations to validate correctness and performance.

Conclusion

This project successfully integrated Constructive Solid Geometry into a ray casting system, enabling the rendering of complex composite objects from basic primitives. The implementation effectively handled recursive CSG trees, Boolean operations on spans, and the proper management of normals and materials. The result is a rendering engine can render detailed and mathematically defined solid shapes.