Ray Tracing in a Weekend Part 4 - Adding a Sphere

Ray vs. Sphere Part 3 introduced a ray class. Now it’s time to let the ray hit the first object: a sphere. The equation of a sphere centered at the origin is [1] \[ x^2 + y^2 + z^2 = R^2 \] which is essentially derived from Pythagoras’ Theorem extended to three dimensions. [2] For any \( (x,y,z) \), if \( x^2 + y^2 + z^2 = R^2 \) then \( (x,y,z) \) is on the sphere, otherwise it’s not.
Read more...

Ray Tracing in a Weekend Part 3 - The Ray Class

The Ray Class In part 2 I added a vec3 class to help with 3-dimensional vector calculations. This chapter moves it one step further by introducing a new ray class. A ray can be thought of as a function \[ p(t) = A + t * B \] where p is a 3D position along a line, A is the ray origin, B is the ray direction, and t is the ray parameter which moves p(t) along the ray.
Read more...

Ray Tracing in a Weekend Part 2 - The vec3 class

The vec3 class In part 1 I made a simple image by assigning rgb values to individual variables in a loop across the x- and y-coordinates. This example produces the same image, but introduces the vec3 class used to perform calculations with 3-dimensional vectors and access them as x, y, z-coordinates or r, g, b-color values. The code below is complete, but feel free to download the complete repo from https://github.
Read more...

Ray Tracing in a Weekend Part 1 - Intro and First Simple Image

Introduction In the next few posts I’m going to document my journey through Peter Shirley’s book Ray Tracing in a Weekend and its two following volumes Ray Tracing - The Next Week and Ray Tracing - The Rest of Your Life (now available for free). I found the first book on Amazon Kindle quite a long time ago, but then I always had to put it on the backburner because I had to finish other courses first.
Read more...