Tutorial 05.0: Light and Material

https://en.wikipedia.org/wiki/Shading

Ambient Light:

    • has no source

    • is everywhere available

    • constant intensity

Diffuse Light:

    • has a direction

    • is scattered at the model surface

    • intensity depends on the angle between surface normal and incoming light direction

Specular Light:

    • has a direction

    • is reflected at the model surface

    • intensity depends on the angle between view direction and reflected light direction

vec3 Intensity(Diffuse) = Intensity(Light) * cos(N, -L)

vec3 Intensity(Specular) = Intensity(Light) * cos(R, -V) ^ Ns

vec3 N = Surface Normal

vec3 L = Light Direction

vec3 V = View Direction (Camera to Surface)

vec3 R = Reflected Light Direction

float Ns = Material(Shininess)

Note:

dot(A, B) = cos(A, B) * |A| * |B|

Light Equation:

vec3 FragmentColor(RGB) =

Intensity(Ambient) * Ka

+ TotalIntensity(Diffuse) * Kd

+ TotalIntensity(Specular) * Ks

vec3 Ka = Material(Ambient)

vec3 Kd = Material(Diffuse)

vec3 Ks = Material(Specular)

The ambient intensity in constant through the whole scene, but the diffuse and specular intensity must be accumulated for all light sources.

Material Properties:

    • vec3 Ka or "Material(Ambient)"

    • vec3 Kd or "Material(Diffuse)"

    • vec3 Ks or "Material(Specular)"

    • float Ns or "Shininess"

    • float d or "Transparency" (unused in light calculations)

    • Textures can be available

Types of Light Sources:

There are different types of light sources, each of them add a certain amount of light to the total diffuse and specular light, but NOT to the ambient part.

Directional Light:

    • has a constant direction

    • has constant intensity

    • example: sun light on earth's surface

Point Light:

    • has a position and a base intensity

    • has additional parameters for attenuation

    • intensity is distance-dependend: the bigger the distance between surface and point light, the weaker the intensity

    • example: candle or light bulb

Spot Light:

    • has a position and a base intensity as well as a middle direction

    • has an additional parameter for angle-dependend attenuation

    • the intensity depends not on the distance, but on the angle between middle direction and surface-to-light direction