Phong Shading Example
This file contains a specific example of the Phong Shading equation.
One variant of Phong's lighting model is:
m n
I = Ia*Ka + SUM (Ii)*((Kd * N.Li) + Ks * (R.Li) )
i=1
I = final intensity (the color we want to calculate) : (RGB triple)
Ia = ambient light in the scene : (RGB triple)
Ka = ambient color of the object : (RGB triple)
m = number of lights in the scene : (integer)
Ii = intensity of light i : (RGB triple)
Kd = diffuse color of the object : (RGB triple)
Ks = specular color of the object : (RGB triple)
N = surface normal : (Normalized Vector)
Li = direction to light i : (Normalized Vector)
Ks = specular color of the object : (RGB triple)
V = view direction : (Normalized Vector, from the viewer to the object)
R = the reflection vector of V about N. R = (-2*N.V)*N + V : (Normalized Vector)
n = phong constant of the object : (integer)
------------------------------------------------------------------------------------
Example:
MATERIAL PROPERTIES:
Ka = [0.1 0.1 0.1]
Kd = [0.9 0.0 0.0]
Ks = [0.5 0.5 0.4]
n = 10
SURFACE NORMAL:
N = [0 0 1]
VIEW DIRECTION:
V = [0.23570 0.23570 -0.94281]
AMBIENT LIGHT:
Ia = [1 1 1]
SCENE LIGHTS: (m=2)
LIGHT1
L1 = [0.57735 0.57735 0.57735]
I1 = [0.5 0.5 0.5]
LIGHT2
L2 = [0 0 -1]
I2 = [0.5 0.5 0.5]
---------------------------------------------------------------
Step 1: Add ambient term
I = Ia * Ka = [1 1 1]*[0.1 0.1 0.1] = [0.1 0.1 0.1]
---------------------------------------------------------------
Step 2: Calculate R
R = (-2*N.V)*N + V
= (-2 * [0 0 1].[0.23570 0.23570 -0.94281]) * [0 0 1] + [0.23570 0.23570 -0.94281]
= (-2 * -0.94281) * [0 0 1] + [0.23570 0.23570 -0.94281]
= [0 0 1.88562] + [0.23570 0.23570 -0.94281]
= [0.23570 0.23570 0.94281]
---------------------------------------------------------------
Step 3: Add contribution from lights
LIGHT1:
I += (I1)*((Kd * N.L1) + Ks * (R.L1)^n)
N.L1 = [0 0 1].[0.57735 0.57735 0.57735] = 0.57735
Kd * N.L1 = [0.9 0.0 0.0] * 0.57735 = [0.51961 0.0 0.0]
R.L1 = [0.23570 0.23570 0.94281].[0.57735 0.57735 0.57735] = 0.81649
(R.L1)^n = 0.81649 ^ 10 = 0.13167
Ks * (R.L1)^n = [0.5 0.5 0.4] * 0.13167 = [0.06583 0.06583 0.05267]
+= [0.5 0.5 0.5] * ([0.51961 0.0 0.0] + [0.06583 0.06583 0.05267])
+= [0.5 0.5 0.5] * [0.58544 0.06583 0.05267]
+= [0.29272 0.03292 0.02634]
I = [0.39272 0.13292 0.12634]
LIGHT2:
I += (I1)*((Kd * N.L1) + Ks * (R.L1)^n)
N.L2 = [0 0 1].[0 0 -1] = -1
Since this dot product is negative, this light does not fall on the
surface, and thus does not contribute to the final intensity. Note also
that if R.L1 < 0, it should be set to 0.
---------------------------------------------------------------
So the final intensity in this example is:
I = [0.39272 0.13292 0.12634]