Shadows + Light +Texture Chen Jing-Fung (2006/12/15) Assistant Research Fellow, Digital Media Center, National Taiwan Normal University Ch10: Computer Graphics with OpenGL 3th, Hearn Baker Ch6: Interactive Computer Graphics 3th, Addison Wesley Ch7: Interactive Computer Graphics 3th, Addison Wesley
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Shadows + Light +Texture
Chen Jing-Fung (2006/12/15) Assistant Research Fellow,
Digital Media Center, National Taiwan Normal University
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); /* set up standard orthogonal view with clipping */ /* box as cube of side 2 centered at origin */ glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(-2.0, 2.0, -2.0, 2.0, -5.0, 5.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0); // view plane up vector at y-axis (0.0,1.0,0.0)
10
Polygon & its shadow
/* define unit square polygon */ glColor3f(1.0, 0.0, 0.0);/* set drawing/fill color to red*/ glBegin(GL_POLYGON); glVertex3f(…); … glEnd(); glPushMatrix(); //save state glTranslatef(light[0], light[1],light[2]); //translate back glMultMatrixf(m); //project glTranslatef(-light[0], -light[1],-light[2]); //return origin //shadow object glColor3f(0.0,0.0,0.0); glBegin(GL_POLYGON); glVertex3f(…);… glEnd(); glPopMatrix(); //restore state
How to design the different size between original polygon & its shadow?
• The simplest model for an object and its light source – Light rays are generated along radially
diverging paths from the single-color source position
• light source is a single color – The light source’s size is smaller than object
– We can use an illumination model to calculate the light direction to a selected object surface’s position
20
Infinitely distant light sources
• A large light source (sun) that is very far from a scene like a point light source
• Large light source is small different to point light source – When remote the point light source, the
object is illuminated at only one direction
– In constant to sun which is very far so it shines everywhere
21
Radial intensity attenuation (1)
• As radiant energy from a light source travels outwards through space, its amplitude at any distance dl from the source is decreased by the factor 1/dl
2 Energylight = 1
dl
Energylight = 1/dl2
dl’
Energylight = 1/dl’ 2
22
Radial intensity attenuation (2)
• General form to the object about the infinity light source and point light source
2
210
,10.1
ll
radattenl
dadaa
f
if source is at infinity
if source is local
23
Directional light sources and spotlight effects
• A local light source can easily be modified to produce a directional, or spotlight, beam of light. – The unit light-direction vector defines the axis
of a light cone, the angle θl defines the angular extent of the circular cone
θl
Light source
Vlight
Light direction vector
24
spotlight effects
θl
Light source
Cone axis vector
• Denote Vlight in the light-source direction and Vobj in the direction from the light position to an object position
α
To object vertex
Vlight
Vobj
Vobj .Vlight = cos α
00 <θl<= 900
cos α >= cosθl
if Vobj .Vlight < cosθl -> the object is outside the light cone
25
Angular intensity attenuation
• For a directional light source, we can degrade the light intensity angularly about the source as well as radially out from the point-source position. – Light intensity decreasing as we move
farther from the cone axis – Common angular intensity-attenuation
function for a directional light source
la
angattenf cos)( 0
26
Attenuation function
– al (attentuation exponent) is assigned
positive value • (al: the greater value in this function)
– Angle φis measured from the cone axis • Along the cone axis, φ=0o fangatten(φ)=1.0
la
angattenf cos)( 0
27
Combination above different light sources
• To determine the angular attenuation factor along a line from the light position to a surface position in a scene
la
lightobj
radattenlf
)(
0.0
0.1
,
VV
if source is not a spotlight
otherwise
if Vobj .Vlight = cos α < cosθl
28
Surface lighting effects
• Besides light source can light to object, object also can reflect lights – Surfaces that are rough so tend to
scatter the reflected light • when object exist more faces of surface,
more directions can be directed by the reflected light
29
Specular reflection
• Some of the reflected light is concentrated into a highlight called specular reflection – The lighting effect is more outstanding
on shiny surfaces
30
Summary light & surface
• Surface lighting effects are produced by a combination of illumination from light sources and reflections from other surfaces Surface is not directly
exposed to a light source may still be visible due to the reflected light from nearby objects.
The ambient light is the illumination effect produced by the reflected light from various surfaces
31
Homework
• Walking in a scene – Hint: Object
walking or walking above floor
– Example: color cube
demo
void polygon(int a, int b, int c , int d){ glBegin(GL_POLYGON); glColor3fv(colors[a]); glNormal3fv(normals[a]); glVertex3fv(vertices[a]); glColor3fv(colors[b]); glNormal3fv(normals[b]); glVertex3fv(vertices[b]); glColor3fv(colors[c]); glNormal3fv(normals[c]); glVertex3fv(vertices[c]); glColor3fv(colors[d]); glNormal3fv(normals[d]); glVertex3fv(vertices[d]); glEnd(); }