To Do

Computer Graphics (Fall 2004) ƒ Work on HW4 milestone

COMS 4160, Lecture 19: ƒ Written Ass 1 http://www.cs.columbia.edu/~cs4160

Many slides from Greg Humphreys, UVA and Rosalee Wolfe, DePaul tutorial teaching texture mapping visually

This Lecture: Texture Mapping Adding Visual Detail

ƒ Important topic: nearly all objects textured ƒ Basic idea: use images instead of more polygons to ƒ Wood grain, faces, bricks and so on represent fine scale color variation ƒ Adds visual detail to scenes ƒ Meant as a fun and practically useful lecture ƒ But not tested specifically on it

Polygonal model With surface texture

Parameterization Option: Varieties of projections

++ =

geometry image texture map

• Q: How do we decide where on the geometry each color from the image should go? [Paul Bourke]

1 Option: unfold the surface Option: make an atlas

[Piponi2000]

charts atlas surface

[Sander2001]

Option: it’s the artist’s problem Outline

ƒ Types of projections ƒ Interpolating texture coordinates ƒ Broader use of textures

How to map object to texture? Idea: Use Map Shape

ƒ To each vertex (x,y,z in object coordinates), must ƒ Map shapes correspond to various projections associate 2D texture coordinates (s,t) ƒ Planar, Cylindrical, Spherical ƒ So texture fits “nicely” over object ƒ First, map (square) texture to basic map shape ƒ Then, map basic map shape to object ƒ Or vice versa: Object to map shape, map shape to square ƒ Usually, this is straightforward ƒ Maps from square to cylinder, plane, sphere well defined ƒ Maps from object to these are simply spherical, cylindrical, cartesian coordinate systems

2 Planar mapping Cylindrical Mapping

ƒ Like projections, drop z coord (s,t) = (x,y) ƒ Cylinder: r, θ, z with (s,t) = (θ/(2π),z) ƒ Note seams when wrapping around (θ = 0 or 2π) ƒ Problems: what happens near z = 0?

Spherical Mapping Cube Mapping

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

Cube Mapping Outline

ƒ Types of projections ƒ Interpolating texture coordinates ƒ Broader use of textures

3 1st idea: Gouraud interp. of texcoords Artifacts

I1221()()yys −+ Iyy −s Ia = yy12− ƒ McMillan’s demo of this is at http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide05.html

I1331()()yys −+ Iyy −s Ia = I1 yy13− ƒ Another example y1 Iab()()xx−+ p Ixx b p − a http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide06.html Ia = xxba− Ia I p Ib Scan line ƒ What artifacts do you see? ys

y2 I2 ƒ Why?

y3 I3 ƒ Why not in standard Gouraud shading? ƒ Hint: problem is in interpolating parameters Actual implementation efficient: difference equations while scan converting

Interpolating Parameters Texture Mapping

ƒ The problem turns out to be fundamental to interpolating parameters in screen- space ƒ Uniform steps in screen space ≠ uniform steps in world space

Linear interpolation Correct interpolation of texture coordinates with perspective divide Hill Figure 8.42

Interpolating Parameters Perspective-Correct Interpolation

ƒ Perspective foreshortening is not getting applied to ƒ Skipping a bit of math to make a long story short… our interpolated parameters ƒ Rather than interpolating u and v directly, interpolate u/z ƒ Parameters should be compressed with distance and v/z ƒ Linearly interpolating them in screen-space doesn’t do this ƒ These do interpolate correctly in screen space ƒ Also need to interpolate z and multiply per-pixel ƒ Problem: we don’t know z anymore ƒ Solution: we do know w ∝ 1/z ƒ So…interpolate uw and vw and w, and compute u = uw/w and v = vw/w for each pixel ƒ This unfortunately involves a divide per pixel ƒ http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide14.html

4 Texture Map Filtering Mip Maps

ƒ Naive texture mapping aliases badly ƒ Keep textures prefiltered at multiple resolutions ƒ For each pixel, linearly interpolate between ƒ Look familiar? two closest levels (e.g., trilinear filtering) int uval = (int) (u * denom + 0.5f); int vval = (int) (v * denom + 0.5f); ƒ Fast, easy for hardware int pix = texture.getPixel(uval, vval); ƒ Actually, each pixel maps to a region in texture ƒ |PIX| < |TEX| ƒ Easy: interpolate (bilinear) between texel values ƒ |PIX| > |TEX| ƒ Hard: average the contribution from multiple texels ƒ |PIX| ~ |TEX| ƒ Still need interpolation!

ƒ Why “Mip” maps?

MIP-map Example Outline

ƒ Types of projections ƒ No filtering: ƒ Interpolating texture coordinates ƒ Broader use of textures

AAAAAAAGH MY EYES ARE BURNING

ƒ MIP-map texturing:

Where are my glasses?

Texture Mapping Applications Modulation textures Map texture values to scale factor ƒ Modulation, light maps ƒ ƒ ƒ Illumination or Environment Mapping Wood texture ƒ Procedural texturing

ƒ And many more Texture value

I = T(s,t)(I + K I + (K (N • L) + K (V • R)n )S I + K I + K I ) E A A ∑L D S L L T T S S

5 Bump Mapping Displacement Mapping

ƒ Texture = change in surface normal!

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

Illumination Maps Environment Maps ƒ Quake introduced illumination maps or light maps to capture lighting effects in video games Texture map:

Light map

Images from Illumination and Reflection Maps: Texture map Simulated Objects in Simulated and Real Environments + light map: Gene Miller and C. Robert Hoffman SIGGRAPH 1984 “Advanced Animation” Course Notes

Solid textures Procedural Texture Gallery Texture values indexed by 3D location (x,y,z) • Expensive storage, or • Compute on the fly, e.g. Perlin noise Æ

6 Where we’re going with course

ƒ All the material for HW 4 is done ƒ We still need unit 5 (3- 4 lectures) ƒ Techniques not used in OpenGL, more advanced ƒ Written ass 2 on this ƒ Other lectures for fun and preview advanced courses ƒ Story of computer graphics movie on Wed ƒ Real-Time rendering next Wed ƒ Preview of COMS 4162 (advanced graphics) later

7