This project is read-only.

Ambient Light

A scene without indirect illumination looks extremely unrealistic. Objects in shadow could look completely black, something unlikely in every scene.

Applying a uniform color that does not depend of the local lights, geometry or camera position is the simplest model of indirect illumination. This simple solution improves significantly the scene realism at a really small cost. However, even if the ambient light is by definition low frequency diffuse information, a uniform color is not enough to produce a photo-realistic look.

A better alternative is image based ambient illumination. This method samples an ambient map that contains the diffuse illumination information of far light sources. To access this map the surface normals are used instead of the reflection vector, for this reason there is no need to use any local illumination parameter. To obtain the correct ambient contribution the map should be sampled in all directions of the hemisphere centered on the surface normal and modulated using the Lambert cosine law.

Comparative between a uniform color ambient lighting and image based ambient lighting.

There are a number of alternatives to store ambient maps that varies on efficient, practicality and efficiency. The most used mediums are cube maps, spherical harmonics and Valve's ambient cubes. Other methods like wavelets (better for a little higher frequency information) and zonal harmonics (easy to rotate) are other good alternatives but that are normally used in other global illumination techniques.

XNA Final Engine implements spherical harmonics lighting and the uniform color technique.

Cube Maps

It is the easiest alternative. However, when the map is sampled we should do it in several directions to approximate better the diffuse contribution. Heidrich (1999) propose to apply a convolution operator on the cubic map so that to obtain in each texel an approximation of the overall contribution for surface points with normal in the direction of that texel. Consequently only one texture access operation is needed. Typically the convolution operator used is a blur filter. Moreover, given that it is low frequency information small resolutions, like 128x128, are more than enough.

Top: the original ambient map. Bottom: the same map with a convolution operator applied.

Spherical Harmonics

The price of keeping in memory and accessing a cube map could be too high even if the map is very small. Spherical harmonics reduce dramatically memory consumption and access time maintaining an accurate representation at the expense of doing extra but simple mathematical calculations.

Spherical harmonics is a mathematical system analog to the Fourier transform, but it's defined in the sphere surface. Intuitively, given a direction it returns a value that is an approximation of the original spherical function. The approximation is more accurate if more base functions are used, but given the properties of the bases used and the fact that the ambient light only requires low frequency information, then with just few bases it is possible to reconstruct an approximation of the original map.

Sphere rendered using (a) the original ambient map (b) the convoluted ambient map (c) second order spherical harmonics.

Second order spherical harmonics are used in the engine and that means that only 9 base functions per color channel are needed. The 27 base functions (9 per channel) are stored directly in the shader algorithm, only 27 coefficients need to be sent to the GPU (and store them in registers) and these coefficients could be calculated automatically by the engine itself if a non-convoluted cube map is supplied.

Ambient Cube

Valve propose the ambient cube method, that are cube maps of only one pixel per face, and because of their size they could be stored in registers.

The algorithm to sample these maps is very simple:
   float3 normalSquared = worldNormal * worldNormal;
   int3 isNegative = ( worldNormal < 0.0 );
   float3 linearColor;
   linearColor =  normalSquared.x * cAmbientCube[isNegative.x] +
                        normalSquared.y * cAmbientCube[isNegative.y+2] +
                        normalSquared.z * cAmbientCube[isNegative.z+4];

Sphere rendered using (a) the original ambient map (b) second order spherical harmonics (c) ambient cube.

They are less accurate than second order spherical harmonics and they lack of some useful properties but still they are simple, fast and useful for very low frequency information.

How to Obtain a Suitable Texture for Ambient Lighting

For ambient light it is almost mandatory to use a HDR texture as a source. HDR textures represent a higher range of brightness values and therefore could capture the intensity of the sun and the subtle illumination of the blue sky.

HDR image


Schneider J., Master Thesis, 2013.

Last edited Feb 5, 2013 at 9:39 PM by jischneider, version 30


No comments yet.