So Far - Nottinghampszqiu/Teaching/Courses/G5BAGR/Slides/10-texture.pdf1 So Far o We have assumed...

9
1 So Far o We have assumed that we know: o The point o The surface normal o The viewer location (or direction) o The light location (or direction) o But commonly, normal vectors are only given at the vertices and it is expensive to compute lighting for every point o Objects rendered using Phong reflection model and Gouraud or Phong interpolated shading often appear rather ‘plastic’ and ‘floating in air’ o Breaking the scene into smaller and smaller polygonal objects increases the detail BUT it is very hard to model and very time- consuming to render Texture Mapping o Texture effects can be added to give more realistic looking surface appearance o Texture mapping associates the color of a point with the color in a texture image - a 2D image is ‘painted’ onto the object Parameterization geometry geometry + + = image image texture map texture map Q: How do we decide where on the geometry each color from the image should go? Option: Varieties of projections [Paul Bourke] [Paul Bourke]

Transcript of So Far - Nottinghampszqiu/Teaching/Courses/G5BAGR/Slides/10-texture.pdf1 So Far o We have assumed...

Page 1: So Far - Nottinghampszqiu/Teaching/Courses/G5BAGR/Slides/10-texture.pdf1 So Far o We have assumed that we know: o The point o The surface normal o The viewer location (or direction)

1

So Far

o We have assumed that we know:o The pointo The surface normalo The viewer location (or direction)o The light location (or direction)

o But commonly, normal vectors are only given at the vertices and it is expensive to compute lighting for every point

o Objects rendered using Phong reflection model and Gouraud or Phonginterpolated shading often appear rather ‘plastic’ and ‘floating in air’

o Breaking the scene into smaller and smaller polygonal objects increases the detail BUT it is very hard to model and very time-consuming to render

Texture Mapping

o Texture effects can be added to give more realistic looking surface appearance

o Texture mapping associates the color of a point with the color in a texture image - a 2D image is ‘painted’ onto the object

Parameterization

geometrygeometry

++ ==

imageimage texture maptexture map

• Q: How do we decide where on the geometryeach color from the image should go?

Option: Varieties of projections

[Paul Bourke][Paul Bourke]

Page 2: So Far - Nottinghampszqiu/Teaching/Courses/G5BAGR/Slides/10-texture.pdf1 So Far o We have assumed that we know: o The point o The surface normal o The viewer location (or direction)

2

Option: unfold the surface

[Piponi2000]

How to map object to texture?

o To each vertex (x,y,z in object coordinates), must associate 2D texture coordinates (s,t)

o So texture fits “nicely” over object

Idea: Use Map Shape

o Map shapes correspond to various projectionso Planar, Cylindrical, Spherical

o First, map (square) texture to basic map shapeo Then, map basic map shape to object

o Or vice versa: Object to map shape, map shape to square

o Usually, this is straightforwardo Maps from square to cylinder, plane, sphere well definedo Maps from object to these are simply spherical, cylindrical,

cartesian coordinate systems

Planar mapping

o Like projections, drop z coord (s,t) = (x,y)o Problems: what happens near z = 0?

Page 3: So Far - Nottinghampszqiu/Teaching/Courses/G5BAGR/Slides/10-texture.pdf1 So Far o We have assumed that we know: o The point o The surface normal o The viewer location (or direction)

3

Cylindrical Mapping

o Cylinder: r, θ, z with (s,t) = (θ/(2π),z)o Note seams when wrapping around (θ = 0 or 2π)

Spherical Mapping

o Convert to spherical coordinates: use latitude/long.o Singularities at north and south poles

Cube Mapping Cube Mapping

Page 4: So Far - Nottinghampszqiu/Teaching/Courses/G5BAGR/Slides/10-texture.pdf1 So Far o We have assumed that we know: o The point o The surface normal o The viewer location (or direction)

4

Texture Mapping

o Main Issues

o How do we map between 3D

o How does the texture modify the shading of pixels?

o How do we sample the texture for a fragment?

Texture Mapping

o Interpolation Texture Mapping (painting)

o We need to define a mapping between the 3D world space (x,y,z) and 2D image space (s,t)∈ [0,1]2

o Texture coordinates defined at vertices serve this purpose

o Specify (s,t) at each vertex:

V0

V1

V2

u

v

Texture Mapping

o Interpolate in the interior:

V0

V1

V2

Mapping the object on the left to the texture on the rightu

v

Texture Mapping

o Interpolate in the interior:

V2(10,10)

Consider the y value of 3 in the interpolation across the triangle.

The rendering process determines that the range of object coordinates are from (3, 3) to (20, 3).

The first co-ordinate comes from the interpolation along the left edge of thetriangle at a parametric value t = 0.3.

V0(0,0)

V1(20, 3)

(3, 3)

(0, 0)

(50, 50)

(100, 15)

u

v

Page 5: So Far - Nottinghampszqiu/Teaching/Courses/G5BAGR/Slides/10-texture.pdf1 So Far o We have assumed that we know: o The point o The surface normal o The viewer location (or direction)

5

Texture Mapping

o Interpolate in the interior:

V2(10,10)

The texture location for this left edge location is (15, 15). Why?

Object locations are interpolated from (3, 3) to (20, 3)

Texture locations are interpolated from (15, 15) to (100, 15)

V0(0,0)

V1(20, 3)

