texture mapping - Fabio...

25
computer graphics • texture mapping © 2009 fabio pellacini • 1 texture mapping computer graphics • texture mapping © 2009 fabio pellacini • 2 why texture mapping? objects have spatially varying details represent as geometry: correct, but very expensive

Transcript of texture mapping - Fabio...

Page 1: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 1

texture mapping

computer graphics • texture mapping © 2009 fabio pellacini • 2

why texture mapping?

•  objects have spatially varying details •  represent as geometry: correct, but very expensive

Page 2: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 3

why texture mapping?

•  use simple geometry •  store varying properties in images •  map to objects

[Wol

fe /

SG97

Slid

e se

t]

computer graphics • texture mapping © 2009 fabio pellacini • 4

why texture mapping?

•  produces compelling results [Je

rem

y Bi

rn]

Page 3: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 5

why texture mapping?

•  easily change object appearance

[Pra

un e

t al

., 20

01]

computer graphics • texture mapping © 2009 fabio pellacini • 6

mapping function

•  surfaces are 2d domains •  determine a function that maps them to images

Mapping Function

Surface Image

Page 4: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 7

mapping functions – projections

•  maps 3d surface points to 2d image coordinates

•  different types of projections –  often corresponding to simple shapes –  useful for simple object

23 ]1,0[: →ℜf

[Wol

fe /

SG97

Slid

e se

t]

computer graphics • texture mapping © 2009 fabio pellacini • 8

projections – planar

Page 5: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 9

projections – cubical

computer graphics • texture mapping © 2009 fabio pellacini • 10

projections – cylindrical

Page 6: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 11

projections – spherical

computer graphics • texture mapping © 2009 fabio pellacini • 12

projections

•  planar projection along xy plane of size (w,h) –  use affine transform to orient the plane differently

•  spherical projection of unit sphere –  consider point in spherical coordinates

•  cylindrical projection of unit cylinder of height h –  consider point in cylindrical coordinates –  treat caps separately

)/,/()( hpwpf yx=p

),()( θφ=pf

)/,()( hpf yφ=p

Page 7: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 13

looking up texture values

•  normal: do not repeat texture –  clamp image coordinates to [0,1] then lookup

•  tiled: repeat texture multiple times –  take mod of image coordinates then lookup

normal tiled

computer graphics • texture mapping © 2009 fabio pellacini • 14

texture mapping artifacts

•  tiling textures might introduce seems –  discontinuities in the mapping function –  change texture to be “tileable” when possible

Page 8: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 15

texture mapping artifacts

•  mapping textures will introduce distortions –  unavoidable artifacts

•  local scale and rotation differences

distorted undistorted

computer graphics • texture mapping © 2009 fabio pellacini • 16

mapping function – explicit coordinates

•  store texture coordinates on control points •  interpolate as any other parameter

–  follow interpolation rule defined by surface type

•  parametric surfaces: can use parameters directly

•  known as UV mapping

Page 9: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 17

uv mapping subdivision surfaces

level 0 level 1 level 2

computer graphics • texture mapping © 2009 fabio pellacini • 18

uv mapping vs. projection

parameterization projection

Page 10: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 19

uv mapping parametric surfaces

[Wol

fe /

SG97

Slid

e se

t]

computer graphics • texture mapping © 2009 fabio pellacini • 20

uv mapping polygon meshes

Page 11: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 21

uv mapping polygon meshes

[Pip

oni e

t al

., 20

00]

computer graphics • texture mapping © 2009 fabio pellacini • 22

uv mapping polygon meshes

•  break up model intro single texture [©

Dis

cree

t]

Page 12: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 23

interpolating uv coordinates on meshes

•  pay attention when rasterizing triangles –  for raytracing just use baricentric coordinates

texture linear interp. perspective interp.

used also for colors

[MIT

Ope

nCou

rsew

are]

computer graphics • texture mapping © 2009 fabio pellacini • 24

painting textures on models

•  if painting is required, paint directly on surfaces –  system determines inverse mapping to update image –  seems/distortions present, but user does not know

Page 13: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 25

texture magnification

•  linearly interpolate closest pixels in texture

[MIT

Ope

nCou

rsew

are]

texture rendered image

computer graphics • texture mapping © 2009 fabio pellacini • 26

texture minification

•  compute average of texture pixels projected onto each view pixels

[MIT

Ope

nCou

rsew

are]

texture rendered image

Page 14: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 27

texture minification

•  remember point-sampling introduces artifacts –  need average of texture below a pixel

[MIT

Ope

nCou

rsew

are]

computer graphics • texture mapping © 2009 fabio pellacini • 28

mip-mapping

•  approximate algorithm for computing filters •  store texture at different resolution •  look up the appropriate image based on its projected

size

[MIT

Ope

nCou

rsew

are]

Page 15: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 29

3d solid texturing

•  define a 3D field of values, indexed using P –  in-memory array: too much memory –  procedurally: hard to define

•  often add noisy-like details on 2d images

[Wol

fe /

SG97

Slid

e se

t]

computer graphics • texture mapping © 2009 fabio pellacini • 30

types of mapping

Page 16: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 31

texture mapping material parameters

•  diffuse coefficient

computer graphics • texture mapping © 2009 fabio pellacini • 32

texture mapping material parameters

•  specular coefficient

Page 17: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 33

displacement mapping

•  variations of surface positions, thus normals –  requires fine tessellation of object geometry

computer graphics • texture mapping © 2009 fabio pellacini • 34

displacement mapping

•  update position by displacing points along normal

•  recompute normals by evaluating derivatives –  no closed form solution: do it numerically

NPP hd +=

vuvudddd

d ΔΔ

×ΔΔ

≈∂∂

×∂∂

∝PPPPN

Page 18: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 35

bump mapping

•  variation of surface normals –  apply normal perturbation without updating positions

computer graphics • texture mapping © 2009 fabio pellacini • 36

bump mapping

•  simple example: bump mapping xy plane

zyxNPP),(),(),(),(vuhvuvuhvuvud

++=

=+=

yxz

zyzxPPN

vh

uh

vh

uh

vudd

d

∂∂

−∂∂

−=

=⎟⎠⎞

⎜⎝⎛

∂∂

+×⎟⎠⎞

⎜⎝⎛

∂∂

+=∂∂

×∂∂

Page 19: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 37

bump vs. displacement mapping

bump map displacement map

computer graphics • texture mapping © 2009 fabio pellacini • 38

bump vs. displacement mapping

bump map displacement map

Page 20: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 39

combining maps types

•  combine multiple maps to achieve realistic effects

computer graphics • texture mapping © 2009 fabio pellacini • 40

lighting effects using texture mapping

Page 21: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 41

shadow mapping

•  graphics pipeline does not allow shadow queries •  we can use texturing and a multipass algorithm

project a color texture “project” a depth texture

[NV

IDIA

/Eve

ritt

et

al.]

computer graphics • texture mapping © 2009 fabio pellacini • 42

shadow mapping algorithm

•  pass 1: render scene from light view •  pass 1: copy depth buffer in a new texture

•  pass 2: render scene from camera view •  pass 2: transform each pixel to light space •  pass 2: compare value to depth buffer •  pass 2: if current < buffer depth then shadow

Page 22: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 43

shadow mapping algorithm

[NV

IDIA

/Eve

ritt

et

al.]

camera view light view shadow buffer

computer graphics • texture mapping © 2009 fabio pellacini • 44

shadow mapping algorithm [N

VID

IA/E

veri

tt e

t al

.]

camera view light distance projected shadow buffer

Page 23: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 45

shadow mapping limitations

•  not enough resolution: blocky shadows –  pixels in shadow buffer too large when projected

•  biasing: surfaces shadow themselves –  remember the epsilon in raytracing –  made much worst by resolution limitation

[Fernando et al., 2002]

computer graphics • texture mapping © 2009 fabio pellacini • 46

environment mapping

•  graphics pipeline does not allow reflections •  we can use texturing and a multipass algorithm

[Wol

fe /

SG97

Slid

e se

t]

Page 24: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 47

environment mapping algorithm

•  pass 1: render scene 6 times from object center •  pass 1: store images onto a cube

•  pass 2: render scene from the camera view •  pass 2: use cube projection to look up values

•  variation of this works also for refraction

computer graphics • texture mapping © 2009 fabio pellacini • 48

environment map limitations

•  incorrect reflections –  objects in incorrect positions: better for distant objs –  “rays” go through objects

•  inefficient: need one map for each object

Page 25: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics09/lectures/13_Texturing.pdf · • tiling textures might introduce seems – discontinuities in the mapping

computer graphics • texture mapping © 2009 fabio pellacini • 49

light effects take home message

•  pipeline not suitable for lighting computations –  algorithms are complex to implement and not robust

•  lots of tricks and special cases

–  but fast

•  interactive graphics: use pipeline algorithms •  high-quality graphics: use pipeline for view, raytracing

for lighting

computer graphics • texture mapping © 2009 fabio pellacini • 50

texturing demos OpenGL tutor:

texture.exe

NVidia samples: bumpy_shiny_patch.exe

hw_shadowmap_simple.exe simple_soft_shadows.exe