Category Archives: Tutorials

Image Based Lighting

Image Based Lighting is used to implement ambient lighting for dynamic objects coming from static objects in a game level. In most cases, it is used for specular lighting or reflections. In this process lighting information at the potential point of interests is stored in a special type of cube maps called Light probes. These Light probes are created using environment maps captured at same locations, which are then blurred in some special way depending on the BRDF [1] that will consume them at runtime. Each mipmap of a light probe contains a version of environment map blurred by a different amount depending roughness represented by that level. For example, if we are using 10 mip map levels to represent roughness  from 0 to 1, then mip-0 will be blurred by a value representing roughness 0, mip-1 will represent 0.1 and so on. The last mip level mip-10 will be blurred by a value represent the roughness of 1.0. This process is also called Cubemap Convolution [4][5].  All of this is done as a pre-process and resulting light probes are fetched at runtime to enable reflections or Image Based Lighting.

Read the rest of this entry

Real-Time shadows : Cascaded Shadow Maps

Cascaded Shadow Maps is so far the best solution to tackle Perspective and Projective aliasing in shadows. The basic idea is to use multiple shadow maps (mostly 3 or 4) to cover different areas of view camera frustum. The root cause of these shadow artifacts is lack of one to one mapping between shadow map texels and pixels on the screen (in view space). The Cascaded Shadow mapping provides higher resolution shadow maps  to objects closer to the eye solving the root cause of artifacts.

(Screenshot – JustAnotherGameEngine)

Read the rest of this entry

Tutorial : Lighting & Shading

Lighting and Shading is one of the most basic and important things of any rendered scene. During fixed function pipeline days lighting mostly used to be phong material with a directional, point or spot light, but which the support for shader developers are free to implement any kind of light or shading model they want. So lighting and shading isn’t single thing but two different things that are closely related.This tutorial is meant for an introductory step into one of the most interesting (at least for me) and challenging topic of lighting and shading.


Lighting refers to modeling how light behaves in a virtual scene . Most of the time goal is to model the real world lights in a virtual scene as accurately as possible. But there’s a catch our processors (CPU / GPU) are not powerful enough yet to model behaviours of real world lights specially in realtime rendering. So we make some good assumptions and try to simply lights in a virtual scene which led to different lighting models. These lighting model decides the properties of light reaching the surface point.

  1. Directional Light – Directional assumes that object or the surface receiving light is either infinitely away or small from the light source so that the difference between the angles of incidence from the light position to various points of the  surface is negligible. So we can assume that light rays reaching the surface are parallel to each other which greatly simplifies the lighting calculation. To describe directional light we need just 2 constants the direction and the color of light. (We also assume the light energy or more appropriately luminous flux is a constant value.)
  2. Point Light – Point Light assumes that the light source is a single point in the virtual space that emits light energy in all direction or in a uniform spherical region around it. In this case light energy reaching surface point also depends upon the distance between the point and the light source which is proportional to inverse square distance between light source and surface point (called fall off function). Also the light direction is different for different points on the same surface and we have to calculate this vector individual for each vertex or each pixel in case of pixel lighting.  So in case of point lights the intensity of light reaching a surface point depends upon – Distance between surface point and the light source calculated for each point. The light direction vector from surface point in question to light source calculated for each point. The light color constant for a light.
  3. Ambient Light – The above two are the examples of direct lights trying to model real world counterparts. The ambient light on the other hand is not a light in itself but the cheapest way to model indirect lighting or the real world behaviour of light bouncing of the surfaces and illuminating the surroundings. In this model a constant light color value is scaled by the surface albedo is added to the shading equation to model indirect lighting.
    Ambient  (notice the cube is invisible because of flattening side effect of ambient light)
  4. There are many more types of light like area lights, spot light etc. What I have mentioned here is the most basic types of light that can be used to lit virtual scenes at cost of very small performance hit on today’s hardware.
    WarnLight (Warn light – a way to model spot light)


Appearance of an object in real world depends on how light is reflected by the object (ignoring transmittance for simplicity). Lighting models describes how light reaches a surface and the job of shading models or shading equation is to compute the outgoing light value along the view direction depending on the material properties of the surface. Shading models try to emulate the real world object surfaces like metals , plastics ,etc.

So in simple terms a shading equation can be given as –

Outgoing Light = Reflectance function * Incoming Light value at surface point to be shaded

A function that describes how light is reflected by the surface given the incoming light direction and the outgoing direction (most of the time the view direction) is known as Bidirection Reflectance Distribution Functions (BRDF) .

Some materials scatter light evenly in all directions and are called Diffuse Materials.  Simple BRDF to model such materials is  Lambertian BRDF

I_{D}=\mathbf{L}\cdot\mathbf{N} C I_{L},

where I_{D} is the intensity of the diffusely reflected light (surface brightness), C is the color and I_{L} is the intensity of the incoming light.

Another class of materials called specular materials reflect light only in mirror direction. Generally a real world material is neither purely diffuse or purely specular so both models are combines to emulate real world materials. One simple BRDF used to model such materials invented by developed by Bui Tuong Phong in 1973 is Phong BRDF.

In advance shading models the directional dependence of reflective properties of a surface materials are also considered and are classified as Isotropic and Anisotropic Materials. One of the BRDFs to model such materials is WARD BRDF.


After experimenting with some basic light models the right direction will be to read tests related to physically based rendering. Those texts get more technical with complex equations on every page so this was ment to be a simple basic tutorial to get started on things and also to give some simple models to work with. Also shaders for these BRDFs and lighting models can easily be founded on google. Here are a couple of very nice references on this subject (these books assume you are comfortable with shader based pipeline) –

  1. Advance Lighting and Materials with Shaders
  2. Physcially Based Rendering