(3, 3)

(0, 0)

(50, 50)

(100, 15)(15, 15)

u

v

Texture Mapping

o Interpolate in the interior:

V2(10,10)

The texture gives a value that will influence the shading process. Specifically, the value from the texture replaces the diffuse constant in the calculation of the diffusion component in the illumination equation. By doing so, the texture values change the object appearance, but shape cues that come from the specular highlights will stay the same.

V0(0,0)

V1(20, 3)

(3, 3)

(0, 0)

(50, 50)

(100, 15)(15, 15)

u

v

Texture Mapping

o Interpolate in the interior:

V2(10,10)

V0(0,0)

V1(20, 3)

(3, 3)

(0, 0)

(50, 50)

(100, 15)(15, 15)

x

y

( ) ( )

( ) ( )

( ) ( )kr

VRIKNLIvuTextureIKI

krVRIKNLIvuTexture

IKI

krVRIKNLIvuTextureIKI

nisidb

aabb

nisidg

aagg

nisidr

aarr

+•+•

+=

+•+•

+=

+•+•

+=

),(

),(

),(

(u, v)(x, y)

u

v

Texture Mapping

o Interpolate in the interior:

V2(10,10)

V0(0,0)

V1(20, 3)

(3, 3)

(0, 0)

(50, 50)

(100, 15)(15, 15)

x

y(u, v)(x, y)

A texture location can be calculated from object location directly. In general, mapping an object with x coordinates in the range from xmin to xmax and y coordinates in the range ymin to ymax into the texture coordinate range can be computed as:

umin , umax , vmin , vmax are determined by the range of texture values assigned to the object vertices.

( ) ( )minminmax

minmaxmin

minmax

minmax yyyyvvvxx

xxuuu −

−−

=−−−

=

u

v

Page 6: So Far - Nottinghampszqiu/Teaching/Courses/G5BAGR/Slides/10-texture.pdf1 So Far o We have assumed that we know: o The point o The surface normal o The viewer location (or direction)

6

Texture Mapping

o Interpolate in the interior: - Painted texture

o Simple

o But can have problems – especially for highly irregular surfaces

Artifacts

o McMillan’s demo of this is at http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide05.html

o Another examplehttp://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide06.html

o What artifacts do you see?o Why?o Why not in standard Gouraud shading?o Hint: problem is in interpolating parameters

Interpolating Parameters

o The problem turns out to be fundamental to interpolating parameters in screen-space

o Uniform steps in screen space ≠ uniform steps in world space

Texture Mapping

Linear interpolationof texture coordinates

Correct interpolationwith perspective divide

Hill Figure 8.42

Page 7: So Far - Nottinghampszqiu/Teaching/Courses/G5BAGR/Slides/10-texture.pdf1 So Far o We have assumed that we know: o The point o The surface normal o The viewer location (or direction)

7

Interpolating Parameters

o Perspective foreshortening is not getting applied to our interpolated parameterso Parameters should be compressed with distanceo Linearly interpolating them in screen-space doesn’t do this

Perspective-Correct Interpolation

o Skipping a bit of math to make a long story short…o Rather than interpolating u and v directly, interpolate u/z and

v/zo These do interpolate correctly in screen spaceo Also need to interpolate z and multiply per-pixel

o Problem: we don’t know z anymoreo Solution: we do know w ∝ 1/zo So…interpolate uw and vw and w, and compute

u = uw/w and v = vw/w for each pixelo This unfortunately involves a divide per pixel

o http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide14.html

Texture Map Filtering

o Naive texture mapping aliases badly

o Filtering

Moire pattern

Mapping to Curved Surfaces

s

t

x

y

z

Xs

Ys

Parametric surfacex=x(u,v)y=y(u,v)z=z(u,v)

A pixelA curvedimage

The task is to map textureto surface, or to find a mappingu=as+bt+cv=ds+et+f

Page 8: So Far - Nottinghampszqiu/Teaching/Courses/G5BAGR/Slides/10-texture.pdf1 So Far o We have assumed that we know: o The point o The surface normal o The viewer location (or direction)

8

Bump Mapping

o This is another texturing techniqueo Aims to simulate a dimpled or wrinkled surface

o for example, surface of an orangeo Like Gouraud and Phong shading, it is a trick

o surface stays the sameo but the true normal is perturbed, to give the

illusion of surface ‘bumps’

How Does It Work?

o Looking at it in 1D: o Original surface P(u)

o Bump map b(u)

o Add b(u) to P(u)in surface normal direction, N(u)

o New surface normal N’(u) for reflection model

Bump Mapping Example

Bump map Result

Bump Mapping Example

o Texture = change in surface normal!

Sphere w/ diffuse texture Swirly bump map Sphere w/ diffuse textureand swirly bump map

Page 9: So Far - Nottinghampszqiu/Teaching/Courses/G5BAGR/Slides/10-texture.pdf1 So Far o We have assumed that we know: o The point o The surface normal o The viewer location (or direction)

9

Illumination Maps

o Quake introduced illumination maps or light maps to capture lighting effects in video games

Texture map:

Texture map+ light map:

Light map

Environment Maps

Images from Illumination and Reflection Maps: Simulated Objects in Simulated and Real Environments

Gene Miller and C. Robert HoffmanSIGGRAPH 1984 “Advanced Computer Graphics Animation” Course Notes