texture mapping - fabio...

50
computer graphics • texture mapping © 2006 fabio pellacini • 1 texture mapping

Upload: others

Post on 18-Oct-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 1

texture mapping

Page 2: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 2

why texture mapping?

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

Page 3: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 3

why texture mapping?

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

[Wol

fe /

SG97

Slid

e se

t]

Page 4: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 4

why texture mapping?

• produces compelling results

[Jere

my

Birn

]

Page 5: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 5

why texture mapping?

• easily change object appearance

[Pra

unet

al.,

200

1]

Page 6: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 6

mapping function

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

MappingFunction

Surface Image

Page 7: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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]

Page 8: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 8

projections – planar

Page 9: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 9

projections – cubical

Page 10: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 10

projections – cylindrical

Page 11: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 11

projections – spherical

Page 12: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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 13: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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

Page 14: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 14

texture mapping artifacts

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

Page 15: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 15

texture mapping artifacts

• mapping textures will introduce distortions– unavoidable artifacts

• local scale and rotation differences

distorted undistorted

Page 16: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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 17: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 17

uv mapping subdivision surfaces

level 0 level 1 level 2

Page 18: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 18

uv mapping vs. projection

parameterization projection

Page 19: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 19

uv mapping parametric surfaces

[Wol

fe /

SG97

Slid

e se

t]

Page 20: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 20

uv mapping polygon meshes

Page 21: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 21

uv mapping polygon meshes

[Pip

onie

t al

., 20

00]

Page 22: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 22

uv mapping polygon meshes

• break up model intro single texture

[©D

iscr

eet]

Page 23: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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]

Page 24: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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 25: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 25

texture magnification

• linearly interpolate closest pixels in texture

[MIT

Ope

nCou

rsew

are]

texture rendered image

Page 26: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 26

texture minification

• compute average of texture pixels projected onto each view pixels

[MIT

Ope

nCou

rsew

are]

texture rendered image

Page 27: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 27

texture minification

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

[MIT

Ope

nCou

rsew

are]

Page 28: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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 29: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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]

Page 30: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 30

types of mapping

Page 31: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 31

texture mapping material parameters

• diffuse coefficient

Page 32: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 32

texture mapping material parameters

• specular coefficient

Page 33: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 33

displacement mapping

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

Page 34: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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 35: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 35

bump mapping

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

Page 36: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 36

bump mapping

• simple example: bump mapping xy plane

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

vuhvuvuhvuvud

++==+=

yxz

zyzxPPN

vh

uh

vh

uh

vudd

d

∂∂

−∂∂

−=

=⎟⎠⎞

⎜⎝⎛

∂∂

+×⎟⎠⎞

⎜⎝⎛

∂∂

+=∂∂

×∂∂

Page 37: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 37

bump vs. displacement mapping

bump map displacement map

Page 38: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 38

bump vs. displacement mapping

bump map displacement map

Page 39: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 39

combining maps types

• combine multiple maps to achieve realistic effects

Page 40: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 40

lighting effects using texture mapping

Page 41: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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 a

l.]

Page 42: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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 43: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 43

shadow mapping algorithm

[NV

IDIA

/Eve

ritt

et a

l.]

camera view light view shadow buffer

Page 44: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 44

shadow mapping algorithm

[NV

IDIA

/Eve

ritt

et a

l.]

camera view light distance projected shadow buffer

Page 45: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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]

Page 46: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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 47: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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

Page 48: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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 49: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 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

Page 50: texture mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics06/lectures/13_Texturing_Web.… · computer graphics • texture mapping © 2006 fabio pellacini • 49

computer graphics • texture mapping © 2006 fabio pellacini • 50

texturing demosOpenGL tutor:

texture.exe

NVidia samples:bumpy_shiny_patch.exe

hw_shadowmap_simple.exesimple_soft_shadows.exe