Illumination and Shading
Illumination and Shading
Illumination and Shading
V - Semester
Unit – 4
L N(N•L) L L
R = 2N(N•L) - L
• Fuzzier highlight V
Phong Illumination
Moving Light
Change n
Putting It All Together
• Single Light (white light source)
Multiple Light Source
• IL: light intensity
glMaterialfv( GL_FRONT_AND_BACK,
GL_AMBIENT, black);
glMaterialfv( GL_FRONT_AND_BACK,
GL_DIFFUSE, white8);
glMaterialfv( GL_FRONT_AND_BACK,
GL_SPECULAR, white2);
glMaterialfv( GL_FRONT_AND_BACK,
GL_SHININESS, mat_shininess);
OpenGL Lighting
GLfloat white[] = {1., 1., 1., 1.};
GLfloat light0_position[] = {1., 1., 5., 0.}; /* directional light (w=0) */
glEnable(GL_LIGHTING);
Shading Models for Polygons
Constant Shading (flat shading)
Interpolated Shading
Dark facet looks darker and lighter looks even more lighter
Smooth Shading
• Need to have per-vertex normals
• Gouraud Shading
– Interpolate color across triangles
– Fast, supported by most of the graphics
accelerator cards
• Phong Shading
– Interpolate normals across triangles
– More accurate, but slow. Not widely supported by
hardware
Gouraud Shading
• Normals are computed at the polygon vertices
• If we only have per-face normals, the normal at each
vertex is the average of the normals of its adjacent
faces
• Intensity interpolation: linearly interpolate the pixel
intensity (color) across a polygon surface
Linear Interpolation
• Calculate the value of a point based on
the distances to the point’s two neighbor points
• If v1 and v2 are known, then
x = b/(a+b) * v1 + a/(a+b) * v2
Linear Interpolation in a
Triangle
• To determine the intensity (color)
of point P in the triangle,
• we will do:
• determine the intensity of 4 by
linearly interpolating between 1
and 2
• determine the intensity of 5 by
linearly interpolating between 2
and 3
• determine the intensity of P by
linear interpolating between 4
and 5
Mach Band ?
Image
Phong Shading Model
Gouraud shading does not properly handle specular highlights,
specially when the n parameter is large (small highlight).