Implementing Phong reflection for multiple light sources
We implemented multiple light sources in the fragment shader,
and added most of the Phong reflection model for
multiple light sources.
I only implemented the ambient and diffuse components
of Phong reflection.
I left instructions in the code to help you
implement the specular component,
which you will be doing as part of your homework.
In order to do that, you will first need to
construct the reflection vector R,
which represents the mirror image
about surface normal N of the
vector from the surface point to the direction LDiri of light source i.
As we showed in class, for any light source direction LDiri, R is computed by:
R = 2 (N • LDiri) N - LDiri
After you have computed R, you then need to
take the dot product of R and the direction to the eye E raised to the specular power p,
and multiply by the light color LColi:
LColi max(0, R • E)p
The direction E to the eye is just the direction tracing back along
our ray from V to W,
so E is just -W.
The resulting color is added to the
total surface color to create a highlight from this light source.
Casting shadows
We also implemented ray traced shadows.
This just consists of tracing a ray from the
surface point toward each light direction LDiri
to see whether there are any obstacles in the way.
If there are, then we don't
add the diffuse or specular component for that light source.
Homework
Due next Wednesday before the start of class
Complete the included code in
hw3.zip
and follow the notes in the fragment shader code
to implement the specular component of Phong reflection.
You can also take this opportunity to create
a cool new scene with multiple light sources
and
interesting animations.
A caution:
You always need to make sure that the light
direction vectors in uLDir
are normalized to unit length.
I will give extra credit if you
manage to animate your light direction vectors and then
normalize them to unit length in the Javascript code.
As usual, see if you can create something fun and original.
Feel free to add other capabilities if you are feeling
ambitious. We definitely give extra credit for work
that goes above and beyond. :-)