A CSG (Constructive Solid Geometry) tree is, in simple terms, a way of adding, subtracting, and intersecting shapes.
This project implements it using multithreading and CUDA for faster simulations by leveraging GPU threads for calculations.
This project uses raycasting with CUDA.
Each pixel is represented as a thread in CUDA.
How a pixel’s color is calculated:
- Take a line from the camera position to the pixel.
- Intersect this line with every shape in the scene.
- Combine those intersections according to the structure of the CSG tree.
To build the project:
git clone https://github.com/pietraldo/raycasting_of_a_csg_tree --recursive --shallow-submodules
cmake -S . -B ./build- W – move forward
- S – move backward
- Right mouse button – control camera orientation
You can also control lighting and camera with:
Example input files are in the example_models folder.
-
Spheres:
(x, y, z, radius, r, g, b)
Example:s1) -6.8 1.12 -8 1 255 255 0 -
Cubes:
(x, y, z, a, b, h, r, g, b)
Example:c1) 0 1 -9.5 1 1 1 0 255 255 -
Cylinders:
(x, y, z, radius, height, axis, r, g, b)
Example:w1) -5 0 0 4 10 1 0 0 255 100 100
You can combine shapes to build a CSG tree:
t1) s1 - c1
t2) s1 + w1
t3) t2 * t1



