57
1 Texture Mapping

1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

Embed Size (px)

Citation preview

Page 1: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

1

Texture Mapping

Page 2: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

2

Texture Mapping Texture Mapping Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

Page 3: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

3

The Limits of Geometric Modeling

Although graphics cards can render over 10 million polygons per second, that number is insufficient for many phenomena Clouds Grass Terrain Skin

Page 4: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

4

Modeling an Orange – 1/2 Consider the problem of modeling an orange

(the fruit) Start with an orange-colored sphere

Too simple Replace sphere with a more complex shape

Does not capture surface characteristics (small dimples)

Takes too many polygons to model all the dimples

Page 5: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

5

Modeling an Orange – 2/2 Take a picture of a real orange, scan it, and

“paste” onto simple geometric model This process is texture mapping

Still might not be sufficient because resulting surface will be smooth Need to change local shape Bump mapping

Page 6: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

6

The Quest for Visual Realism

Page 7: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

7

Three Types of Mapping Texture Mapping

Uses images to fill inside of polygons Environmental (reflection mapping)

Uses a picture of the environment for texture maps

Allows simulation of highly specular surfaces Bump mapping

Emulates altering normal vectors during the rendering process

Page 8: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

8

Texture Mapping

geometric model texture mapped

Page 9: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

9

Decal Textures

Page 10: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

10

Bump Mapping

Page 11: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

11

Where does Mapping take place? Mapping techniques are implemented at the end

of the rendering pipeline Very efficient because few polygons pass

down the geometric pipeline

Page 12: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

12

Simple Texture Mapping

s

t

x

y

z

image

geometry screen

Page 13: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

13

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

Page 14: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

14

Coordinate Systems Parametric coordinates

May be used to model curved surfaces Texture coordinates

Used to identify points in the image to be mapped World Coordinates

Conceptually, where the mapping takes place Screen Coordinates

Where the final image is really produced

Page 15: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

15

Texture Mapping

parametric coordinates

texture coordinatesworld coordinates

screen coordinates

Page 16: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

16

Texture Mapping = Pattern Mapping

Page 17: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

17

Mapping Functions Basic problem is how to find the maps Consider mapping from texture coordinates to

a point a surface Appear to need three functions

x = x(s,t)

y = y(s,t)

z = z(s,t) But we really want

to go the other way

s

t

(x,y,z)

Page 18: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

18

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 correspondsNeed a map of the form

s = s(x,y,z)

t = t(x,y,z) Such functions are difficult to find in general

Page 19: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

19

Sample Mapping – 1/2 In next topic, we will study parametric surf

aces Assume we want to map a point in the text

ure map T(s, t) to a point on the surface p(u, v) by a linear map of the form:u=as + bt + cv=ds + et + fas long as aebd, this mapping is invertible

Page 20: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

20

