-
Calculate vector l.
l = position of light - P
-
Must have the generic hit point on the primitive
by the inverse transformed ray.
P' = it_ray(hit_time)
-
Calculate the vector,
m', that is normal (perpendicular)
to the
generic hit point.
- The vector that is normal to the generic sphere is
the same as the generic hit point.
m' = P' - center of sphere
m' = P' - (0,0,0)
m' = P'
- The vector that is normal to the generic plane is:
- The vector that is normal to the generic square is:
- The vector that is normal to the generic tapered cylinder's:
- wall is
- base is
- cap is
-
Calculate the vector that is normal to the actual
hit point. It is the result of post-multiplying the object's inverse
transformed matrix M by the vector normal to the generic hit point:
m = M * m'
-
Normalize both vectors, l
and m.
-
Calculate value for lambert.
lambert = max{ l dot
m, 0}
-
Calculate the diffuse portion of the intensity of the
color due to this light, (each for red, green, and blue):
Idiff = lightdiff * materialdiff
* lambert
-
Calculate vector e, the vector from
the actual point, P, to the eye (camera position).
e = - ray's direction
or
e = ray.start - P
-
Normalize vector e.
-
Calculate the halfway vector h,
the vector that is halfway between vector
l and vector e.
h = l + e
-
Normalize vector h.
-
Calculate value for phong.
phong = max {0, h dot m}
-
Calculate the specular portion
of the intensity of the color due to this light (each for red, green,
and blue):
Ispec = lightspec * materialspec
* phong f
where f is the specular exponent
and 0<=f<=200.
-
Calculate the ambient portion
of the intensity of the color due to this light (each for red, green,
and blue):
Iamb = lightamb * materialamb
-
Calculate the total intensity of the
color due to this light:
IL_i = Idiff + Ispec + Iamb
-
Calculate the global ambient value
for intensity of the color (each for red, green, and blue):
IG = GlobalAmbient * materialamb
-
After calculating the IL for each
light, calculate the total value (each for red, green, and blue):
I = IL_0 + IL_1 + IL_2 + ...+ IL_numlilghts-1
+ IG
-
Return this value.