Basic data types
Alright, the first push to the github repo is complete. Starting out small with just the basic data types that will be at the core of everything, and some tolerance equality operators for comparisons.
The constructor functions point()
and vector()
use the neat trick of tagging with .w = 1.0
for Points and .w = 0.0
for Vectors.
typealias Point = simd_double4
typealias Vector = simd_double4
struct Ray { let origin: Point; let direction: Vector }
let r = Ray(origin: point(0,0,0), direction: vector(1,1,1))
r.direction ==~ vector(sqrt(1/3)) // rays have normalized direction
On a side note, I’m trying out the pomodoro technique to manage my ability to focus for this project; working in sets of 25 minutes, and taking 5 minute breaks. Maybe I should rephrase the Devember contract as I will work for two pomodoros per day, instead of one hour. Plus one pomodoro for the devlog.
Next related
Intersecting spheres
The first piece of actual ray tracing: calculating the intersection between a ray and a sphere. To find the intersections, we need to solve the quadratic equation of the sphere being equal to the linear equation of the ray. The interpretation of imaginary roots is that the ray does not intersect the sphere.
Previous related
Devember again
This one snuck up on me faster than anticipated, but here we go.
Light and Magic
Made some refinements to lighting. Originially there was only a point light without distance falloff, which is not an accurate light model in any case. The light inside the room lights the entire world, all the way to the horizon.
Cache is King
Cut teapot rendering time in half with some clever caching.