advanced computer graphics - tu-freiberg.de€¦ · 1 advanced computer graphics lecture 5: texture...

15
1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification & Minification Mipmapping Environment Mapping Bump Mapping Light & Gloss Mapping Further reading T. Akenine-Möller & E. Haines. Real-Time Rendering. AK Peters. 2002. Chapter 5 A. Watt. 3D Computer Graphics, 3rd edition. Addison-Wesley. 2000. Chapter 8 Rosalee Wolfe. Teaching Texture Mapping Visually. http://old.siggraph.org/education/materials/HyperGraph/ma pping/r_wolfe/r_wolfe_mapping_1.htm wikipedia.org

Upload: others

Post on 30-Jul-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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

Page 2: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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

Page 3: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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)

Page 4: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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)

Page 5: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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)

Page 6: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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

Page 7: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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

Page 8: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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

Page 9: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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)

Page 10: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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

Page 11: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

11

Anisotropic texture filtering

tri-linear mipmapping anisotropic filtering

Mipmapping: Memory requirements

Not twice the number of bytes…!Rather 33% more – not that much

Page 12: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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

Page 13: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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

Page 14: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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

Page 15: Advanced Computer Graphics - tu-freiberg.de€¦ · 1 Advanced Computer Graphics Lecture 5: Texture Mapping Bernhard Jung TU-BAF, Summer 2007 Overview Texture Mapping Texture Magnification

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