Part I: Raytracing

Suppose you’re visiting some exotic place and come across a stunning landscape - so stunning, you just need to make a painting capturing its beauty.

A Swiss landscape
A Swiss landscape

You have some paper and some markers, but you absolutely lack artistic talent. Is all lost?

Not necessarily. You may not have artistic talent, but you’re methodical.

So you do the most obvious thing: you get an insect net. You cut a rectangular piece, frame it, and fix it to a stick. Now you can look at the landscape through a netted window. Next, you decide the best point of view to appreciate this landscape, and plant another stick to mark exactly where your head should be to get exactly this viewpoint:

You haven’t started the painting yet, but at least you have a fixed point of view and a fixed frame through which you can see the landscape. Moreover, this fixed frame is divided in small squares. So now comes the methodical part. You draw a grid on the paper, with the same number of squares as the insect net. Then you look at the top-left square of the net. What’s the predominant color seen through it? Sky blue. So you paint the top-left square of the paper with sky blue. You do this for every square, and soon enough, you have a pretty good painting of the landscape as seen through the window:

A crude approximation of the landscape
A crude approximation of the landscape

If you think about it, a computer is essentially a very methodical machine absolutely lacking artistic talent. If we substitute the squares in the paper with the pixels on the screen, we can describe the process of rendering a scene as follows:

For each pixel on the canvas
    Paint it with the right color


However, it’s too abstract to implement it directly on a computer. So we can go into a bit more detail:

Place the eye and the frame as desired
For each pixel on the canvas
    Determine the square on the grid corresponding to this pixel
    Determine the color seen through that square
    Paint the pixel with that color

This is still too abstract, but it starts to look like an algorithm - and perhaps surprisingly, that’s the high-level overview of the full raytracing algorithm. Yes, it’s that simple.

Of course, the devil is in the details; the following chapters will dive into each of these steps.

<< Common concepts · Basic ray tracing >>
Computer Graphics from scratch · Introduction · Table of contents · Common concepts · Part I: Raytracing · Basic ray tracing · Light · Shadows · Reflection · Arbitrary camera · Beyond the basics · Raytracer pseudocode
Part II: Rasterization · Lines · Filled triangles · Shaded triangles · Perspective projection · Scene setup · Clipping · Hidden surface removal · Shading · Textures
Found an error? Everything is in Github.