Texture Mapping
•
The fragment operations can access a specialized
RAM
–
The Texture RAM
–
Organized in a set of Textures
•
Each texture is an array
1D, 2D o 3D
Texels
•
Typical examples of texels:
–
each texel is a color (components: R-G-B, or R-G-B-A)
•
The texture is a "
color-map
"
–
each texel is an alpha value
•
the texture is an "
alpha-map
"
–
each texel is a normal (components: X-Y-Z)
•
the texture is a "
normal-map
" or "
bump-map
"
–
each texel contains a specularity value
•
the texture is a "
shininess-map
"
Typical application: mapping images on geometry
3D geometry
(quads mesh
+
RGB texture
2D
(color-map)
More examples
Texture Mapping: History
•
1974 introduced by Ed Catmull
–
In its Phd Thesis
•
Only in 1992 (!) we have texture mapping hardware
–
Silicon Graphics RealityEngine
•
1992 on:
increasingly used and integrated in graphic cards
–
First of all by low end graphic boards
•
Today:
a fundamental rendering primitive
–
the main image-based technique
Ed Catmull
Notation
Texture 2D
u
v
texel
Texture Space
(or "parametric space" or "u-v space")
A Texture is defined
In the region [0,1] x [0,1]
of the "parametric space"
5
1
2
te
xe
ls
1024 texels
Texture Space
u
v
Texture Mapping
•
We associate to each vertex (of each triangle) its
u,v
coordinates in the texture space
Screen Space
x
0,y
0x
2,y
2x
1,y
1u
0,v
0u
1,v
1u
2,v
2Position of the 1st vertex
Attributes of the 1st vertex
u
0,v
0u
1,v
1Texture Mapping
•
More precisely, we define a mapping between the
3D triangle 3D and a texture triangle
Texture Mapping
•
each fragment has its own
u,v
coordinates
in the
texture space
Texture Space
Screen Space
Problem: linear interpolation of texture coordinates
•
Not true for perspective projection!
–
It is only an approximation
–
It works fine to interpolate colors, normals, ..
–
Not applicable to interpolate texture coordinates...
V
1V
2V
3p
3
R
R
2
f(p)
f( v
1)
f( v
2)
f( v
3)
projection
f
p
has barycentric coordinates
a,b,c
In the triangle
v
1v
2v
3f(p)
has barycentric coordinates
Problem: linear interpolation of texture coordinates
•
Example:
u
v
1
1
u,v= (1,0)
u
1,v
1= (1,1)
u
1,v
1= (0,1)
Problem: linear interpolation of texture coordinates
Solution: Perspective Correction
•
p
has
barycentric coordinates
c
0c
1c
2V
0V
2V
1A
0,B
0...
A
1,B
1...
A
2,B
2...
p
p
=
c
0
v
0
+
c
1
v
1
+
c
2
v
2
Attributes of
p
:
(not considering the
“
perspective correction
")
A
p
=
c
0
A
0
+
c
1
A
1
+
c
2
A
2
B
p
=
c
0
B
0
+
c
1
B
1
+
c
B
Solution: Perspective Correction
•
p
has
barycentric coordinates
c
0c
1c
2V
0V
2V
1A
0,B
0...
A
1,B
1...
A
2,B
2...
p
p
=
c
0
v
0
+
c
1
v
1
+
c
2
v
2
Attributes of
p
:
(not considering the
“
perspective correction
")
w
0
w
1
A
p
=
c
0
A
A
0
0
+
c
1
A
1
+
c
2
A
2
w
0
A
1
w
1
A
2
w
2
A
p
=
A
p
=
c
0
A
1
0
+
c
1
A
1
1
+
c
2
A
1
2
w
2
Solution: Perspective Correction
Screen
buffer
Original
attribute
A
Apply
transformatio
ns
compute:
A'
= A / w
and
w'
= 1 / w
c
0
w
A
0
+
c
1
+
c
2
0
A
1
w
1
A
2
w
2
A
p
=
1
w
0
w
1
1
w
1
2
interpolat
e
A'
and
w'
Final
fragment
attribute:
A'
/
w'
c
0
+
c
1
+
c
2
Perspective Correction
Perspective Correction
•
Texture mapping with perspective correction
–
Also known as (aka):
•
Perfect texture mapping
•
3 magic vectors method
(out of fashion)
Note: the texture must be loaded
Screen
buffer
Texture RAM
L
O
A
D
Note: the texture must be loaded
1.
From hard disk to main RAM memory
•
(in the
motherboard
)
2.
From main RAM memory to Texture RAM
•
(
on board
of the graphics HW)
In OpenGL
•
As an example:
glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, ID);
glTexImage2D (
GL_TEXTURE_2D,
0,
// mipmapping
GL_RGB,
// original format
imageWidth, imageHeight,
0,
// border
GL_RGB,
// RAM format
Assigning texture coordinates to vertices
•
2 possibilities:
–
Computing textures coordinates on the fly
•
During the rendering…
–
Precomputing
•
(and store them within the mesh)
Difficult problem: u-v mapping
•
Associate texture coordinates to each vertex of the
mesh
–
During preprocessing
u
v
Difficult problem: u-v mapping
In OpenGL
•
Like any other attribute
Assigning texture coordinates to vertices
•
2 possibilities:
–
Computing textures coordinates on the fly
•
During the rendering…
–
Precomputing
Automatically computed
•
Idea: from (x,y,z) to (u,v) - Linearly
•
Using object or view coordinate
Automatically computed
•
Even 1D
Assigning texture coordinates to vertices
•
2 possibilities:
–
Computing textures coordinates on the fly
•
During the rendering…
–
Precomputing
Environment mapping: spherical
Environment map: a texture containing the color
of the environment “reflexed by each normal of
the half-sphere”.
Environment mapping: spherical
Simulates a mirror-like object reflecting a far-away background
Environment mapping: cube
front right back
below
above
Environment mapping: cube
Screen
buffer
Texture RAM
interpolati
ng
3D texture
coordinate
s
interpolat
ed
coordinat
es
3D
texture
Project on the
cube, look-up the
corresponding
face
compute
3D Texture
coordinates
1,+1] x 1,+1] x [-1,+1]