Saturday, May 2, 2026

Primer:Lighting

Overview 
Lighting is an important factor to consider while rendering realistic 3D shapes.  The following discusses adapting lighting conditions while rendering 3D images.

Details
According to physics, visible light is made up of a band of different wavelengths. Each segment has a designated color that human eye can detect.


When light is shone on an object, it absorbs some wavelengths and reflects some giving out the color based on the material property of the object. 
The reflection is different based on its proximity to the light source and the angle between its position and  the light source. Therefore light calculations should factor these.

The calculations primarily considers three kinds of light sources.

Ambient
Ambient light means that light always existed in absence of a light source. Imagine a unlit room next to the street where light is coming in from a street lamp through the window bouncing off the walls onto curtains, furniture etc. It's dark, yet curtains, furnitures etc are visible albeit not clearly.
This pictorially represented as below
To calculate the amount of ambient reflection (I) on a surface,  the formula below is used.
I = Ka  ∑ Ia
Ka  is the ambient reflection intensity of the material that ranges from 0 to 1. Higher the value stronger is the reflection.
Ia  is global of the ambient reflection intensity of the individual light source.

Example:
In this example, the Red light falls on Gray object. Here the 3rd image shows ambient lighting of the the back face of the sphere where lighting is same everywhere.


Diffused Light
Diffused light means that directional light that is reflected equally irrespective of user view point. The effectiveness of the reflection depends on the angle of incidence and the surface normal. In other words, the cross product of both. The lesser the value, higher is the reflection.

This pictorially represented as below. θ represents the cross product between light incidence and the surface normal.

To calculate the amount of diffuse reflection (I) on a surface,  the formula below is used.
I = Kd Ip (n.L)
Kd  is the surface diffuse reflection intensity of the material that ranges from 0 to 1. Higher the value stronger is the reflection.
Ia  is the diffuse reflection intensity of the light source.
n.L is the cross product of the surface normal n and light incident on the surface.

Example:
In this example, the red light falls on Gray object. Here the 3rd image represents the back face of the sphere where lighting is poor because of angle of incidence.
The 4th image combines both ambient and diffuse lighting highlighting the curvature.


Specular Light
Specular light applies to smooth and polished surfaces that readily reflect light. When light hits the shiny surface it forms bright highlights.Here the reflection is targeted and is perpendicular to the angle of incidence in the opposite direction. A viewer can see only if in exactly the right position, somewhere along the path of the reflection.

Specular reflection from a very shiny surface produces very narrow cones of reflected light;
specular highlights on such a material are small and sharp. A duller surface will produce wider
cones of reflected light.

Specular reflection can be calculated as follows.
I = Ks  Imax(0,v⋅r)ᵖ

Ks is the specular reflection coefficient to determine how strong or weak the specular reflection appears.
Il is the brightness of the light source illuminating the surface.
v⋅r is the cross product between the observer's line of view and the direction of the reflected light.
p is known as the shininess factor. As p increases, the light cone becomes narrower (because r⋅e ≤ 1), the highlighted spot becomes smaller.
max(0,v⋅r)ᵖ controls the size and sharpness of the specular highlight, making it more or less focused depending on the value of p.  The max returns 0 is returned if the v.r is negative.

Example
In this example, the White light source falls on Gray object. The 3rd image shows the specular reflection. The fourth images shows combined reflection of ambient,diffuse and specular.


Emissive Light
Some surfaces such as ovens, tv screens etc may emit light. It's independent and can be directly factored.
I=Km
Km is emissive light value.