Module 13 · From Scratch · Container Runtime · about 16 min to read
Continue where you left off ×
A ray tracer in an afternoon
Capstone Keypress to Pixel · Open board
The board that follows one key press until a pixel changes colour. A ray tracer is the same last step done on purpose: for every pixel on the screen, work out one colour, from numbers alone.
The idea in 30 seconds
A ray tracer sends one ray from the eye through each pixel and works out one colour per ray.
A ray touches a sphere where a small equation in t has an answer, and the smaller answer is the near side.
The normal is the direction a surface faces, and for a sphere it points from the centre to the hit point.
Diffuse light is the dot product of the normal and the direction to the lamp, floored at 0.
Specular light is the mirrored direction dotted with the direction to the eye, raised to a shininess.
A shadow is a second ray toward the lamp, and anything in the way means the light does not arrive.
Read the story
Lesson 103 of 117 in From Scratch
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson The problem: a screen has pixels, a scene has only numbers Rays: one straight line per pixel Spheres: where does a ray touch a ball? Normals: which way does the surface face? Diffuse light: facing the lamp makes it bright Specular light: the shiny spot depends on where the eye is Shadows: a second ray toward the lamp PPM: the easiest picture file there is The code Run it Break it: shadows with no offset What this leaves out Terms it explains: ray, normal, dot product, diffuse, specular.
Review From Scratch
Mark as read Saved in this browser, and to your account when you sign in.