Page 6: Rasterization: How we draw

Spring 2026 Sample Solution

Now that we’ve learned what pixels are, and the problems with using them, we can ask the question: How do we turn our 3D scene into pixels? Or, to be precise, how do we compute the color for each image pixel that is created by the camera viewing the 3D scene?

Pixels vs. Fragments

First, I want to make a fine terminology point.

We defined a pixel as a point sample of the image: it is the value that actually is in the image.

Imagine a point sample that is made on a triangle. It could be a pixel - if it appears on the screen. However, it might not become a pixel. For example, we might compute the color of that point sample and decide that some other triangle is blocking it, or that it needs to be combined with something else for anti-aliasing purposes.

We use the term fragment to refer to something that is basically a pixel that hasn’t made it to the final image yet. We distinguish it from a pixel because it might not become a pixel.

You might think of a fragment as a “pixel candidate” - it is something that is computed (a point sample on a triangle) because it might become a pixel.

The terms are sometimes conflated: we talk about pixels, even though they are really fragments. Early descriptions of graphics hardware and shaders used the term pixel for everything. I will try to use the terms pixels and fragments correctly.

Rasterization

The algorithm that the graphics hardware uses is called rasterization. Basically, we convert each triangle separately.

We can figure out where a triangle in the world is in the 2D plane of the image by applying a transformation to its vertices. We can then draw this 2D triangle by determining which pixels it covers (i.e., those that are inside of it).


1  for each triangle T
2      T' = transform(T) // find screen space triangle
3      for each pixel that T' covers
4          fill the pixel with the appropriate color

There is a catch: if multiple triangles cover the same pixel, we want to see the triangle that is closest to the camera (close triangles occlude farther ones). For now, we will assume the triangles are not transparent. This problem is called occlusion and we will need algorithms to handle it. We’ll discuss that on the next page.

So, technically, this algorithm computes fragments, since the colors computed in line 4 might not make it to the final image.

Notice that there is a nested loop: for each triangle, we consider each fragment (pixel) of the triangle. There is a potential for inefficiency: if the triangle isn’t visible, we still may spend time processing it.

The Need for Speed

There are a few key things we need to do to make the rasterization process fast.

  1. We need to be able to process triangles and pixels in parallel.
  2. We do not want to waste time drawing triangles and pixels that we cannot see.
  3. We want to perform bounded computations for each triangle and pixel.

The desire for parallelism, and for bounded computation, means that each triangle should be independent. If one triangle can depend on others, we have order dependencies (so we cannot process them in parallel), and potentially unbounded computations (there may be many triangles to consider).

The rasterization “algorithm” generally does treat each triangle and each fragment independently, which allows for parallelization. There is a dependency created by the need to do occlusion. On the next page, we’ll learn about the Z-buffer algorithm which allows us to keep the independence of this algorithm by handling occlusion after the fragments have been collected.

The desire to keep each triangle and fragment independent does cause limitations. It means that all shading computations (lighting) must be local: the color of a fragment can depend on lights and textures, but not on other fragments or triangles. It means that anti-aliasing is challenging for pixels that are “partially covered” by multiple triangles. It can be wasteful: one triangle cannot know if another triangle will occlude it.

However, the simplicity and efficiency that come from the independence assumption mean that it is the primary way that graphics systems are built. These downsides are handled with “hacks” and extra processing steps outside the rasterization process.

Ray Tracing vs. Rasterization

Rasterization loops over the triangles, working more like a painter drawing objects onto the canvas than the physical process by which light travels and forms images in the real world.

Ray tracing is a different algorithm for drawing 3D scenes. It more closely mimics the natural process: we ask for each pixel (or other position - we’ll get to that in a moment), where did the light coming to that position come from? Ray tracing is a big topic unto itself - we introduce it briefly here to contrast it with rasterization.

In the real world, light starts at a light source, bounces around, and then some small amount of it makes it to our eye, or the camera/sensor that we are making a picture with. We call this “algorithm” from-the-source ray tracing. Because nature is massively parallel (lots of photons), the fact that most photons won’t make it to our sensor doesn’t matter. Light doesn’t exist just for us to see it.

In the graphics world, we only care about the light that eventually affects the image. Therefore, most ray tracing works “backwards”. We start where the light ends up, and ask “where could it have come from?” While the term “backwards ray-tracing” was sometimes used, it is ambiguous. Is it backwards from physics, or backwards from how we normally do things in graphics? Therefore, I prefer terms like from-the-eye ray tracing.

From-the-eye ray tracing has a very similar structure to rasterization: we consider every pixel, and check it against every triangle:


1  for each pixel P 
2      for each triangle T
3          if T is seen by P
4              fill the pixel with the appropriate color

Line 3 asks whether the ray of light that reaches the pixel could have come from the triangle. Or, shooting the ray from the eye, does the ray intersect the triangle? This ray/object intersection is a core computation. One advantage to ray tracing: it can easily handle primitives other than triangles; any shape that has a ray/object intersection procedure can work.

Notice that the ray tracing algorithm is also a nested loop like rasterization; however, it has the loops in the reverse order. Ray tracing requires its inner loop to consider all triangles. The key to making ray tracing efficient is to use spatial data structures so the inner loop doesn’t have to consider all objects in the scene.

Historically, ray tracing has been difficult to make efficient because the key computations have to consider large numbers of objects. However, recent hardware advances make the spatial data structures practical.

The real advantage to ray tracing is that it can be applied recursively. We start at a pixel and trace backwards to a point on an object where the light for that pixel would have come from. We can then apply ray tracing from that point (recursively) to ask where the light came from to reach that point. This process mimics how nature does lighting (except that we trace backwards). It does allow for objects to interact with each other: the light that hits one object might come from bouncing off another object.

We will return to discuss ray tracing later in the course, although sadly, we don’t have enough time to discuss it in depth. For now, the main thing to know is that it is not how most interactive 3D graphics are created.

How are Triangles Drawn?

The key step of rasterization is to convert a triangle into a list of fragments. That is, to figure out which pixels the triangle “covers”.

Notice that this inherently creates an aliasing problem: we ask whether the pixel is inside of the triangle, which is a binary test. It creates a hard edge, which is susceptible to aliasing. We won’t worry about that for now.

Here is a very simple algorithm for converting a triangle to pixels:


1  for each pixel P 
2      compute the barycentric coordinates
3      if the coordinates are positive, include the pixel

It is easy to estimate what pixels to consider (for example, the rectangular bounding box around the triangle). Computing the barycentric coordinates gives a quick inside/outside test; and if the test succeeds, the barycentric coordinates are very useful (we use them to interpolate colors, texture coordinates, and depth values). It might seem a little wasteful to try extra points, but this is made up for by the fact that we can do each one of these tests in parallel. This algorithm lends itself well to hardware.

There are fancier “software” methods for enumerating the pixels inside of triangles. Often, it involves finding the left and right edges of each horizontal row by tracing along the edges of the triangles. These algorithms are called scan conversion. They are more complicated to implement.

What do we need to know?

We generally don’t need to implement rasterization: it’s done by the hardware and controlled by the API.

The independence assumption explains why many of the choices in how we implement graphics are the way they are. For example, it explains why we need hacks for reflections and shadows, and why anti-aliasing between triangles is a problem.

Central to rasterization is the strategy for handling occlusion, which we will discuss next.

Next: Page  7 - Handling Occlusion