Surface normals
Today brings normal vectors into the mix, a critical component for shading computations; the normal vector of a surface at the point where it was hit by a ray, to be precise. Because the normal depends on the hit position on the surface, and we’ll need that too, we keep that around as well.
struct Hit { let surface: Surface; let position: Point; let normal: Vector }
extension Ray { func hit(Surface) -> Hit? }
For the (2-dimensional) unit sphere, our only surface so far, the normal at a point on its surface can be calculated as the vector from origin: \(\overrightarrow{N}_{hit} = \dot{P}_{hit} - \dot{0}\)
Next related
Pixels on a canvas
Pretty much the whole point of a ray tracer such as this one is to render pretty pictures, and for that we’re going to need a canvas to render onto.
Previous 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.
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.
Devember again
This one snuck up on me faster than anticipated, but here we go.