Texture Mapping. Typical application: mapping images on geometry. =. +. RGB texture 2D (color-map). 3D geometry (quads mesh). More examples. Texture Mapping. The fragment operations can access a specialized RAM The Texture RAM Organized in a set of Textures
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Texture Mapping
=
+
RGB texture 2D
(color-map)
3D geometry
(quads mesh)
1D, 2D o 3D
of Texels (texture elements) of the same type
+
=
Ed Catmull
(MEGA-MEGA-GURU)
v
1.0
512 texels
u
1.0
1024 texels
texel
Texture Space
(or "parametric space" or "u-v space")
Texture 2D
A Texture is defined
In the region [0,1] x [0,1]
of the "parametric space"
v
u1,v1
u0,v0
u1,v1
Position of the
1st vertex
Attributes of the
1st vertex
u0,v0
u2,v2
u2,v2
u
Texture Space
x1,y1
x0,y0
x2,y2
Screen Space
Screen Space
Texture Space
texture look-up
Screen Space
Texture Space
texturelook-up
including:
texture
coordinates
(per vertex!)
interpolation
texture
coordinates
texture coordinatesinterpolated
set-up
points rasterizer
Projected Vertices
& computed attributes
Fragments
& interpolated attributes
Vertices
& their attributes
Screen
buffer
set-up
Triangles rasterizer
vertexcomputation
Fragment
computations
set-up
Segments rasterizer
Texture RAM
f( v3 )
V3
f( v2 )
projection f
f(p)
p
V2
f( v1 )
V1
f(p) has barycentric coordinates a,b,c in the triangle f(v1)f(v2) f(v3)
p has barycentric coordinates a,b,c
In the triangle v1v2v3
v
1
u
1
u,v= (1,0)
u1,v1= (1,1)
u1,v1= (0,0)
u1,v1= (0,1)
A1,B1...
A0,B0...
p
A2,B2...
p =c0 v0 +c1v1+c2v2
V1
V0
= ( x0, y0, z0, w0)
Attributes of p:
(not considering the “perspective correction")
V2
Ap=c0 A0 +c1A1+c2A2
Bp=c0 B0 +c1B1+c2B2
A1,B1...
A0,B0...
A2,B2...
p =c0 v0 +c1v1+c2v2
Attributes of p:
(not considering the “perspective correction")
V1
V0
= ( x0, y0, z0, w0)
p
V2
A0
A1
A2
Ap =c0 A0+c1A1+c2A2
w0
w1
w2
Ap=
w0
w1
w2
1
1
1
Ap =c0 A0+c1A1+c2A2
set-up
points rasterizer
Screen
buffer
Projected Vertices
& computed attributes
Fragments
& interpolated attributes
Vertices
& their attributes
set-up
Triangles rasterizer
vertexcomputation
Fragment
computations
set-up
Segments rasterizer
interpolate
A'and w'
Final fragment attribute:
A'/w'
Apply transformations
compute: A' = A / w
and
w' = 1 / w
A0
Original attribute A
A1
A2
c0 +c1+c2
w0
w1
w2
Ap=
1
1
1
c0 +c1+c2
w0
w1
w2
With
LOAD
Texture RAM
set-up
points rasterizer
Screen
buffer
Projected Vertices
& computed attributes
Fragments
& interpolated attributes
Vertices
& their attributes
set-up
Triangles rasterizer
vertexcomputation
Fragment
computations
set-up
Segments rasterizer
Both steps are quite slow. It is not possible to accomplish them once per frame!
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
GL_UNSIGNED_BYTE,
imageData);
texturelook-up
including:
coordinatestexture
(per vertex!)
including:
texture
coordinates
(per vertex!)
interpolation
texture
coordinates
Interpolated
texture
coordinates
set-up
points rasterizer
Screen
buffer
Projected Vertices
& computed attributes
Fragments
& interpolated attributes
Vertices
& their attributes
set-up
Triangles rasterizer
vertexcomputation
Fragment
computations
set-up
Segments rasterizer
Texture RAM
The choice is application-dependent!
v
v
u
u
Hand-made
or automated
TexCoord2d( u,v )
texturelook-up
interpolating
texture coordinates
texture coordinates interpolated
set-up
points rasterizer
Screen
buffer
Projected Vertices
& computed attributes
Fragments
& interpolated attributes
Vertices
& their attributes
set-up
Triangles rasterizer
vertexcomputation
Fragment
computations
set-up
Segments rasterizer
texture coordinates
(transformed)
including:
texture
coordinates
Texture RAM
texturelook-up
Interpolated
texture coordinates
interpolating
texture coordinates
set-up
points rasterizer
Screen
buffer
Projected Vertices
& computed attributes
Fragments
& interpolated attributes
Vertices
& their attributes
set-up
Triangles rasterizer
vertexcomputation
Fragment
computations
set-up
Segments rasterizer
compute
texture coordinates
Using the position
texture coordinates
Texture RAM
1D texture!
Environment map: a texture containing the color of the environment “reflexed by each normal of the half-sphere”.
The texture coordinate is the transformed normal!
Simulates a mirror-like object reflecting a far-away background
simulates a complex material
(fixed lighting)
above
left
front
right
back
below
interpolating
3D texture
coordinates
interpolated
coordinates 3D texture
set-up
points rasterizer
Projected Vertices
& computed attributes
Fragments
& interpolated attributes
Vertices
& their attributes
set-up
Triangles rasterizer
vertexcomputation
Fragment
computations
Screen
buffer
set-up
Segments rasterizer
Project on the cube, look-up the corresponding face
compute
3D Texture
coordinates
[-1,+1] x [-1,+1] x [-1,+1]
As view ray reflexed by the normal
Texture RAM
above
left
front
right
back
below
S, T, R, Q
1- abilitate:
glEnable(GL_TEXTURE_GEN_S);
2- choice of the mode:
glTexGeni(GL_S , GL_TEXTURE_GEN_MODE , mode )
Computes the texture coordinates from the position in object coordinates
(before the trasformation)
GL_OBJECT_LINEAR
GL_EYE_LINEAR
GL_SPHERE_MAP
Computes the texture coordinates from the position in view coordinates
(after the MODEL-VIEW)
=
mode
The texture coordinates is the reflexed view ray (using the normal)
(after the MODEL-VIEW)
3- choice of the plane
S, T, R, Q
glTexGenfv(GL_S, GL_EYE_PLANE , v);
or
EYE OBJECT
4 elements vector
The resulting texture coordinate = vT• pos_vertex
(It’s the distance from the plane!)
v
1
u
1
if (u<0) u←0; if (u>1) u←1;
if (v<0) v←0; if (v>1) v←1;
u ← u – [ u ]
v ← v – [ v ]
v
1
u
1
Note: the texture must be TILEABLE
Very space-efficient!
note:
u and v treated separately
example: repeat u and clamp v
Texture parameters. each texture loaded in memory has its own parameters.
glTexParameteri(
GL_TEXTURE_2D,
GL_TEXTURE_WRAP_S,
GL_CLAMP );
or
glTexParameteri(
GL_TEXTURE_2D,
GL_TEXTURE_WRAP_S,
GL_REPEAT );
texture look-up
(in texels)
Screen Space
Texture Space
texel
pixel
magnification
pixel
minification
one pixel = less than one texel
Screen Space
Texture Space
one pixel = more than one texel
7.5
6.5
5.5
4.5
3.5
2.5
1.5
0.5
0.5
1.5
3.5
4.5
5.5
6.5
2.5
v
Solution 1:
Use the texel containg the pixel
(that is, the texel whose center
is closest to the u,v coordinates
of the fragment)
Equivalent to rounding up
the texel coordinates
to the nearest integer
"Nearest Filtering"
7.5
u
"texels are visible !"
Nearest Filtering: result
texture 128x128
7.5
6.5
5.5
4.5
3.5
2.5
1.5
0.5
0.5
1.5
3.5
4.5
5.5
6.5
2.5
v
Solution 2:
Compute the average of the four closest texels
Bilinear Interpolation
7.5
u
Bilinear Interpolation: result
texture 128x128
Bilinear interpolation
Does not solve the problem
Nearest Filtering
MIP-map
level 3
MIP-map
level 2
MIP-map
level 1
MIP-map
level 4
(only one texel)
MIP-mapping: "Multum In Parvo"
MIP-map
level 0
MIP-mapping
Bilinear interpolation
5
4
3
2
1
Other example
0
Choose the magnification filter:
glTexParameteri(
GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
or
glTexParameteri(
GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,
GL_LINEAR );
Trilinear interpolation
Choose the minification filter:
glTexParameteri(
GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER,
mode );
where
mode= GL_NEAREST
GL_LINEAR
GL_NEAREST_MIPMAP_NEAREST
GL_LINEAR_MIPMAP_NEAREST
GL_NEAREST_MIPMAP_LINEAR
GL_LINEAR_MIPMAP_LINEAR
glTexImage2D (
GL_TEXTURE_2D,
i, // MIP-map level
GL_RGB, // original format
imageWidth, imageHeight,
0, // border
GL_RGB, // RAM format
GL_UNSIGNED_BYTE,
imageData);
glTexImage2D (
GL_TEXTURE_2D,
0, // MIP-map level
GL_RGB, // original format
imageWidth, imageHeight,
0, // border
GL_RGB, // RAM format
GL_UNSIGNED_BYTE,
imageData);
gluBuild2DMipmaps (