How anti-aliasing works:
There are
many different ways for implementing anti-aliasing into a ray tracer, some are
very heavy computation wise and some are less heavy but wields not as good
results. The method that will be implemented in this project is a anti-aliasing
method that is called super sampling which is a type of full scene anti aliasing (FSAA)[1]. Super sampling is not known for being the
most effective method, though it is fairly easy to implement and gives good
results. Essentially what super sampling does is shooting more than one ray from
each pixel. It then takes the average color of all the ray hits and divides them
by how many rays that is shot from each pixel. You can also think of this as rendering the resolution of the scene 2 - 16 (Or more) times bigger and
then down sampling it down to the actual screen resolution[1]. There is also a method that is called adaptive super sampling [2][3]. When shooting out rays from the pixel a pattern is used, this part of anti-aliasing is called sampling. There are many different sampling methods and they are all suited for different tasks so there is no perfect sampling method [1]. With adaptive super sampling rays are adaptively chosen where they should be shot. Some initial rays are shot and if they have a high variance compared to each other, additional sampling will occur and thus not sampling where it won't be needed. This is more efficient than
regular super sampling and is more suited for interactive real time
applications.[3][2]
Implementation:
The method chosen
for anti-aliasing is super sampling with a grid pattern. This was chosen
because it is easy to implement and yet wields great results[1]. To implement SSAA (Super
sampling anti aliasing) rewriting the main draw-function was necessary. The
draw-functions previously only sent out one ray per pixel. The triangle that the ray struck became that pixels color even though the majority of the area of the
pixel might not be that specific color.
In the implementation of anti-aliasing several rays are sent from each pixel. The average color value of these rays becomes the pixels color. The grid pattern used was made by creating an offset on the first rays starting position. We choose to only include the possibility of square grids and not other shapes. This means that the size of sampling only can be equal to that of a perfect square.
In the implementation of anti-aliasing several rays are sent from each pixel. The average color value of these rays becomes the pixels color. The grid pattern used was made by creating an offset on the first rays starting position. We choose to only include the possibility of square grids and not other shapes. This means that the size of sampling only can be equal to that of a perfect square.
Result:
Bellow are the results for anti-aliasing different grid sizes.
Please click on the images for full resolution.
Please click on the images for full resolution.
References:
[1]Tomas, Akenine-Möller., Eric, Haines and Nathaniel Hoffman. Real Time Rendering. 3rd ed. Wellesley: AK Peters ltd, 2008. Pages 126-127.
[2]OpenGL documentation, Multisampling. (n.d).
https://www.opengl.org/wiki/Multisampling (Accessed 2015-05-25)
[3] Allan B Tucker, Computer Science handbook. 2nd ed. Boca Raton:
Taylor and Francis Group LLC, 2004. Page "39-19".
Note that this books page number actually was referred to like this, i think it means Chapter 39, page 19.
[2]OpenGL documentation, Multisampling. (n.d).
https://www.opengl.org/wiki/Multisampling (Accessed 2015-05-25)
[3] Allan B Tucker, Computer Science handbook. 2nd ed. Boca Raton:
Taylor and Francis Group LLC, 2004. Page "39-19".
Note that this books page number actually was referred to like this, i think it means Chapter 39, page 19.