0% found this document useful (0 votes)
74 views

Computer Graphics The Problem:: Some Slides Adopted From H. Pfister, Harvard

Texture mapping allows using a single polygon with a repeating texture pattern instead of modeling every detail with geometry. This technique enhances visual realism. Textures are defined as pixmaps containing pixel values or procedural functions. Texture coordinates assigned to vertices are interpolated across polygons, but perspective projection causes distortion. To fix this, perspective correct interpolation linearly interpolates the inverse of the w coordinate instead of the texture coordinate directly, and performs perspective division to obtain the correct interpolated texture coordinate. This technique prevents stretching and preserves textures when mapped onto polygons.

Uploaded by

omar agha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Computer Graphics The Problem:: Some Slides Adopted From H. Pfister, Harvard

Texture mapping allows using a single polygon with a repeating texture pattern instead of modeling every detail with geometry. This technique enhances visual realism. Textures are defined as pixmaps containing pixel values or procedural functions. Texture coordinates assigned to vertices are interpolated across polygons, but perspective projection causes distortion. To fix this, perspective correct interpolation linearly interpolates the inverse of the w coordinate instead of the texture coordinate directly, and performs perspective division to obtain the correct interpolated texture coordinate. This technique prevents stretching and preserves textures when mapped onto polygons.

Uploaded by

omar agha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Computer Graphics The Problem:

Lecture 7:

Texture mapping

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


Some slides adopted from
H. Pfister, Harvard

The Solution: Textures The Quest for Visual Realism

•  The visual appearance of a graphics scene can be


greatly enhanced by the use of texture.

•  Consider a brick building, using a polygon for every


brick require a huge effort in scene design.

•  So why not use one polygon and draw a repeating


brick pattern (texture) onto it?

1
Texture Definition Procedural textures

•  Textures may be defined as: •  Write a function: F(p) → color

–  Pixmaps - Arrays containing the actual pixel values to be


mapped to the polygon, e.g. photos.

–  Procedures - Suitable for repeating patterns.

•  non-intuitive
•  difficult to match existing texture

Photo textures The concept of texture mapping

2
Texture mapping: Terminology The concept of texture mapping

For each triangle/polygon in the model


establish a corresponding region in the texture

During rasterization interpolate the


Graphics Lecture 5: Slide 10
coordinate indices into the texture map

Texture Coordinates Tiling Texture

•  Specify a texture coordinate (s, t) at each vertex (0,3) (0,3)

•  Canonical texture coordinates (0,0) → (1,1)


•  Often the texture size is a power of 2
(but it doesn't have to be) (0,1)

•  How can we tile this texture?

(0,0) (3,0) (0,0) (3,0)


tiles with seamless tiling
visible seams (repeating)
(0,0) (1,0)

3
Texture synthesis Texture coordinates

•  Specify a texture coordinate (s, t) at each vertex


•  Canonical texture coordinates (0,0) → (1,1)
•  Linearly interpolate the values in screen space
(0,1)

(0,0) (1,0)

Mapping texture to individual pixels What Goes Wrong?

•  Interpolate texture coordinates across scanlines


•  Same as Gouraud shading but now for texture
coordinates not shading values

•  Notice the distortion along the diagonal triangle edge


of the cube face

4
Perspective projection How to fix?
•  The problem is that perspective projection does not preserve •  Suppose we assign parameter t to vertices p and r
affine combinations of points!
•  In particular, equal distances along a line in eye space do not •  Suppose t = 0 at p, and t = 1 at r
map to equal distances in screen space •  p projects to p’ and r projects to r’ (divide by w)
•  What value should t have at location q’?
p
p’ = p/wp

q’ = q/wq q
•  Linear interpolation in screen space is not equal to linear
interpolation in eye space!
r’r’==r/z
r/w
r r
r

How to fix? Perspective Correct Interpolation

•  We cannot linearly interpolate t between p’ and r’ •  Linearly interpolate t / w (not t) between p’ and r’.
•  Only projected values can be linearly interpolated in –  Compute tp’ = tp / wp and tr’ = tr / wr
screen space –  Linearly interpolate (lerp) tp’ and tr’ to get tq’ at location q’
•  Solution: perspective-correct interpolation •  But, we want the (unprojected) parameter tq, not tq’
p p
p’ = p/wp p’ = p/wp

q’ = q/wq q’ = q/wq
q q

r’r’==r/z
r/w
r r r’r’==r/z
r/w
r r
r r
Graphics Lecture 5: Slide 19

5
Perspective Correct Interpolation Perspective Correct Interpolation

•  The parameter tq’ is related to tq by a factor of 1/w: •  Summary:


–  Lerp 1 / wp and 1 / wr to obtain 1 / wq at point q’. –  Given parameter t at vertices:
–  Divide tq’ by 1 / wq to get tq •  Compute 1 / w for each vertex
•  Linearly interpolate 1 / w across the triangle
•  Linearly interpolate t / w across the triangle
p •  Do perspective division:
p’ = p/wp
Divide t / w by 1 / w to obtain interpolated parameter t
q’ = q/wq q

r’r’==r/z
r/w
r r
r

Perspective Correct Interpolation Mapping texture to individual pixels


P3

P2 Diagram 7.2
Bi-linear texture
e
map
c
b
p
β Polygon being
textured
a
P4
P1 α

6
Bi-linear Map - Solving for α and β Non Linearities in texture mapping

•  The second order term means that straight lines in the


P3
texture may become curved when the texture is
p = αa + βe P2 mapped.
e = b + α(c - b) e •  However, if the mapping is to a parallelogram:
c
so b p = αa + βb + αβ(c-b)
p
p = αa + βb + αβ(c-b) and
β
a
b=c
P4
P1 α so p = αa + βb
Its Quadratic !

Texture Mapping & Illumination 2D Texture Mapping

•  Texture mapping can be used to alter some or all of •  Increases the apparent complexity of simple geometry
the constants in the illumination equation •  Requires perspective projection correction
•  Can specify
variations in
(
L(ω r ) = k a + k d (n ⋅ l) + ks (v ⋅ r) q ) 4Φπ d s
2
shading within
a primitive:
–  Illumination
–  Surface
Reflectance

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

7
What's Missing? Remember Normal Averaging for Shading?

•  What's the difference between a real brick •  Instead of using the normal of the triangle, interpolate an averaged
wall and a photograph of the normal at each vertex across the face
wall texture-mapped onto a plane?

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

Bump Mapping Bump Mapping

•  Textures can be used to alter the surface normal of an object. •  The texture map is treated as a single-valued height
•  This does not change the actual shape of the surface - we are function.
only shading it as if it were a different shape!
•  The partial derivatives of the texture tell us how to
alter the true surface normal at each point to make the
object appear as if it were deformed by the height
function.

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

8
Another Bump Map Example What's Missing?

•  What does a texture- & bump-


mapped brick wall look like as you
move the viewpoint?

•  What does the


silhouette of a
Bump Map
bump-mapped
sphere look like?

Cylinder w/Diffuse Texture Map Cylinder w/Texture Map & Bump Map

Displacement Mapping Environment Maps

•  Use the texture map to actually move the surface point. •  We can simulate reflections by using the direction of the
–  How is this different than bump mapping? reflected ray to index a spherical texture map at "infinity".
•  The geometry must be displaced before visibility is •  Assumes that all reflected rays begin from the same point.
determined.

9
Environment Mapping Example Questions?

Graphics Lecture 5: Slide 37 Terminator II

10

You might also like