This project is an implementation of a SSAO algorithm, done completely from scratch.
In the following video, the SSAO implementation with different adjustments are demonstrated.
Screen-space ambient occlusion adds some shading/occlusion of areas in the output image where a real occlusion is suspected. This is done by comparing depth values of the framebuffer just before rendering. If there are fragments, where most sides (computed over a local kernel) are closer to the viewer, the actual fragment, it is assumed to be less illuminated than the surrounding fragments. In this case, the fragment is shaded.
This algorithm runs only in screen space. So ignoring the complexity of the scene completely.
Any SSAO algorithm is not physically correct and also not always perfect(Bleeding over neighbouring fragments). Dependent on the viewer and camera position, different areas can be occluded.
Though not always looking perfect, it adds a very nice touch to the scenery and gives a three dimensional impression.
By adding the SSAO fragment shader to a finished game or program, screen space ambient occlusion can be adjusted and implemented without changing or accessing the actual code.
The following picture shows the final ambient occlusion without rendering any colors of the scene:
And the same view again with normal textures and colors. The ambient occlusion is added (multiplied to the fragment color):
I tested an ran this simulation on a debian-based Linux OS (Ubuntu, Mint, ...). It should run on other machines as well but is not tested.
The following system-attributes are required for running this simulation:
-
A graphics card supporting OpenGL version 3.3 (For the shaders).
-
Unix-Libraries: xorg-dev, mesa-common-dev and freeglut3-dev
It should work on Windows and OSX, but is not tested. In the root directory, execute:
- make
- ./ambient_occlusion
While the simulation runs, you can move around (always looking to the center!) with your mouse (left-klick and move) and zoom in/out with your mouse (right click and move up/down). All other options for playing around with different kinds of the ambient occlusion (resizing the kernel, ...) are displayed when pressing "h" on your keyboard.
Some possible improvements I could think of right now, are:
- Implementation of a random kernel for each fragment (persistent) to minimize bleeding over neighbouring fragments.
- Normalization of the occlusion-factor to not get fragments blacked out completely.
So, here are some more screenshots, because screenshots are awesome :)