Sample Mapping – 2/2

)(

),(

minmaxminmax

minmin

minmaxminmax

minmin

vvtt

ttvv

uuss

ssuu

Page 21: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

21

Mapping a Texture Based on parametric texture coordinates

s

t1, 1

0, 1

0, 0 1, 0

(s, t) = (0.2, 0.8)

(0.4, 0.2)

(0.8, 0.4)

A

B C

a

bc

Texture Space Object Space

Page 22: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

22

Two-part Mapping One solution to the mapping problem is to

first map the texture to a simple intermediate surface

Example: map to cylinder

Page 23: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

23

Cylindrical Mapping

parametric cylinder

x = r cos 2 uy = r sin 2uz = v/h

maps rectangle in u,v space to cylinderof radius r and height h in world coordinates

s = ut = v

maps from texture space

Page 24: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

24

Spherical MappingWe can use a parametric sphere

x = r cos 2uy = r sin 2u cos 2vz = r sin 2u sin 2v

in a similar manner to the cylinderbut have to decide where to putthe distortion

Spheres are use in environmental maps

Page 25: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

25

Box Mapping Easy to use with simple orthographic

projection Also used in environmental maps

Page 26: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

26

Second Mapping Map from intermediate object to actual object

Normals from intermediate to actual Normals from actual to intermediate Vectors from center of intermediate

intermediateactual

What if a ray is blocked?

Page 27: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

27

Texture Example

The texture (below) is a 256 x 256 image that has been mapped to a rectangular polygon which is viewed in perspective mode

Page 28: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

28

Linear Interpolation of Textures

Page 29: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

29

Texture Mapping & Polygon Rasterization

Problems of linearly interpolatingtexture coordinates in screen space. Similar problems in the interpolations of

colors for Gouraud shading and normalsfor Phong shading.

Problems in antialiasing Expanding and shrinking

Page 30: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

30

Example

Page 31: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

31

Perspective Correction Dividing the texture coordinates by w Linearly interpolating (u/w, v/w, 1/w) At each pixel, dividing (interpolated)

u/w and v/w by (interpolated) 1/w

Page 32: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

32

Aliasing Point sampling of the texture can lead to ali

asing errors

point samples in u,v (or x,y,z) space

point samples in texture space

miss blue stripes

Page 33: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

33

Area AveragingA better but slower option is to use area averaging

Note that preimage of pixel is curved

pixelpreimage

Page 34: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

34

Sampling Texture Maps

Page 35: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

35

Over-Sampling indicative of aliasing high-frequency details showing up in areas

where we expect to see low frequencies

Page 36: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

36

Spatial Filtering Prefilter the texture to remove the high fre

quencies that show up as artifacts

Page 37: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

37

Mip Mapping MIP Mapping is one popular technique for precom

puting and performing this prefiltering Computing this series of filtered images requires o

nly a small fraction of additional storage over the original texture

Page 38: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

38

Magnification and MinificationMore than one texel can cover a pixel (minification) ormore than one pixel can cover a texel (magnification)

Can use point sampling (nearest texel) or linear filtering( 2 x 2 filter) to obtain texture values

Texture Polygon

Magnification Minification

PolygonTexture

Page 39: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

39

Examples pointsampling

mipmapped pointsampling

mipmapped linear filtering

linear filtering

Page 40: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

40

Environment Mapping

Page 41: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

41

Sphere Mapping

Page 42: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

42

Box Mapping

Page 43: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

43

Bump Mapping

Page 44: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

44

Bump Mapping

Page 45: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

45

Bump Mapping

Page 46: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

46

Displacement Mapping

Page 47: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

47

Bump Mapping versus Displacement Mapping

Page 48: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

48

Texture Mapping in Quake

Page 49: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

49

Shadow Maps

Page 50: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

50

Basic Steps of Shadow Maps Render the scene from the light’s point of view, Use the light’s depth buffer as a texture (shadow map), Projectively texture the shadow map onto the scene, Use “texture color” (comparison result) in fragment shading.

Page 51: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

51

Three Dimensional or Solid Textures

Page 52: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

52

Tri-linear Interpolation

Page 53: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

53

Line Aliasing Ideal raster line is one pixel wide All line segments, other than vertical and h

orizontal segments, partially cover pixels Simple algorithms color

only whole pixels Lead to the “jaggies”

or aliasing Similar issue for polygons

Page 54: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

54

Antialiasing Can try to color a pixel by adding a fraction of its

color to the frame buffer Fraction depends on percentage of pixel

covered by fragment Fraction depends on whether there is overlap

no overlap overlap

Page 55: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

55

Area Averaging Use average area 1+2-12 as blending factor

Page 56: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

56

Image Filtering

m

mk

n

nlljkiklij

ij

ahb

aA

,

][

H: Filter(convolution) matrix of (2m+1)×(2n+1)

010

111

010

5

1H

Examples:

121

242

121

16

1H

010

151

010

H

Page 57: 1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing

57

Motion Blur Jitter an object and render it multiple times, leaving

the positions of the other objects unchanged, we get dimmer copies of the jittered object

If the object is moved along a path, rather then randomly jittered, we see the trail of the object motion blur