Adjusting Lighting Move the sliders around and hit the Redraw button. This works best in 24 bit color. I welcome any comments on the applet, esp. the user interface.
At the top of this page you should see an applet with 17 sliders, a button and an image (that is possibly still being computed). The image is of a sphere against a dark grey back ground, but likely that is not how it current appears.
To understand what you are seeing, you have to know a little about the way three dimensional space is represented on a flat display. The computer thinks in terms of two directions, horizontal and vertical. Unlike the way we usually represent 2-dim. space, the origin is in the top left corner and the vertical axis points down. In order to have an image appear rightside up, you must always remember to have it drawn upside down
Furthermore, distances are calculated in terms of pixels; the smallest distinct element that the computer can show. For example the "A" in "Ambient Light" in the applet looks like this: Here you can see the individual pixels making up the image of the "A". The image of the sphere above measures 244 by 244 pixels. To create an image, we must only decide what color each of the pixels in the image should show.
For the sake of simplicity, the code which draws the sphere does all of the computation as if the sphere has radius 1 and is centered at the origin. This makes thinking of the model easy and makes scaling the image much easier, but it does require some of the computations to be done with floating point arithmetic rather than integer arithmetic.
With a sphere of radius one at the origin, the picture looks like the
The view point is located out ten units along the positive z-axis. The light source is adjustable with the sliders labeled D and T. The light is at the point (D*sin(T), D*sin(T), D*cos(T)).
The sphere is colored according to the illumination model of Phong Bui-Tuong
[see p. 729 of Foley, et al.]. The red, green and blue colors of each pixel
on the sphere are determined by the equation
This image shows where the various vectors that appear in the illumination equation appear on the sphere. All four are unit vectors so that dot products give the cosines of the angles between the vectors. Snell's law for reflections implies that