This diamond is light by multiple light sources. Each ray of light is absorbed, reflected, and refracted in varying proportions, and anti-aliasing ensures that edges are smooth.
This diamond is light by multiple light sources. Each ray of light is absorbed, reflected, and refracted in varying proportions, and anti-aliasing ensures that edges are smooth.

Enhancements#

This iteration of the 3D ray-tracing graphics engine (see previous) adds the following features:

  • Multiprocessing
    • Ray-tracing is inherently parallelisable: you have millions of rays that are all independent of one another. We achieve an “easy” 5-10x performance increase by using as many cpu cores as possible.
  • Anti-aliasing
    • I experimented with a few different algorithms, and found that multisample anti-aliasing worked very well. This involves firing multiple rays for each pixel and averaging out the result. I clawed back some performance by detecting when anti-aliasing was required (severe edges), and only subsampling for affected pixels.
  • Real-time rendering
    • I created a new window-mode so that the user can control the camera in real-time.
  • Compound shapes
    • I added some functions for building up complex shapes from primitives. Below you can see how I created a diamond from lots of triangles.
  • Split rays
    • Light doesn’t choose between absorption, reflection, and refraction. In reality it will do all three.
With anti-aliasing turned on, the edges of this diamond become buttery smooth.
This diamond is made from lots of triangles, and has an accurate refractive index. With anti-aliasing turned on, the edges of this diamond become buttery smooth.