# Chapter 65: Anti-Aliasing

## Super Sampling

### Pixel Centers

When we originally talked about camera rays, we set up our coordinate system such that we had one ray generated for each pixel. This ray traveled through the center of the pixel, and we used the color found by this ray as the color we wrote out to our image file.

To implement super-sampling, we need to generate multiple rays per pixel. Then, we average up the colors of each of these rays in order to determine the color of the pixel. For example, this means that if we cast four rays for a given pixel, and two of the rays hit a purple sphere while two rays hit the black background, the resulting color would be 50% black and 50% purple (i.e. dark purple).

Recall that originally our determination of camera space coordinates from pixel coordinates looked like this:

Where are the camera space coordinates for a given pixel of an image with size .

### Super Samples

But this gives us a single coordinate in the center of the pixel. We instead want to have an grid of rays within that pixel.

A grid of super samples (sometimes called `2x super sampling`

) will produce a significantly improved image.
However, it will take up to four times as long to render.

A grid of super samples (sometimes called `3x super sampling`

) will produce an image similar to a `2x`

but perhaps slightly smoother.
However, it will take up to nine times as long to render.

In general, increasing the super sample parameter significantly increases the render time but will produce diminishing returns.

### Equations

Note that if we consider the bounds of this particular pixel, trying to find the “super sample locations” is quite similar to trying to find the “pixel center locations” within the image as a whole. In particular, it is exactly the same:

Where is the coordinate within the tiny pixel region for a given super sample when there are super samples.

Recall that in our original camera ray equation indicated the pixel of concern. We can simply add our new offset to this pixel location to produce an equation for super sample locations.

Which can be simplified to:

Where is the pixel, is the sub-pixel, is the image size and is the number of sub-pixel super-samples.

By multiplying by , we can see that this is equivalent to treating the image as times as large:

This is what we get in our original equation for (without supersampling) if we replace with and replace with .