A ray tracer, from the film down
I. The goal
A ray tracer in PatLang and conformal geometric algebra, opened top down from a short film to the algebra of points, with a graphics-card renderer checked byte for byte against it.
I. The goal
The film's own checks are about frames: windows, plates and the timeline. The node also needs the whole picture branch and the whole scene branch, so it passes only when everything the film is made from passes too.
A surface normal, a reflection vector, a point light, a material, and the Phong model that combines them. Two places in this page are where geometric algebra replaces something the book has to patch: reflection, andโฆ
Mirrors and glass: the renderer starts spawning secondary rays, so color_at , shade_hit and two new colour functions recurse, with a depth limit to stop two facing mirrors bouncing forever. Both effects are geometryโฆ
Distance has been invisible so far: a sphere a hundred units away is as sharp and as bright as one at ten. Air is not clear. A ray that crosses it is dimmed and tinted, and the further it goes the more. This page givesโฆ
Two eyes a few centimetres apart see a scene from two viewpoints, and the brain turns the difference into depth. A pair of pictures, one for each eye, side by side, does the same for anyone who can look at them theโฆ
Until now a picture was rendered by many processes : the picture was cut into bands, one process per band, and each process built the whole scene for itself before it rendered a row. The model is not changed byโฆ
The Dalek took about 90 minutes a picture on 20 processes, and this pages before it were already slow enough to wait for. This page is about the renderer, not new features, and it has one rule: no picture may change.โฆ
Until now a scene has been a PatLang program: calls to sphere() , set_transform , mat_mul , with_material_deep , a page of them. This page gives scenes and models their own small language, in a text file, with theโฆ
A tree is a rule used on itself: a branch is a limb, and at the tip of the limb are smaller branches; at the last of them are leaves. The scene language of A language for scenes and models can say that, becauseโฆ
A bird is a better test of the scene language than a tree, because nobody mistakes a bad one for a good one. This page builds a robin with the tools of Surfaces of any function and A language for scenes and models andโฆ
Union, intersection and difference of solids. A CSG shape holds two operands, each of which may be a primitive, a group or another CSG shape, so trees of any size can be built from binary operations.
Rays, spheres, intersection records, the hit rule, and the first picture that comes from casting rays. In the conformal algebra a sphere is a vector, and "a point lies on a sphere" is a single inner product. The book'sโฆ
The axis-aligned cube from โ1 to 1 on every axis, with two jobs: intersect a ray with it, and find its normal. In the conformal algebra both are statements about plane vectors, and the cube is six of them.
The last primitive, and the one that lets a ray tracer draw anything a modelling program can export: a triangle given by its three corners, a reader for Wavefront OBJ files, and smooth triangles that carry a normal atโฆ
A group is a shape with no surface of its own: it is the shapes it holds, carried by one transformation. Nest groups and a transformation placed on the outermost one moves the whole tree. This page also asks forโฆ
The book's last chapter lists directions to take a ray tracer next (area lights, spotlights, focal blur, motion blur, anti-aliasing, texture maps, normal perturbation) and leaves them open. Here the next step is a newโฆ
The torus and other polynomial surfaces solved f(x, y, z) = 0 for a polynomial f : along a ray it becomes a polynomial in t , and its roots can be bracketed exactly. A function with a sin , a sqrt , an abs or aโฆ
A pattern is a rule that turns a point into a colour: stripes, a gradient, rings and checkers. The pattern has its own transformation, applied after the object's, so a pattern follows its object and can also be scaledโฆ
The patterns of Patterns colour a point from its three coordinates: stripes by x , rings by x and z , checkers by all three. A picture needs something else. A globe wears a flat map, and the map has to know which pointโฆ
A texture map changes the colour of a surface. A bump changes how the surface faces the light: shading depends on the normal, so a picture that tilts the normal makes a smooth sphere look dimpled or a flat wall lookโฆ
The torus and other polynomial surfaces made a surface from a polynomial, but the polynomial had to be built by calls: tm_pow , tm_sub , tm_scale , a page of them for the heart. This page reads it the way it is writtenโฆ
The book represents points and vectors as 4-tuples (x, y, z, w) with w = 1 for points and w = 0 for vectors. Here a tuple is a multivector of the conformal geometric algebra Cl(4,1) , and the book's operations fall outโฆ
The book builds 4ร4 matrices, multiplication, transposition and inversion by cofactor expansion. The interface stays the book's: a matrix is a list of rows and M[r][c] reads an element. What changes is where theโฆ
Colours, a canvas, and a way to look at the result. The book writes plain-text PPM; this project also writes PNG , so images open anywhere without a converter.