Keenan's Blog

Computer Graphics From Scratch

2022-10-31

2-1 Rendering a Swiss Landscape

Imagine you're in Switzerland and you come across a beautiful landscape. Its so inspiring that you need to paint it.

Figure 2-1: A swiss landscape

But if you are like me you probably lack the artistic talent to replicate it. But we can be methodical, we can cut a bug catching net into a rectangle and frame it so that we can look at the landscape through the netted frame. You then need to mark a position where your eyes should be so you can keep the same point of view while painting.

Before painting we have a fixed point of view and a fixed position for the frame that we see the landscape through. The next step is to draw a grid onto your canvas so that it is the same as the frame with the net. The methodical part is to look at the top left square of the frame and determine its predominant color. In this case the color is Sky Blue. So you fill the top left square on your canvas sky blue, you then repeat this step for each square on the canvas and the frame. The painting you get will look like the one the below.

Figure 2-2: A Rough Approximation of the Swiss Landscape

This process may not seem very logical to humans who can contexualize the environment and can paint the landscape in whatever style or fashion they have the ability to do so. But for a computer these steps are simple and easily reproducible. The process can be described like this:


For reach square on the canvas
  Paint it the right color

Simple, however, this is too abstract for a computer to understand so lets give a little bit more details:


Place Eye and Frame as desired
For Each Square on the canvas
  Determine which square on the grid corresponds to the square on the canvas
  Determine the predominant color in that grid square
  Paint the square with that color

This is still a bit too abstract but it is starting to look like an algorithm and at a high level it represents the raytracing algorithm.

<- 1-4 The Scene 2-2 Basic Assumptions->