Skip to content

pietraldo/raycasting_of_a_csg_tree

Repository files navigation

Raycasting of a CSG Tree

Introduction

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.

Screenshot


Content


How It Works

This project uses raycasting with CUDA.
Each pixel is represented as a thread in CUDA.

How a pixel’s color is calculated:

  1. Take a line from the camera position to the pixel.
  2. Intersect this line with every shape in the scene.
  3. Combine those intersections according to the structure of the CSG tree.

Build

To build the project:

git clone https://github.com/pietraldo/raycasting_of_a_csg_tree --recursive --shallow-submodules
cmake -S . -B ./build

Instructions

Moving in the Scene

  • W – move forward
  • S – move backward
  • Right mouse button – control camera orientation

You can also control lighting and camera with:

Controls


Input File

Example input files are in the example_models folder.

Objects

  • 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
    

Operations

You can combine shapes to build a CSG tree:

t1) s1 - c1
t2) s1 + w1
t3) t2 * t1

Examples

Example 1

Example 2

About

Raycasting of csg tree using cuda

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published