# Texture Mapping Computer Game Programming James Kuffner Jr Carnegie Mellon

Document Sample

```					         Texture Mapping

15-493
Computer Game Programming

James Kuffner, Jr.
Carnegie Mellon University

Texture Mapping
Provides realistic appearance to models without

Works by modifying
of an object by mapping
a function (such as a 2D
image) onto the surface.

2

1
Classic Image Mapping
Consider an image as a 2D function mapping
from [0,1]2 (texture coordinates) to the RGB
color space:
T (u, v) → (r, g, b)
Each object defines a mapping M from points
on the surface to texture coordinates:
M( x, y, z) = (u, v)
Given a point (x,y,z) on the surface, use the
color:
(r, g, b) = T ( M( x, y, z ))
3

Image Mapping Example
Texture Image:            Result:

4

2
Surface Properties that Texture
Maps can Modify
Final color (image maps, light maps)
Surface normal (bump maps)
Transparency (opacity maps)
Reflectance properties (diffuse, specular maps)
Reflected color (environment maps)
Any combination of the above
We now have vertex and pixel shading
capabilities in hardware, so you can
perform complex texturing interactively
5

3
Texture Coordinates
Certain objects have a natural parameterization
(e.g., squares, Bezier patches)
Polygons (triangles):
– Each vertex is assigned a pair of texture
(u,v)
coordinates (u,v)
– Texture coordinates in the interior are linearly
interpolated
How do we define a mapping for more
complex surfaces?
7

Two-Step Texture Mapping
(Bier and Sloan 1986)

Step I: define a mapping between the texture
and some intermediate surface:
– plane
– cylinder
– sphere
– cube
Step II: Project intermediate surface onto
object surface

8

4
Intermediate Surface Projections

9

Texture Anti-Aliasing
A single screen space pixel might correspond to many
pixels in the texture image:

10

5
Unfiltered Texture:

11

Filtered Texture:

12

6
Texture Pre-Filtering
Problem: filtering a texture during rendering is
too slow for interactive performance

Solution: pre-filter the texture in advance
– Summed area tables - gives the average value of
axis-
each axis-aligned rectangle in texture space
Mip-       (tri-
– Mip-maps (tri-linear interpolation) - supported by
most of today’s texture mapping hardware

13

Mip-mapping (Williams 83)
Store pre-filtered scaled copies (texture
“levels”) of the original source texture
Typically, each level is half the size of the
previous level

How much additional memory does this cost?
14

7
Storing Mip-maps
Amazingly, only 1/3
more memory than
the original image
required for mip-map

15

Texture maps used to modify the object color can be:
UNLIT (sometimes called a “Decal” or “Label”)
– Uses the source image color directly
– No lighting calculations
LIT (modifies diffuse or specular color in shading)
– Uses lighting and shading model to calculate final color
16

8
Bump Mapping (Blinn 78)
Intensity value of a source image is used to modify
the normal direction of the object surface
Does not modify surface geometry, but the visual
result fools us into thinking the surface is not smooth

17

Bump Mapping

18

9
Bump Mapping
RESULT ON A SMOOTH SPHERE:

SOURCE IMAGE:

19

Procedural and Solid Textures
Peachey,
(Gardner 184, Peachey, Perlin 1985)

Problem: mapping a 2D image/function onto
the surface of a general 3D object is a difficult
problem:
– Distortion
– Discontinuities
Idea: use a texture function defined over a 3D
domain - the 3D space containing the object
– Texture function can be digitized (stored as a 3D
array of volume data) or generated procedurally
20

10
Perlin’
Ken Perlin’s famous solid texture marble vase, 1985

Perlin’
Ken Perlin’s vase with procedurally varying index of refraction, 1985

11
Procedural Textures
– compact representation (code vs. data)
– unlimited resolution
– unlimited extent
– controllable via parameters
– Can be difficult to program and debug
– Can be difficult to predict and control
– Typically slower to evaluate
pre-
– Can be difficult to pre-filter
23

Environment Mapping
Modify the reflected color
Use a cube map or spherical image map to
associate reflected colors with all directions

24

12
Multi-Textures and Detail Textures
Blend several textures on the same surface
Now supported in hardware (from 4-16 textures)
4-

25

13

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 23 posted: 1/24/2009 language: English pages: 13
How are you planning on using Docstoc?