computer graphics inf4/msc computer graphics lecture 11 texture mapping

44
Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Upload: dorthy-kennedy

Post on 23-Dec-2015

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Computer Graphics

Lecture 11

Texture Mapping

Page 2: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

The Problem:

• We don't want to represent all this detail with geometry

Page 3: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

3

Computer Graphics Inf4/MSc

Today

• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,

• Common texture coordinates mapping

• Bump mapping

• Environment mapping

Page 4: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

4

Computer Graphics Inf4/MSc

Texture mapping.

• Method of improving surface appearance by adding details on surface.

Page 5: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

5

Computer Graphics Inf4/MSc

Texture mapping.

• Image is ‘pasted’ onto a polygon.• Image is called a Texture map, it’s pixels are often

referred as a Texels and have coordinates (u,v)• Texture coordinates are defined for each vertex of

the polygon and interpolated across the polygon.

v

u

v

u

y

x

Page 6: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Photo-textures

Page 7: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

7

Computer Graphics Inf4/MSc Finding the texture coords of

arbitrary pixels inside the triangle

y

• Use the barycentric coordinates explained in Lecture 9

Page 8: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Texture Interpolation• Specify a texture coordinate (u,v) at each vertex• Can we just linearly interpolate the values in screen

space?

(0,0) (1,0)

(0,1)

Page 9: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc Interpolation - What Goes

Wrong?

texture source what we get| what we want

• Linear interpolation in screen space:

Page 10: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Why does it happen?

• Uniform steps on the image plane does not correspond to uniform steps along the edge

Page 11: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

• Use a rectangular mesh instead of a triangular mesh or

• Increase the number of polygons

How do we deal with it?

Page 12: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

12

Computer Graphics Inf4/MSc

Today

• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,

• Common texture coordinates mapping

• Bump mapping

• Environment mapping

Page 13: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

13

Computer Graphics Inf4/MSc

Aliasing

• Happens when – The camera is zoomed too much into the textured

surface (magnification)– Several texels covering a pixel’s cell (minification)

Page 14: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

14

Computer Graphics Inf4/MSc

Texture Magnification

• Zooming into a surface with a texture• Methods to determine the color of each pixel

– Nearest neighbour – Bilinear interpolation

Page 15: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

15

Computer Graphics Inf4/MSc

Texture Minification • Multiple textures in a single pixel• Solution:

– Nearest neighbour (using the color at the center of the pixel)– Bilinear blending – Mipmapping

Page 16: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Nyquist Limit

• The texture frequency (ft) should be no greater than half the sample frequency (fs)

• ft <= 0.5 fs• Say it is a 2x2 texture :

– Wavelength 2 texels wide– Frequency ft = 1 / 2 – 1 / 2 x 2 <= fs , i.e., – To properly display this texture on a screen, the

frequency must then be at least 2x 1/2, i.e., at least one pixel per texel

Page 17: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

17

Computer Graphics Inf4/MSc

MIP mapMultum In Parvo = Many things in a small place

Produce a texture of multiple resolutionsUse the resolution according to the number of texels in one pixel

Page 18: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

18

Computer Graphics Inf4/MSc

Today

• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,

• Common texture coordinates mapping

• Bump mapping

• Environment mapping

Page 19: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc Common Texture Coordinate

Mappings

• Orthogonal• Cylindrical• Spherical • Perspective

Projection• Texture

Chart

Page 20: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Demo movie

Page 21: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Texture Mapping & Illumination

• Texture mapping can be used to alter some or all of the constants in the illumination equation: – pixel color, diffuse color, alter the normal, ….

Phong’s Illumination Model

Constant Diffuse Color Diffuse Texture Color Texture used as Label Texture used as Diffuse Color

Page 22: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

22

Computer Graphics Inf4/MSc

Today

• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,

• Common texture coordinates mapping

• Bump mapping

• Environment mapping

Page 23: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

What's Missing?• What's the difference between a real

brick wall and a photograph of the wall texture-mapped onto a plane?

