Navigation: back up next notes exercises
The following call enables/disables lighting:
glEnable(GL_LIGHTING);
glDisable(GL_LIGHTING);
OpenGL allows for atleast eight light sources in a scene (and possibly more depending upon the implementation). The lights are: GL_LIGHT0,...,GL_LIGHT7. The following call enables/disables a light in OpenGL:
glEnable(GL_LIGHT0);
glDisable(GL_LIGHT0);
OpenGL supports point lights, spot lights, and directional lights.
/* point light */ GLfloat light_position[] = { 1.0, 1.0, 1.0, 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); /* GL_LIGHT0 is a point light */
/* directional light. w parameter of light_position is 0, so light_position represents a direction */ GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); /* GL_LIGHT0 is a directional light */ /* spot light */ GLfloat light_position[] = { 1.0, 1.0, 1.0, 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); /* set the position of GL_LIGHT0 */ GLfloat spot_direction[] = { -1.0, -1.0, 0.0 }; /* direction is specified in homogenous coordinates */ glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction); /* set the direction of GL_LIGHT0 */ glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0); /* set the cutoff angle */
The following are calls which set the parameters of a light:
glLightfv(GL_LIGHT0, GL_AMBIENT, amb_light_rgba ); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif_light_rgba ); glLightfv(GL_LIGHT0, GL_SPECULAR, spec_light_rgba ); glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2.0); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 1.0); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.5); glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0);
The following calls define the surface properties to be used for all subsequently drawn objects:
glMaterialfv( GL_FRONT, GL_AMBIENT, ambient_rgba ); glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuse_rgba ); glMaterialfv( GL_FRONT, GL_SPECULAR, specular_rgba ); glMaterialfv( GL_FRONT, GL_SHININESS, n );
The position and directions of light are affected by the modelview matrix and stored in eye coordinates.
OpenGL supports smooth and gouraud shading model:
glShadeModel (GL_FLAT); /* flat shading */ glShadeModel (GL_SMOOTH); /* gouraud shading */

Spot Light
(to be written)

Traditional graphics LIMs are:
Most such ad-hoc illumination models have three components:
I = ambient + diffuse + specular
The ambient term allows for some global control of brightness in a scene. Typically,
I = Ia * ka
where Ia is an ambient illumination constant defined once for the entire scene, and ka is an ambient reflection coefficient, usually restricted to lie in [0,1].


Id = Ii k_diff cos(th), th in [-pi/2, pi/2] = Ii k_diff (N.L), N.L 0 and assuming N and L are normalized
Ii: intensity of light source i k_diff: surface reflection coefficient th: angle between N and L
The last component of the commonly-used local illumination model is one that takes into account specular reflections. The following figure illustrates the situation:
The Phong illumination model is one often-used method of calculating the specular component:
I_s = I_i k_spec cos^n(alpha)
= I_i K_spec (R.V)^n
where k_spec is a specular reflection coefficient and alpha is the angle between the reflection and viewing vector. The surface parameter 'n' can be thought of as describing the surface roughness, where an ideal mirror would have n=¥ , and a rough surface might have n=1.
How can R be computed?
The function cos^n(alpha) looks as follows:

Blinn reformulated the specular reflection model so that it agreed better with experimental results. It makes use of a halfway vector, H, as follows:
I_s = I_i k_spec cos^n(alpha)
= I_i K_spec (N.H)^n

The advantages of this model include:
Combining the various models and assuming the Phong illumination model gives:
I = I_a k_a + I_i k_diff (N.L) + I_i k_spec (R.V)^n
where each of k_a, k_diff, and k_spec are parameters which are associated with specific surfaces and take on values between 0 and 1. To deal with colour, three equations of the above form are typically used:
I = I_a_r k_a_r + I_i_r k_diff_r (N.L) + I_i_r k_spec_r (R.V)^n I = I_a_g k_a_g + I_i_g k_diff_g (N.L) + I_i_g k_spec_g (R.V)^n I = I_a_b k_a_b + I_i_b k_diff_b (N.L) + I_i_b k_spec_b (R.V)^n
Some other problems and their adhoc solutions:



For the following scene, sketch the graphs of the ambient, diffuse, specular, and total illumination seen by the eye. Your graphs should sketch I as a function of x. Use the Phong illumination model, given by:
I = K_a I_a + K_d (N.L) + K_s I_s (R.V)^n
and the following parameter values:
I_a = 0.2, I_d = 1.0, I_s = 1.0, K_a = 0.3, K_d = 0.6, K_s = 0.5, and n = 100.
Light a triangle using the Phong Illumination model
What’s the intensity at the centroid of the triangle, P = (0.333,1,1)' assuming a white object (r,g,b)=(1,1,1).
Briefly describe the limitations of the Blinn and Phong illumination models.