1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science Laboratory University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Texture Mapping Ed Angel Professor Emeritus of Computer Science University of New Mexico 2 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
3 Objectives Basic mapping strategies Forward vs backward mapping Point sampling vs area averaging Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
4 Is it simple? Although the idea is simple---map an image to a surface---there are 3 or 4 coordinate systems involved 2D image 3D surface Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
5 Coordinate Systems Parametric coordinates May be used to model curves and surfaces Texture coordinates Used to identify points in the image to be mapped Object or World Coordinates Conceptually, where the mapping takes place Window Coordinates Where the final image is really produced Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
6 Texture Mapping parametric coordinates texture coordinates world coordinates window coordinates Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
7 Mapping Functions Basic problem is how to find the maps Consider mapping from texture coordinates to a point on a surface Appear to need three functions x = f 1 (s,t) y = f 2 (s,t) z = f 3 (s,t) But we really want to go the other way s t (x,y,z) Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
8 Backward Mapping We really want to go backwards Given a pixel, we want to know to which point on an object it corresponds Given a point on an object, we want to know to which point in the texture it corresponds Need a map of the form s = g 1 (x,y,z) t = g 2 (x,y,z) Such functions are difficult to find in general Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
9 Backward Mapping Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 We can associate texture coordinates manually (see next presentation) sometimes it is simple, sometimes not Or we can use mapping functions.
10 Two-part mapping One solution to the mapping problem is to first map the texture to a simple intermediate surface First step: map to a known object Example : map to cylinder Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
11 Second Mapping Second step: map from intermediate object to actual object Normals from intermediate to actual Normals from actual to intermediate Vectors from center of intermediate intermediate actual Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
12 Cylindrical Mapping Parametric equations of a cylinder : x = r cos (2 u) y = r sin (2 u) z = v/h They map a rectangle in u,v space to a cylinder of radius r and height h in world coordinates Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley ≤ u ≤ 1 0 ≤ v ≤ 1 If we set : u = s v = t We can then map from texture space. Draw some points on cylinder…
13 Spherical Map We can use a parametric sphere x = r cos (2 u) y = r sin (2 u) cos (2 v) z = r sin (2 u) sin (2 v) in a similar manner to the cylinder but have to decide where to put the distortion Spheres are used in environmental maps Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley ≤ u ≤ 1 0 ≤ v ≤ 1 Draw some points on sphere…
14 Box Mapping Easy to use with simple orthographic projection Also used in environment maps Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Box Mapping Example Geri’s game 1997 (Pixar)Geri’s game Pixar History : 15 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Box mapping (for Geri’s glass) 16 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Notes The character ressembles actor Jonathan Harris (Lost in space)Jonathan Harris Geri can also be seen in Toy Story 2 Animators often put « secret » references in their work : 17 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Pixar debut: Luxo Jr (1986) Luxo jr: 1986 History : Why choose a desk lamp ? A simple object on the animator’s desk… First time, shades are computed using « shaders »… 18 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Another Application of Box Mapping: Reflection Reflection mapping using a box: Good diagram in Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
20 Aliasing Point sampling of the texture can lead to aliasing errors point samples in u,v (or x,y,z) space point samples in texture space miss blue stripes Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
21 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
22 Area Averaging A better but slower option is to use area averaging Note that preimage of pixel is curved pixel preimage Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
23 Area Averaging Filtering methods: /AntiAliasingMenu.html ngUndersampling.en.html (click on next slides…) Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015