• What happens if we change the lighting or the camera position?

Page 24: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Bump Mapping• Use textures to alter the surface normal

– Does not change the actual shape of the surface– Just shaded as if it were a different shape

Sphere w/Diffuse Texture Swirly Bump Map Sphere w/Diffuse Texture & Bump Map

Page 25: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Bump Mapping

• Treat the texture as a single-valued height function• Compute the normal from the partial derivatives in

the texture

Page 26: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Another Bump Map Example

Cylinder w/Diffuse Texture Map

Bump Map

Cylinder w/Texture Map & Bump Map

Page 27: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

What's Missing?

• There are no bumps on the silhouette of a bump-mapped object

Page 28: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Displacement Mapping

• Use the texture map to actually move the surface point

• The geometry must be displaced before visibility is determined

Page 29: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

29

Computer Graphics Inf4/MSc

Today

• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,

• Common texture coordinates mapping

• Bump mapping

• Environment mapping

Page 30: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Environment Maps

• We can simulate reflections by using the direction of the reflected ray to index a spherical texture map at "infinity".

• Assumes that all reflected rays begin from the same point.

Page 31: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Example

Page 32: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Environment Mapping Example

Terminator II

Page 33: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc Cubic Mapping

• The map resides on the surfaces of a cube around the object– align the faces of the cube with the

coordinate axes

• To generate the map:• Using methods such as ray tracing

– Or, take 6 photos of a real environment with a camera in the object’s position : much easier

Page 34: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Calculating the reflection vector

• Normal vector of the surface : N• Incident Ray : I• Reflection Ray: R

R = I -2 N ( N . I )

• The texture coordinate is based on the reflection vector

• Assuming the origin of the vector is always in the center of the cube environment map

Page 35: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Indexing Cubic Maps• Assume you have R and the cube’s faces

are aligned with the coordinate axes, and have texture coordinates in [0,1]x[0,1]– How do you decide which face to use?

• The reflection vector coordinate with the largest magnitude

• (0.8, 0.3, 0.2) face in +x direction

– How do you decide which texture coordinates to use?

• Divide by the coordinate with the largest magnitude

• Remapped to a value between 0 and 1.

(0.8,0.3,0.2) ((0.3/0.8 +1)*0.5, ((0.2/0.8 +1)*0.5) = (0.6875, 0.625)

Page 36: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

A Sphere Map

Page 37: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Sphere Mapping• To generate the map:

– Take a photograph of a shiny sphere – For synthetic scenes, you can use ray tracing, or

warping a cubic environment map

Page 38: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Indexing Sphere Maps• Given the reflection vector R

• (s,t) on the spherical map

• Problems:– Highly non-uniform sampling

– Highly non-linear mapping

21

222 12

2

1 ,

2

1

zyx

yx

RRRm

m

Rt

m

Rs

Page 39: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Non-linear Mapping

• Linear interpolation of texture coordinates picks up the wrong texture pixels– Use small polygons!

Correct Linear

Page 40: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Example

Page 41: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Refractive Environment Mapping

• When simulating effects mapping the refracted environment onto translucent materials such as ice or glass, we must use Refractive Environment Mapping

Page 42: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

Computer Graphics Inf4/MSc

Snell’s Law

• When light passes through a boundary between two materials of different density (air and water, for example), the light’s direction changes.

• The direction follows Snell’s Law

• We can do environment mapping using the refracted vector T

Page 43: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

43

Computer Graphics Inf4/MSc

Summary

• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,

• Common texture coordinates mapping

• Bump mapping

• Environment mapping

Page 44: Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping

44

Computer Graphics Inf4/MSc Assignment

• Rendering a head / teapot

• You may use the 3D rendering function of OpenGL, but better marks are given if you do the illumination by yourself

• Extra marks given for – Textures,

– Environment mapping,

– Shadows, mirrors (extra objects)

– Global illumination (ray tracing, etc)

– Make sure the program runs on DICE