Author: Romain Vergne (website)
Please cite my name and add a link to my web page if you use this course

Image synthesis and OpenGL: lighting

Quick links to:
  1. The problem
  2. Color
  3. The rendering equation
  4. Local lighting
  5. Types of lights
  6. Types of reflections
  7. Computing lighting on the GPU
  8. Sources

The problem



The illumination on a given point of the surface depends on:


  • primary light sources
    • direct lighting
  • secondary light sources
    • all the objects in the scene
    • an illuminated object becomes a light source
    • indirect lighting
  • Complex phenomenon:
    • Color bleeding
    • Shadows


Cornel box (1984)
We will be mainly interested in direct lighting and local illumination in this course.



The illumination on a given point of the surface depends on:
  • The viewpoint
  • The surface properties
    • reflexion
    • absorption
    • diffusion
  • The light properties
    • direction
    • wavelenght
    • energy
Involve a lot of dimensions


Color


Physically, visible light is an electromagnetic wave




Physiologically, our eyes use 3 types of sensors to perceive light colors

In computer science



Additive models
(lighting)
Soustractive models
(painting)



Color matching functions: spectral sensitivity
curves of 3 linear light detectors
If \( I (\lambda) \) is the spectral distribution of a color, then:

\[
X = \int_{400}^{800} I(\lambda) \bar{x}(\lambda) d \lambda
\]
\[
Y = \int_{400}^{800} I(\lambda) \bar{y}(\lambda) d \lambda
\]
\[
Z = \int_{400}^{800} I(\lambda) \bar{z}(\lambda) d \lambda
\]



Still, the perception of colors is not well understood and the perfect color space does not exist! (example of color contrast)
try this excellent demo

Coding colors



The rendering equation [Kajiya 1986]

\[
L(\mathbf{p} \rightarrow \mathbf{e}) =
 L_e(\mathbf{p} \rightarrow \mathbf{e}) +
 \int_{\Omega_\mathbf{n}}
  \rho(\mathbf{p}, \mathbf{e}, \pmb{\ell})
  (\mathbf{n}\cdot\pmb{\ell}) \
   L(\mathbf{p} \leftarrow \pmb{\ell}) \
  d\pmb{\ell}
\]

Local lighting

General equation


Empirical model for computing the outgoing radiance
\[
L(\mathbf{p} \rightarrow \mathbf{e}) =
\rho_a L_a +
 \sum_{k}
  \rho(\mathbf{p}, \mathbf{e}, \pmb{\ell}_k) \
  (\mathbf{n}\cdot\pmb{\ell}_k) \
   L(\mathbf{p} \leftarrow \pmb{\ell}_k)
\]

The simplest model: assign a color at each point of the surface (albedo)

\[
L(\mathbf{p} \rightarrow \mathbf{e}) = color
\]

The second simplest model: consider a single dynamic light

\[
L(\mathbf{p} \rightarrow \mathbf{e}) =
  \rho(\mathbf{p}, \mathbf{e}, \pmb{\ell}) \
  (\mathbf{n}\cdot\pmb{\ell}) \
   L(\mathbf{p} \leftarrow \pmb{\ell})
\]

Types of lights

Infinitesimal lights



Directionnal light
  • Distant sources (sun)
  • Environment maps (video-games)
\[
L(\mathbf{p} \leftarrow \pmb{\ell})  = L
\]
Point light
  • position in space \( \mathbf{p}_{\pmb{\ell}} \)
  • near, small sources
\[
L(\mathbf{p} \leftarrow \pmb{\ell})  = L/r^2
\]
with \( r = || \mathbf{p} - \mathbf{p}_{\pmb{\ell}} || \) and \( \pmb{\ell} = \frac{\mathbf{p} - \mathbf{p}_{\pmb{\ell}} }{r} \)
Spot light
  • position in space
  • near, small sources
  • defined in a cone
    • direction \( \mathbf{s}_{\pmb{\ell}} \)
    • exponent \( e \)
    • a cutoff \( c \)
\[
L(\mathbf{p} \leftarrow \pmb{\ell})  = \frac{(\mathbf{s}_{\pmb{\ell}} \cdot \pmb{\ell})^e L}{r^2}
\]
if \( (\mathbf{s}_{\pmb{\ell}} \cdot \pmb{\ell})<c \) and 0 otherwise



Area lights



  • Defined on volumes / surfaces
  • Soft shadows
  • Expensive!

Types of reflections

Lets consider a (white) directional light ( \( L=cst=(1,1,1) \) ). The model is equal to:
\[
L(\mathbf{p} \rightarrow \mathbf{e}) =
  \rho(\mathbf{p}, \mathbf{e}, \pmb{\ell}) \
  (\mathbf{n}\cdot\pmb{\ell})
\]

The lambertian model



Lambertian surface
\[ \rho(\mathbf{p}, \mathbf{e}, \pmb{\ell}) = cst \]
  • Light is diffused in every direction
  • Independant on the point of view

