What is supersampling?
One of the most undesirable artifacts found in computer generated images is aliasing, where an edge takes on a jagged, pixelated profile. Supersampling is a method of anti-aliasing, which attempts to smooth these edges, slightly blurring the boundary, making the final image more realistic. Although the process is quite computationally expensive, its results can be strikingly effective, and all modern rendering packages will include some form of supersampling.
There are numerous variations of supersampling, a few of which are explained below, but all of them attempt to acheive the same goal, through a very similar method.
How is it done?
The reason aliasing occurs is that although real-world shapes have a smooth, continuous outline, monitors, and especially LCD screens, can only display discrete, distinct points of light, or pixels. These square pixels have a uniform colour, and if anti-aliasing is not used, the entire pixel will be coloured according to only one colour sample, taken at the centre of the pixel:
Actual shape: Pixelated image:
+-------+ +-------+
| /| | |
| o /#| | |
| /##| | |
+---/###+ +-------+
| /####| |#######|
| /#o###| |#######|
|/######| |#######|
+-------+ +-------+
Here, we can see that if only one sample is taken per pixel (where the o is), a continous straight line becomes jagged.
Supersampling, on the other hand, measures the colour at several points within each pixel, and combines the results. Although the slant of the line cannot be recreated (as each pixel is uniformly coloured), the balance of colour throughout the pixel can be reproduced much more faithfully.
In the example given above, the bottom pixel is ¾ dark and ¼ light. However, the final pixel values are entirely dark and entirely light, respectively. If supersampling had been used, the bottom pixel might have been shaded dark grey and the top pixel light grey. Without reducing pixel size, this is the best approximation to a sloping line possible.
Types of supersampling
As supersampling has to be applied to every pixel in an image, it is essential that the algorithm used is efficient, and yet effective.
This techique acknowledges that very few pixels will actually be on a boundary, and hence very few pixels justify the computation required by supersampling.
At first, just a few (maybe four) colour samples are made within the pixel. If the values for these measurements are sufficiently similar, the pixel doesn't require supersampling, and can be immediately shaded with according to the samples already taken.
This method can be used in conjunction with any of the techniques shown below, to improve their performance.
The following are methods to determine where the extra rays should be shot through the pixel.
This is the most simple ray placement algorithm. Instead of shooting a ray through the middle of the pixel, the pixel is split into n×n sub-pixels, and a ray shot through the centre of each sub-pixel.
+---------------+
| o o o o |
| |
| o o o o |
| |
| o o o o |
| |
| o o o o |
+---------------+
This algorithm is very easy to implement, and runs very fast. However, due to the regular nature of the ray placement, aliasing is still noticeable unless n is very large.
As the name suggests, this algorithm selects points in the pixel to shoot rays through at random.
+---------------+
| o o oo|
| o o |
| o |
| o o |
| o o|
| o o |
| o o o |
+---------------+
Although this prevents the problems associated with regular grids, significant parts of the pixel can be left unsampled, while others are drastically oversampled. This is a waste of resources, and in the worst case is almost comparable to no supersampling at all.
This algorithm is in many ways ideal. It uses a randomizing function to shoot rays through the pixel as above, but also checks that no two rays are too close together. This has the effect of distributing the rays throughout the pixel, preventing clumping.
+---------------+
| o o o o|
| o |
| o o |
| o o |
| o |
| o o |
| o o o o |
+---------------+
Although the results from this method are probably the best, it is a process that must be repeated millions of times in an image, and the computation cost of working out where to place the rays, let alone doing the ray-tracing itself, is too great. The render times are too poor to justify using this algorithm.
This is a hybrid of the three algorithms above. Like Poisson disc, it ensures that the rays do not clump together too much, while avoiding a regular pattern and remaining computationally cheap.
The pixel is split into n×n sub-pixels, but instead of firing a ray through the centre of each one, a random point is chosen within each sub-pixel. The example below is 2×2 for clarity.
+---------------+
| | |
| | o |
| o | |
|-------+-------|
| | o |
| o | |
| | |
+---------------+
Although clumping cannot be totally eradicated, only four rays can congregate in any one place. The simplicity of the algorithm ensures it is easy to implement.