The diffuse light contribution has an additional multiplicative factor,
proportional to (s.m), and the specular component has a multiplicative
factor (h.m)f
Exercise: Which of these terms is affected as the eye or the light source moves?
GLfloat lpos[]= [3.0, 4.0, 5.0, 1.0]; GLfloat fpos[]= [1.0, 0.0, 0.0, 0];
glLightfv(GL_LIGHT0, GL_POSITION, lpos); glLightfv(GL_LIGHT1, GL_POSITION, fpos);
GLfloat amb0[]={0.1, 0.1, 0.5, 1}; GLfloat amb1[]={0.1, 0.1, 0.1, 1};
glLightfv(GL_LIGHT0, GL_AMBIENT, amb0); glLightfv(GL_LIGHT1, GL_AMBIENT, amb1);
GLfloat diff0[]={0.3, 0.3, 0, 1};
glLightfv(GL_LIGHT0, GL_DIFFUSE, diff0);
GLfloat spec1[]={1, 0.8, 0, 1};
glLightfv(GL_LIGHT1, GL_SPECULAR, spec1);
GLfloat dir[]={2, 1, 4};
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, dir);
// let this one be a spotlight instead of a point source
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 30);
// spotlight cutoff half-angle in degrees
glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2);
// spotlight intensity decay exponent for cosine(angle from center ray)
glLIGHTf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0);
glLIGHTf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 2.0);
glLIGHTf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 3.0);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0); glEnable(GL_LIGHT1);
GLfloat amb[]={0.1, 0.1, 0.1}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb); //global ambient light
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
// to force accurate computation of true direction of eye from each vertex
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
// to force back faces to be shaded
Ambient: black.
All are omnidirectional point sources (unless otherwise specified).
Diffuse: white for LIGHT0, black for others.
Specular: white for LIGHT0, black for others.
Attenuation parameters are 1, 0, 0, i.e., no attenuation (1/(1+0+0)).
Diffuse light (associated with a light source) does come from a specific
direction,
although it is reflected equally in all directions when it hits
a surface;
but ambient light does not come from a specific direction.
light 3 4 5 .8 .8 .8
background 1 1 1
globalAmbient .1 .1 .1
ambient .2 .6 0 diffuse .8 .2 .1 specular 1 1 1 specularExponent 20
scale 4 4 4 sphere