\[
L(\mathbf{p} \rightarrow \mathbf{e}) =
  \rho_d \
  (\mathbf{n}\cdot\pmb{\ell}) L_d
\]
\[
L(\mathbf{p} \rightarrow \mathbf{e}) =
  \sum_k \rho_{kd} \
  (\mathbf{n}\cdot\pmb{\ell}) L_{kd}
\]
One light:
  • \( \rho_d = \) constant diffuse material color 
  • \(  L_d = \) constant diffuse light color
Multiple light
  • sum of contribution of each light
  • may have different color coeficients

The mirror and transparent models




Mirror surface
\[ \rho(\mathbf{p}, \mathbf{e}, \pmb{\ell}) = cst\ if\ (\mathbf{r}\cdot\mathbf{e}=1),\ 0\ otherwise \]
  • Reflected light vector \( \mathbf{r}=2 \mathbf{n} (\mathbf{n}\cdot \pmb{\ell})-\pmb{\ell} \)
  • Dependant on the point of view
  • Usefull for environment maps
    • compute the reflected view vector
    • \( \mathbf{r}=2 \mathbf{n} (\mathbf{n}\cdot \mathbf{e})-\mathbf{e} \)
    • use it to fetch a color in the map




Transparent surface
\[ \rho(\mathbf{p}, \mathbf{e}, \pmb{\ell}) = cst\ if\ (\mathbf{r}\cdot\mathbf{e}=1),\ 0\ otherwise \]
  • Refracted light vector \( \mathbf{r}=e \pmb{\ell} - (e (\mathbf{n}\cdot \pmb{\ell}) + \sqrt{1-e^2 (1-(\mathbf{n}\cdot \pmb{\ell})^2)}) \mathbf{n} \)
  • Dependant on the point of view
  • Same principle for environment maps



\[
L(\mathbf{p} \rightarrow \mathbf{e}) =
  \rho_s(\mathbf{p}, \mathbf{e}, \pmb{\ell}) \
  (\mathbf{n}\cdot\pmb{\ell}) L_s
\]
\[
L(\mathbf{p} \rightarrow \mathbf{e}) =
  \sum_k \rho_{ks} (\mathbf{p}, \mathbf{e}, \pmb{\ell})\
  (\mathbf{n}\cdot\pmb{\ell}) L_{ks}
\]
One light:
  • \( \rho_s = \) constant specular material color 
  • \(  L_s = \) constant specular light color
Multiple light
  • sum of contribution of each light
  • may have different color coeficients


Glossy models






Glossy surface \[ \rho(\mathbf{p}, \mathbf{e}, \pmb{\ell}) =  \rho_d(\mathbf{p}, \mathbf{e}, \pmb{\ell}) + \rho_s(\mathbf{p}, \mathbf{e}, \pmb{\ell}) \]
  • Usually expressed as a sum of diffuse and specular terms
  • \( \rho_d = cst \) (as before)
  • \( \rho_s = (\mathbf{r}\cdot\mathbf{e})^e\) (for instance)

The Phong model



\( \rho_s = (\mathbf{r}\cdot\mathbf{e})^e\)

The general formulation of the Phong model is given by a weighted sum of an ambient, diffuse and specular term:
\[
L(\mathbf{p} \rightarrow \mathbf{e}) = \rho_a L_a + \sum_k  \rho_{kd} L_{kd} (\mathbf{n}\cdot\pmb{\ell}) + \rho_{ks} L_{ks} (\mathbf{r}\cdot\mathbf{e})^e
\]
where

The Blinn-Phong Model



Specular term replaced by \( \rho_s = (\mathbf{h}\cdot\mathbf{n})^e \) , with \( \mathbf{h}=\frac{\pmb{\ell}+\mathbf{e}}{|| \pmb{\ell}+\mathbf{e}||} \)

Anisotropy effect


Specular term replaced by \( \rho_s = (\mathbf{h}\cdot\mathbf{n})^{n_u cos^2\phi + n_v sin^2 \phi} \)

Fresnel effect


Obtained using Schlick approximation: \( F = R_s + (1-R_s)(1-\mathbf{e}\cdot\mathbf{h})^5 \)

Other effects?





Diffraction
Non-realistic effects
Varying material properties

How to compute lighting on the GPU?

Flat shading


Compute lighting per face
  • In the vertex shader
  • Normals are constant for the vertices of each triangle
  • Produce shading discontinuities

Gouraud Shading

Compute lighting per vertex
  • In the vertex shader
  • Normals are different for each vertex
  • Color is computed and interpolated during rasterization
  • Quality / result depends on tesselation
Question: what is the color at point M?


Phong Shading (different from the Phong model)



Compute lighting per fragment
  • Normals are interpolated during rasterization (vertex to fragment)
  • Normals are re-normalized
  • Color is computed
  • Best result


Sources


PREVIOUS: EXERCICE03
NEXT: EXERCICE04