Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Illumination (Lighting)
Shading
Illumination Model
Shading
Illumination Calculation
Illumination Models
object 2
object 1
Example: OpenGL
sun
Point light
Directional light
Ambient
Diffuse
Specular
Spot light
object 4
object 3
object 2
object 1
Diffuse = Kd * I * cos ()
N : surface normal
cos() = N.L
See nothing!
?
p
n = 10
n = 90
n = 30
n = 270
Lighting in OpenGL
IInterpolate
t
l t across surface
f
(G
(Gouraud/smooth
d/
th shading)
h di )
OR
Use a constant illumination (get it from one of the vertices)
Light Properties
Enable/Disable lighting
Surface material properties
Provide correct surface normals
Light model properties
(Illum)
(N.H)
Self emission
Global ambient
Light distance attenuation and spot light effect
Light Properties
Properties:
(1) constant: specify which light you want to set the property
example: GL_LIGHT0, GL_LIGHT1, GL_LIGHT2 you can
create multiple lights (OpenGL allows at least 8 lights)
(2) constant: specify which light property you want to set the value
example: GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_POSITION
(check the red book for more)
Property Example
Types of lights
GLfloat
GLfloat
GLfloat
GLfloat
glLightfv(GL_LIGHT0,
glLightfv(GL_LIGHT0,
glLightfv(GL_LIGHT0,
glLightfv(GL_LIGHT0,
GL_AMBIENT, light_ambient);
GL_DIFFUSE, light_diffuse);
GL_SPECULAR, light_specular);
GL_POSITION, light_position);
colors
Position
glEnable(GL_LIGHTING);
glDisable(GL_LIGHTING);
glEnable(GL_LIGHTn) (n = 0,1,2,)
Eye
y space:
p
the highlight
g g remains in the same
position relative to the eye
http://www.xmission.com/~nate/tutors.html
Material Properties
Material Example
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
mat_amb_diff);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_speacular);
glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
glLightModelfv(property, value)
Enable two sided lighting
Surface Normals
property = GL_LIGHT_MODEL_TWO_SIDE
value = GL_TRUE (GL_FALSE if you dont want two sided
lighting)
glBegin( )
glBegin()
glNormal3f(x,y,z)
glVertex3f(x,y,z)
glEnd()
Property = GL_LIGHT_MODEL_AMBIENT
Value = (red, green, blue, 1.0);
refl. coefficient
Lighting revisit
v1, m1
modeling and
viewing
v2, m2
per vertex
lighting
projection
interpolate
vertex colors
clipping
v3, m3
Rasterization
texturing
shading
viewport
mapping
Display
Flat shading
perceived intensity
Smooth shading
Smooth shading
Flat shading
smooth shading
n1
n3
n2
n4
10
Linear interpolation
Cb = lerp(C1, C3)
C3
Lerp(Ca, Cb)
v2
x = a / (a+b) * v2 + b/(a+b) * v1
C2
v1
C1
Ca = lerp(C1, C2)
11
Phong Shading
Normal interpolation
n1
nb = lerp(n1,
lerp(n1 n3)
na = lerp(n1,
lerp(n1 n2)
lerp(na, nb)
n2
n3
12