Ambient Occlusion
Representing reality has been an impactful research field for centuries. It exists across various artistic fields such as painting and sculpture.
Artistic movements like impressionism have tried to find better ways of illustrating reality than reality itself, for this they depict objects as light avoiding a defined shape or form. Light representation impacts: emotions, credibility, intention and context.
In recent years we have seen an increasing graphical improvement trying to get closer to reality. This lead to the developement of techniques to simulate light behavior in computers.
Computer generated films such as Toy story, illustrates the evolution of techniques for photorealism. Even high stylized games are not free of this requirement of respecting light behavior since it directly impacts the whatchers inmersion into the story.
That is why some rules are constant for good looking media such as light characteristics (color, intensity, spectrum, …) and light interaction (global illumination, ambient occlusion, transparency, caustics, … ).
These concepts are out of scope but I will summarize them.
Global Illumination
is a collection of techniques to simulate realistic lighting.
One of the characteristics of light is that it bounces from one surface to another. Calculating all bounces of light reaching each surface point is expensive but provides good results. For this calculations we use path tracing and ray tracing algorithms.
Algorithms like ray tracing and path tracing simulate full global illumination
, but they require significant processing power. In exchange, they provide close to real light occlusion and do not need to use ambient occlusion techniques.
This techniques are so realistic because they use the scene geometry and textures to calculate the light for a certain number of iterations (global illumination
). This iterations are known as bounces
, the number of times a light path collides on a surface and changes direction.
Example Renderers:
To simplify or “fake” global illumination we could place lights from all directions by gessing how the surface should look. Whith this strategy we avoid global illumination
, instead we only use a single bounce from each light.
Instead of placing hundreds of lights in the scene, we can group them into an image. This images are called: environment texture, cube map, HDRI, spherical map… Each one with its own characteristics.
For global illumination
we will calculate light and bounces assuming the environment image are virtual light placed really far.
Image Based Lightning
will use it as a projected texture on the surface making the calculation almost instant compared to Ray Tracing or Path Tracing. One limitation of IBL
is that we do not take into account occlusion, buuuuut… we are trying to overcome that.
RESUME: The most physically accurate approach for rendering is by ray trancing and path tracing. Real time techniques require a global illumination simplifications, usually Image Based Lighting techniques. This simplifications have limitations that we must overcome.
Ambient Occlusion was first used in “Pearl harbour” to store the quantity of ambient light that reaches the surface of an airplane 10. This same technique was used in Cruise Control a few years before to determine the reflection intensity of each window. Find more information on [1: Ben Snow: the evolution of ILM’s lighting tools; ; 2014].
We already mentioned that this technique can be expensive and time consuming. Luckily for them, films do not require real time processes even though its still desired. For this productions, they baked geometry occlusions in image sequences
and use it in the rendering pipeline as another texture.
We are going to explore two different techniques developed by ILM: Ambient Occlusion
and Reflection Occlusion
. The reason they developed two techniques is because materials are usually composed of two components: Diffuse
and Specular
.
We will start by explaining Reflection Occlusion.
Reflection Occlusion (RO) is a rendering technique used to estimate how much reflected light
reaches a surface point. In essence, it simulates how exposed each point is towards the reflection vector.
This technique uses ray tracing to detect whether the fragment is occluded or not. We then store the result on an image and darken the reflections in the final image.
Remember, this technique is view dependent therefore we need to compute it each frame or bake it if we know the camera position and the scene will not be modified.
The process to obtain the Reflection Occlusion path is
:
The limitation of this technique is that, instead of reflecting itself, it just darkens the surface. For general purposes this is enough.
In path tracing renderers, you are usually provided a parameter to choose the bounces limit. This is of course more realistic, but may take several minutes 13.
As easy and powerful this method may seem, it is not used because of the processing time it takes for each frame to calculate collision. New techniques like Ray Tracing may be able to provide real time Reflection Maps in the future.
Finally!!, we get to point of the post. We are now on the Lambert side of the formula
3.
Ambient Occlusion (AO) is a rendering technique used to estimate how much ambient light reaches a surface point. In essence, it simulates how exposed each point is to surrounding light, based on nearby geometry.
In the real world, light rays are often blocked or “occluded” by objects. This effect happens naturally and gives surfaces subtle shadows in creases, corners, and areas where objects are close together. Recreating this effect adds a layer of realism to CGI scenes (14).
That said, ambient occlusion is not physically accurate, but rather an artistic approximation of a real-world phenomenon. It’s designed to enhance depth perception and spatial relationships in rendered images without simulating full global illumination 15.
AO will generate a value (usually between 0 and 1) on a surface point that represents how much light is reaching. This technique is agnostic to the scene lights and as long as geometry doesn’t change, it can be baked.
Ambient occlusion will take care of the contact shadows. It will not account for directional shadows cast by distant light sources like windows — it only simulates shadowing caused by nearby geometry.
Let’s now compare the result with path tracing
and global illumination+AO
. The model Suzanne should have a shadow under the hat and also occlude light to his right ear.
We will use an Image Based Lighting Global Illumination technique where we project an image into the geometry based on its normal direction (diffuse lightning). All darkened and lighted areas will be provided from an irradiance texture of the environment.
The following interactive example offers three slides:
AO is actually the same idea as Reflection Occlusion. The biggest difference is that we will use lots of vectors per fragment instead of one.
The diffuse light Concept:
Mirrors bounce light from exactly one point (at least in a perfect mirror). There are cases where the mirror may be a bit dirty and it reflects light from closer directions generating a blurred image. Diffuse light works under the premise that light will hit the surface from all directions
.
This is only for illustration purposes. Concepts like Specular, Diffuse, microfacet model, Roughness, Metalness, Fresnel, Physically Based Rendering and scattering light deserve a post for themselves.
I will try to explain in the future the physical principles behind diffuse and specular lights. For the moment lets just assume the diffuse component represents the absorbed light inside the surface and radiated back in random directions
.
For more context we can look at the lambertian formula. You can also look at [2: Diffuse Irradiance; ; n.d.]:
Since light hits a surface point from all directions we must check occlusion on all directions too!!
. If there is no occlusion, the diffuse component will become the weighted average of all incident light.
A basic algorithm to calculate Ambient Occlusion is to generate random vectors inside a hemisphere aligned with the fragment normal. We ray cast in those directions and store how many rays have been occluded. We average the result and store it in a texture.
An additional layer of realism would be to integrate lambert’s rule that states: the more aligned incident rays are with the fragment’s normal, the more they contribute to the final result.
This technique is view independent therefore we can bake it and use it in any context.
With the above implementations, hemisphere rays weighted by aligment with normal direction, would be enough to make a correct implementation. further improvements would involve keeping track of the bounce color and weight it on the angle. In case the predominant direction is occluded, we will not use the main color but the surrounding ones. This is particularly usefull to avoid the sky illumination for example when there is a roof. A simplification of this method is to store a vector that is not the normal but it represents better the final color we look for
Lets review what we got until this point and put names to this techineques:
When games entered in a graphics war they looked for applying AO in the gamplay. At first the only method known was to bake it for static elements of the scene.
This worked but they where lacking dynamic ambient occlusion. The solution was to take into account only geometries of each object (this means that an object will only take into account its own geometry to calculate AO).
Screen space ambient occlusion techniques as the name suggest, will provide AO by using the screen space coordinates of the render. This provides a real time ambient occlusion calculation even though that it requires a few triks to perform fast that lead to less accuracy.