phong_shader_and_texture_mapping
phong_shader_and_texture_mapping
Texture Mapping
10 March 2009
CMPT370
Dr. Sean Ho
Trinity Western University
What's on for today
Shading polygons
● Flat shading
● Gouraud shading
● Phong shading
Texture mapping
● Coordinate transforms
● Cylinder, sphere, cube maps
● Bump mapping
● Environment mapping
Texture map:
● Paste an image onto a surface
Bump map:
● Perturbs normal vectors in lighting model to
simulate small changes in surface orientation
Environment (reflection) map:
● Use a picture of the surrounding room/sky for
a texture map
● Simulates reflections in very specular surfaces
Only texture maps are built-in to OpenGL
● World coords
(x,y,z)
● Window coords
(xs, yt)
Parametric cylinder:
x = r cos(2πs)
y = r sin(2πs)
z = t/h
Map from
● Square [0,1] x [0,1] in (s,t) texture space to
● Cylinder of radius r, height h
in (x,y,z) world coordinates
Parametric sphere:
x = r cos(2πs)
y = r sin(2πs) cos(2πt)
z = r sin(2πs) sin(2πt)
● Bad distortions at the poles
Cube/box mapping:
● Easy with
orthographic projection
Parameterized surface:
p(u,v) = (x(u,v), y(u,v), z(u,v))
● Tangent vectors: pu = ∂p/∂u, pv = ∂p/∂v
● Normal vector: n = pu x pv
Perturbed surface: p'(u,v) = p(u,v) + d(u,v) n(u,v)
● d(u,v) is the displacement function/map
Perturbed normal: n' = p'u x p'v
2a
2b