Download - Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

Transcript
Page 1: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

    Texture Mapping

Adapted from slides byRich Riesenfeld

http://www.cs.utah.edu/classes/cs5600/

Page 2: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

2

Texture Mapping

• Maps a pattern (texture) onto a surface• Texels fill each pixel• Texels selected from sample pattern 

(texture map)• Pattern is often repeated

Page 3: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

3

Texture Mapping Characteristics

• Too much detail to model 

geometrically, like grass, etc

• Pattern is repeated (periodic)

Page 4: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

4

Texture Maps

Page 5: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

5

Tiling textures

Page 7: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

7

Examples Examples of Mapped of Mapped TextureTexture

Page 8: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

8

Basic Concept (2D Texture maps)

• Relate a 2D image to a 3D model• Texture coordinates

–2D coordinate (u,v) that corresponds to a location in the texture image

–usually in range [0,1]

Page 9: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

9

Elements of Texture Mapping

• Texture source function (1D, 2D or 3D)• Inverse map: 

 texture location   surface location• Typical texture sources

– Procedure– Tabular data (texture image)

Page 10: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

10

Texture Mapping Techniques

• 2D texture mapping: paint 2D pattern onto the surface

• Environmental (reflection) mapping• Bump mapping: perturb surface 

normals to fool shading algorithms• Procedural texture mapping

Page 11: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

11

Need to Impose Parametrization

(0,0,0) (0,1,0)

(0,0,1)

(1,0,0)

(1,1,1)

h(0, 0)

(0.5, 0)

(0, 0.5)

(1, 1)

(0, 1)

(1, 0)(1, 0.5)

(h,ө)

ө

өø

(0.5, 1)

(0, 0.5)

(ө, 1)

(ө,  0)

(ө, ø)

(1, 0.5)

(x, y, z)

Page 12: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

12

Using a planar projection

Page 13: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

13

More Examples

http://astronomy.swin.edu.au/~pbourke/texture/texturemapping

Texture Mapping, Paul Bourke (1987)

Planar  Cubic  Cylindrical 

Page 14: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

14

Texture Mapped Teapot

Page 15: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

15

Examples

Page 16: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

16

Steps in Texture Mapping (OpenGL)

1. Create a texture object and specify a texture for that object

2. Indicate how the texture is to be applied to each pixel

3. Render the scene, supplying both texture and geometric coordinates

Page 17: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

17

Mapping the 2D Texture to Surface

• The map: 2D texture(s,t)  3D object(x,y,z)

• Mapping onto triangle is not difficult

• Mapping onto triangular mesh is more difficult (have to handle texture discontinuity)

• Mapping onto parametric surface is easier

• Alternative: use an intermediate parametric surface (cylinder, sphere)

Page 18: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

18

Texture Mapping for Meshes

• Assign per­vertex texture coordinate• During rasterization: interpolate 

texture coordinates at each pixel (similar to project 1)

• Lookup texture color via texture coordinate

Page 19: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

19

s

t(1, 1)

(0, 1)

(0, 0) (1, 0)

(s, t) = (0.2, 0.8)

(0.4, 0.2)

(0.8, 0.4)

A

B C

aa

bbcc

Texture Space Object Space

Mapping Texture

••

••••

••••

••

Page 20: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

20

Mapping Texture onto Parametric Surface

• Parametric surface:S(u,v) = (x(u,v), y(u,v), z(u,v))

• Use (u,v) as texture coordinates 

Page 21: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

21

Using an intermediate surface

• Two­step mapping:– Map the texture to a simple intermediate 

surface (sphere, cylinder, cube)– Map the intermediate surface (with the 

texture) onto the surface being rendered

Page 22: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

22

Page 23: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

23

Page 24: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

24

spherical projection, cont'd• starting with point p on the surface• project to point p' on unit sphere:

p' = (p ­ c)/|p – c|• now use (x,y,z) coordinates of p' to 

compute (u,v) coordinates via the natural parameterization of the sphere

Page 25: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

25

spherical projection, cont'd• details of last step explained in project 2

Page 26: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

26

MIP Mapping (multum in parvo)“Many things in a small place”

Page 27: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

27

Mipmapped Textures• Mipmapping:

– prefiltered texture maps 

– decreasing resolutions

– used to combat aliasing

• OpenGL supports mipmapping 

Page 28: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

28

Aliasing

aliasing (left); antialiased (middle, right)(from wikipedia)

Page 29: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

29

Bump Mapping

smooth silhouettes

Page 30: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

30

Bump mapping 

• 2D texture maps don't interact w/ lighting• Bump mapping: use texture map to define 

perturbed surface normals• Compute lighting using perturbed normals

Page 31: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

31

Page 32: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

32

Page 33: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

33

Okino Com

puter Graphics

www.okino.com/slidshow/bowling2.htm

Page 34: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

34

More Examples

Contours indicate equidistance from reference plane

Texture Mapping as a Fundamental Drawing PrimitivePaul Haeberli and Mark Segal(1993) www.sgi.com/misc/grafica/texmap/

Environment Mapping 

Page 35: Texture Mapping - EECS · Steps in Texture Mapping (OpenGL) 1. Create a texture object and specify a texture for that object 2. Indicate how the texture is to be applied to each pixel

35

Projective Texture Mapping