Chapter 05 Computer Graphics
Chapter 05 Computer Graphics
"#$%&'()*
+,-"%,.-(#./(0"#/,.-
Instructor
LE Thanh Sach, Ph.D
!"#$%&$
vShading I
vShading II
vShading in OpenGL
vBut we want
vLight strikes A
@Some scattered
@Some absorbed
vSome of scattered light strikes B
@Some scattered
@Some absorbed
vSome of this scattered
light strikes A
and so on
Computer Graphics: Chapter 05 – Lighting and Shading Slide: 9
!"#$"%&#'()*+,-&.#
multiple reflection
translucent surface
vLook right:
Bui Tuong Phong (Phong Model):
vPoint source
@Model with position and color
@Distant source = infinite distance away
(parallel)
vSpotlight
@Restrict light from ideal point source
vAmbient light
@Same amount of light everywhere in scene
@Can model contribution of many sources and
reflecting surfaces
Computer Graphics: Chapter 05 – Lighting and Shading Slide: 16
!"#$%&'()*+',
smooth surface
rough surface
Computer Graphics: Chapter 05 – Lighting and Shading Slide: 17
!"#$%&'#()*
r = 2 (l · n ) n - l
specular
highlight
shininess coef f
reflected
intensity
incoming intensity
absorption coef
Computer Graphics: Chapter 05 – Lighting and Shading Slide: 22
!"#$%"&'&'#(($)*#++&,&#'-
-90 f 90
Computer Graphics: Chapter 05 – Lighting and Shading Slide: 23
!"#$%&'())
I =kd Id l · n + ks Is (v · r )a + ka Ia
ê !! !! b b ú
êë I b úû a
êë kd I d max(l.n, 0) + k s I s (max(r.v, 0)) + ka I a úû
b b b b
Where:
é kdr k s
r
k ù
r
a
ê g g gú - are materials’ properties
ê kd k s k ú
a
- In Opengl: specified by glMaterialfv(.)
ê kdb k b
k úû
b
ë s a
ê !! !! b b ú
êë I b úû a
êë kd I d max(l.n, 0) + k s I s (max(r.v, 0)) + ka I a úû
b b b b
Where:
é I dr I s
r
I ù
r
a
ê g g gú - are light intensities
êId I s I ú
a
- In Opengl: specified by glLightfv(.)
ê I db I b
I úû
b
ë s a
vReplace (v · r )a by (n · h )b
v b is chosen to match shininess
v Resulting model is known as the modified
Phong or Blinn lighting model
@Specified in OpenGL standard
ê !! !! b b ú
êë I b úû a
êë kd I d max(l.n, 0) + k s I s (max(h.n, 0)) + ka I a úû
b b b b
Where:
! !
! l +v
h= ! ! is half vector
|l +v|
Computer Graphics: Chapter 05 – Lighting and Shading Slide: 36
!"#$%&'
Only differences in
these teapots are
the parameters
in the modified
Phong model
vFor sphere
x=x(u,v)=cos u sin v
y=y(u,v)=cos u cos v
z= z(u,v)=sin u
v Tangent plane determined by vectors
∂p/∂u = [∂x/∂u, ∂y/∂u, ∂z/∂u]T
∂p/∂v = [∂x/∂v, ∂y/∂v, ∂z/∂v]T
n = (p2 - p0 ) ×(p1 - p0 )
p
normalize n ¬ n/ |n| p0 p
1
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightv(GL_LIGHT0, GL_POSITION, light0_pos);
glLightv(GL_LIGHT0, GL_AMBIENT, ambient0);
glLightv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
glLightv(GL_LIGHT0, GL_SPECULAR, specular0);
-q f q
vGouraud Shading
@Find average normal at each vertex (vertex
normals)
@Apply modified Phong model at each vertex
@Interpolate vertex shades across each polygon
vPhong shading
@Find vertex normals
@Interpolate vertex normals across edges
@Interpolate edge normals across polygon
@Apply modified Phong model at each fragment