The Lighting Model
The intensity (or color) of a pixel is given by I
I = <I
r
, I
g
, I
b
>
We will frequently deal with I as a scalar.
Just remember if we do I=F(x) it is really I = < F(x
r
, x
g
, x
b
>
Ambient light
We can't perfectly model light
So we cheat
Ambient
light is the light that is "in the room".
I
a
is a vector of ambient light at a point.
We can provide a different amount of ambient light from each light source. (L
a
)
Or we can just have an ambient light contribution in the scene.
Each surface can be given an ambient light reflective property (k
a
.
This is a vector, <k
ar
, k
ag
, k
ab
>
I
a
= k
a
L
a
Or for many lights
I
a
= Σ
lights
k
a
L
a
Diffuse Component
Diffuse light is modeled by Lambert's law of cosines
The diffuse light is proportional to the incident light and the surface normal.
R
d
~ cos(θ)
So for a incoming ray of light
l
And the surface normal
n
R
d
~ l·n = |l||n|cos(θ);
This is modified by
The diffuse component of the light source (L
d
)
The diffuse property of the surface (k
d
I
d
= k
d
(l·n)L
d
But since this can be negative, we clamp it to be positive.
I
d
= max(k
d
(l·n)L
d
,0) in c++
I
d
= clamp(k
d
(l·n)L
d
,0,1) in glsl.
Or sum this across all light sources.
There are times we want to involve the distance from the light.
Normally we would expect it to fall off in proportion to the distance from the light source (d)
or 1/d
Or even 1/d
2
But this has been found to be problematic
So the formula used in classical lighting is
1/(a+bd+cd
2
)
Where d is the distance to the light source.
And a,b and c are constants
max(k
d
(l·n)L
d
,0) I
d
= Σ
lights
----------- a + bd +cd
2
I = I
a
+ I
d