1
AdvancedComputer Graphics
Lecture 5: Texture Mapping
Bernhard JungTU-BAF, Summer 2007
Overview
Texture MappingTexture Magnification & Minification
MipmappingEnvironment MappingBump MappingLight & Gloss Mapping
Further readingT. Akenine-Möller & E. Haines. Real-Time Rendering. AK Peters.
2002. Chapter 5A. Watt. 3D Computer Graphics, 3rd edition. Addison-Wesley. 2000.
Chapter 8Rosalee Wolfe. Teaching Texture Mapping Visually.
http://old.siggraph.org/education/materials/HyperGraph/mapping/r_wolfe/r_wolfe_mapping_1.htm
wikipedia.org
2
Texture Mappingtexturing: glue images onto geometrical objects
cheap way to achieve more realism e.g. environment mapping, bump mapping, …
smooth shading bump mappingenvironment mapping
Texture mapping
(u,v) in [0,1]projector function corresponder function(s)
texel = pixel from animage texture
3
XYZ UV Parameter Space
Projecting geometry to uv-space per pixel
better quality; during rasterization; non-interactive renderersper vertex
real-time applicationsprojector functions usually applied at modelling stage, results stored at verticeswhen Gouraud shading, texture coordinates are not linearly interpolatedinstead apply perspective correction!
(0,0) (1,0)
(1,1)(0,1)
(u,v) in [0,1] (x0,y0,z0,)
(x1,y1,z1)
(x2,y2,z2)
Parameter Space Texture Coordinates
Corresponder functions (mapping uv texels) What if (u,v) >1.0 or < 0.0 ?To repeat textures, use just the fractional part
Example: 5.3 -> 0.3Repeat, mirror, clamp, border:
(-1,-1)
(2,2)
4
Specifying uv-parameters during modeling
= +
pizza.jpg
coordIndex [ 0, 1, 2, 3, 4, 5 ]texCoord TextureCoordinate {
point [# Center point of pizza image
0.50 0.50,# Slice perimeter
0.68 0.07, 0.76 0.11,0.83 0.17, 0.89 0.24,0.93 0.32,
]}texCoordIndex [ 0, 1, 2, 3, 4, 5, ]solid FALSE
}}
#VRML V2.0 utf8# The VRML 2.0 SourcebookShape {
appearance Appearance {material Material { }texture ImageTexture {
url "pizza.jpg"}
}geometry IndexedFaceSet {
coord Coordinate {point [# Slice, pulled out of pizza
0.50 0.0 0.50, 0.88 0.0 1.42,1.06 0.0 1.33, 1.21 0.0 1.21,1.33 0.0 1.06, 1.42 0.0 0.88
]}
vertex uv-spacemapping
demo
Projector FunctionsHardware support for special projector functions that can be applied in real-time
top row: spherical, cylindrical, planar, and natural (u,v) projectionbottom row: various projections applied to an object (that has no natural projection)
5
Planar Projections
http://softimage.wiki.avid.com/xsidocs/ep546436.htm
Cylindrical Projection
http://softimage.wiki.avid.com/xsidocs/ep546436.htm
• convert (x,y,z) to cylindrical coordinates (r, θ, height) (u, v)
6
Spherical Projection
http://softimage.wiki.avid.com/xsidocs/ep546436.htm
http://www.siggraph.org/education/materials/HyperGraph/mapping
http://www.cs.unc.edu/~rademach
Singularities at poles!
Natural (UV) Projection
http://softimage.wiki.avid.com/xsidocs/ep546436.htm
Use NURBS uv-parameters directly as coordinates for uv space
7
Using various projections on a single model
http://www.titopagan.com/
How textures modify a surface …
replacereplace original surface color with texture colorthis removes any lighting computed for the surface"glow texture" – color always appears the same, regardless of lighting conditions
decallike replace, but when α-value is in the texture, the texture is blended with the original color
modulatemultiply the surface color by the texture color
decal in worldtexture for decal
http://developer.valvesoftware.com/wiki/Creating_Decals
8
Texture Magnification
32x64 texture on rectangle, viewed very closely, therefore magnified
left: nearest neighbor right: bi-linear interpolation
a texel may cover several pixels common methods:
nearest neighborpixelation
bi-linear interpolationinterpolate color from four neighboring texels
usually better results
Texture Minification
one pixel covering many texelsmethods
select center texel? ("nearest neighbor") aliasing problems
average colors of all texels covered by pixel?
can be expensive (not constant time)mip-mapping …
mipmappingno mipmapping
http://www.flipcode.com/articles/article_advgltextures.shtml
9
Mipmapping
Image pyramidHalf width and height when going upwardsAverage over 4 ”parent texels” to form ”child texel”Depending on amount of minification, determine which image to fetch fromCompute d first, gives two images
Bilinear interpolation in each
u
v
d
Mipmapping
Interpolate between those bilinear valuesGives trilinear interpolation
Constant time filtering: 8 texel accessesHow to compute d?
vu
d
Level n+1
Level n
(u0,v0,d0)
10
Computing d for mipmapping
Approximate quad with squareGives overblur for longish quads
Even better: anisotropic texture filteringif surface at high angle with respect to the camera approximate quad with several smaller mipmap samples
pixel projectedto texture space
texel
bdAb
A
2log
ralquadrilateofareaiveapproximat
==
=
Anisotropic texture filtering
16 samples
tri-linear mipmapping 16:1 anisotropic filtering
11
Anisotropic texture filtering
tri-linear mipmapping anisotropic filtering
Mipmapping: Memory requirements
Not twice the number of bytes…!Rather 33% more – not that much
12
Environment mappingmethod for generating (approximations of) reflections in curved surfaces
Environment mapping
Assumes the environment is far awaySphere mapping
Blinn & Newell, 1976Cube mapping is the norm nowadays
advantages: no singularities as in sphere mapmuch less distortiongives better resultnot dependent on a view position
per-pixel calculationssupported by modern graphics hardware, thus feasible in real-time
13
x
y
z
Environment mapping -Cube mapping
Simple math: compute reflection vector, rLargest abs-value of component, determines which cube face.
Example: r=(5,-1,2) gives POS_X faceDivide r by 5 gives (u,v)=(-1/5,2/5)If your hardware has this feature, then it does all the work
neye
Bump mapping
by Blinn in 1978Inexpensive way of simulating wrinkles and bumps on geometry
Too expensive to model these geometricallyInstead let a texture modify the normal at each pixel, and thenuse this normal to compute lighting
geometry Bump mapStores heights: can derive normals
+ Bump mapped geometry=
heightfield bump image ... applied on a sphere
14
Bump mapping: example
Light Mapping
per pixel lightinglike Phong shading (and unlike Gouraud shading)but real-time capable (unlike Phong shading)
works if lighting is static in an environmentdiffuse component then remains the same from any anglelight maps may also be recalculated on the fly for dynamic lighting
http://www.flipcode.com/articles/article_lightmapping.shtml
15
Gloss MappingGloss map: texture that varies the contribution of the specular component over the surfaceLighting equation per pixel:
o = tdiff ⊗ idiff + tgloss ispectdiff – RGB diffuse texture mapidiff – interpolated diffuse lighting color from vertextgloss – single value gloss mapispec – interpolated specular color from vertex
shiny cube -highlight covers entire surface
cube with gloss map –rusty parts no longer shiny
Top Related