Signed Distance Fields

To implement SDFs we followed this tutorial by Jamie Wong. We implemented Signed Distance Functions for Spheres, Toruses and Mandelbulbs. To get the normals of these shapes we approximate the gradient of our sdf at the intersection point. For uv-coordinates we map them as if our shape was a sphere. Below you can see a render using our Mandelbulb of 9th power and our Torus.

Code:

  • src/shapes/sdf.cpp
  • src/shapes/sdf_sphere.cpp
  • src/shapes/sdf_torus.cpp
  • src/shapes/sdf_mandelbulb.cpp(code originally from Inigo Quilez)
Spoiler: Implementation of this feature in our final render
    Mandelbulb :)