Texture Mapping

David S. Ebert

September 2000

• Applicable to all shading attributes
• color
• specularity
• reflections
• normals
• refraction
• transparency
• Main problem: How to map 2D texture onto 3D object

4 Choices:
1. Interpolated texture coordinates in screen space

has perspective distortion problems

2. Map in object/world space

we will look at in detail

3. Use projection function (e.g., spherical mapping)

simple, special cases work OK, others don't

4. 2-part texture mapping -- Bier (divide and conquer)

more complicated, used somewhat.

Map in object space

Correction:

P0v = P00 + v (P01 - P00)

P1v = P10 + v (P11 - P10)

Puv = P0v + u (P1v - P0v)

Puv = {P00 + v (P01 - P00)} + u{ (P10 + v (P11 - P01)) - (P00 + v (P10 - P00))}

...

solve for u and v.

In general case, add Pij's u,v coordinates into equation.

Before do this,

• undo viewport map (xi, yi, zi)
• undo perspective and normalizing transform (object -- world)
• perspective project points

Now what do you do ?

• take closest point -- alias prone
• bilinear interpolate 4 closest values -- solve some problems
• map pixel corners back and filter projected area

Solution: Antialiased texture mapping

• mip mapping [Lance Williams 83] (square filter)
• Store texture map at multiple resolutions (power of 2)
Each one integrated (square filter) on higher resolution table
(e.g., 512x512, 256x256, 128x128, 64x64, 32x32, 16x16, 8x8, 4x4, 2x2,1x1)
• Interpolate between value from map i and map i-1
• How do you choose map i ?

Use square root of texture area subtended by pixel

• simple method is to map back (x+1/2, y+1/2), (x-1/2, y-1/2)
• d = sqrt(UVarea);
• choose i such that d < (1 / (i res)) and d > (1 / (i-1) res)
• now average the u and v values of the 4 pixel corners to get [u][v] (or do this procedure for each of the pixel corners).
• then get value of texture[i][u][v] and texture[i-1][u][v] and linearly interpolate them.
• To calculate texture[i][u][v] and texture[i-1][u][v] bilinearly interpolate the texture map.

• Williams used pyramid storage

• Example Mip-maps

• Summed Area Tables -- precalculated single table
• each point is the sum of texture value at that point plus the sum of intensities at lower left hand corners.

• less storage
• handles rectangular filters

• Disadvantages: - Why doesn't anybody use it?
• Can you do it with 8 bits per entry?
• Since uses rectangular filter, still not good for edge on viewing
• Must use rectangular filter

Object Space vs. World Space for Mapping

• In world space, object will move through the texture. -- The texture is not stuck to the object.

• Example:

Other Mapping Functions

• Spherical Mapping Example
• Cylindrical Mapping Examples
• Box Mapping Examples

Bump Mapping [Blinn 78]

• Texture map contains displacement to the surface.

Mathematical Derivation:

Decompose N into partial surface derivatives in the u and v directions: Pu Pv.

N = Pu X Pv

F(u,v) is displacement of surface,

P' = P + F(u,v) * N /||N||

Assuming F is negligibly small,

N' = P'u X P'v

P'u = Pu + Fu * N /||N||

P'v = Pv + Fv * N /||N||

N' = N + D

D = [Fu(N X Pv) - Fv(N X Pu)] / ||N||

How do we calculate Fu, Fv?

Given F(u,v) function, ep = 1 / (TextureMapResolution)

Fu = (F(u+ep, v) - F(u - ep, v)) / (2*ep)

Fv = (F(u, v+ep) - F(u, v - ep)) / (2*ep)

How do we calculate Pu, Pv?

• Displace world space point in +u, -u direction and +v, -v direction by small amount and calculate approximated partial derivative as :
Pu = (P(p+uepsilon) - P(p-uepsilon)) / (2 * epsilon)
Pv = (P(p+vepsilon) - P(p-vepsilon)) / (2 * epsilon)

• If smooth shading, need to adjust this because of interpolated normals:
PVtemp = Pu X N
Pu = N X PVtemp

PUtemp = Pv X N
Pv = N X PUtemp

Dependence on scale:

If scale object, need to adjust displacement map accordingly

D' = alpha * D * |N|/|D| ,

alpha = sqrt ( Fu2 + Fv2)

N'' = N + D'

Displacement Mapping [Cook 84]

• Use texture map to displace actual surface geometry. (vertices, control vertices)

• Done as a pre-process to geometry before the actual rendering

• Requires fine resolution in geometry or will get unexpected holes.

• Alternative is for program to add geometry when displacement variation can't smoothly be represented in geometry.

• Example of Bump Mapping vs. Displacement Mapping

• How do you tell the difference between the two?

Environment Mapping (Reflection Mapping) [Newell 76]

• Used to simulate ray traced reflections.

• Use reflection vector as index into texture map.

• Texture map is either hand drawn or precomputed rendering of scene viewed from that location (often times 6 directional rendering ).

• Normally use box projection or spherical.

• Examples of box projection:

• Notice the differences in the ray traced vs. environmental mapped images:

• Key to tell which is which? Look for object reflecting itself.