Antialiasing with Supersampling
Introduction: The Problem with Jagged Edges
Welcome to the first lesson of our course on realistic rendering techniques! If you've completed the foundational ray tracing course, you now have a working ray tracer that can render spheres with proper lighting and shading. However, if you look closely at the images your ray tracer produces, you'll notice something that makes them look less realistic: jagged edges, especially along the boundaries of objects.
These jagged edges are called "aliasing artifacts," and they're one of the most noticeable differences between a basic ray tracer and a production-quality renderer. When you render a sphere against a background, the edge where the sphere meets the sky appears as a staircase pattern rather than a smooth curve. Similarly, any diagonal lines or curved surfaces in your scene will have this harsh, pixelated appearance.
In this lesson, we'll explore why aliasing happens in the first place and, more importantly, how to fix it using a technique called antialiasing through random sampling. By the end of this lesson, you'll understand how to transform your ray tracer from producing images with harsh, jagged edges to generating smooth, professional-looking renders. The technique we'll learn is fundamental to all modern rendering systems, from movie production to video games.
Understanding Aliasing: Why Do We Get Jagged Edges?
To understand why we get jagged edges, we need to think about the fundamental mismatch between the continuous world we're trying to render and the discrete pixels we're rendering into. The real world is continuous — a sphere's edge is a perfectly smooth curve. But our digital image is made up of individual square pixels arranged in a grid, and each pixel can only be one color.
Let's consider a concrete example. Imagine a diagonal line passing through your image at a 45-degree angle. In the real world, this line is infinitely thin and perfectly straight. But when we try to represent it with pixels, we have to make a binary decision for each pixel: is this pixel part of the line or not? The result is a staircase pattern where the line jumps from one row of pixels to the next.
In our current ray tracer, we shoot exactly one ray per pixel, typically through the center of that pixel. This single ray determines the entire color of that pixel. If the ray hits the sphere, the pixel is colored based on the sphere's surface. If it misses, the pixel gets the background color. There's no middle ground, no blending — just a hard decision for each pixel.
This binary approach works fine in the middle of a surface where all nearby rays would give similar results. But at the edge of an object, adjacent pixels can have completely different colors. One pixel's ray might just barely hit the sphere and return a surface color, while the next pixel's ray might just barely miss and return the sky color. This creates the harsh, staircase-like boundary we see as aliasing.

The problem is most visible at high-contrast edges, like where a dark sphere meets a bright sky. The human eye is particularly sensitive to these sharp transitions, making the jagged pattern very noticeable. Even though each individual pixel is "correct" based on the single ray we shot through it, the overall image doesn't look smooth because we're missing information about what's happening between those sample points.

