Texture Mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics05/lectures/13...3D Solid...
Transcript of Texture Mapping - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics05/lectures/13...3D Solid...
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 1
Texture Mapping
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 2
Why Texture Mapping?
• objects have spatially varying details• represent as geometry: correct, but very
expensive
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 3
Why Texture Mapping?
• use simple geometry• store varying properties in images• map to objects
[Wol
fe /
SG
97 S
lide
set]
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 4
Why Texture Mapping?
• produces compelling results
[Jer
emy
Birn
]
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 5
Why Texture Mapping?
• easily change object appearance
[Pra
unet
al.,
200
1]
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 6
Mapping Function
• surfaces are 2d domains• determine a function that maps them to images
MappingFunction
Surface Image
Computer Graphics • Texture Mapping © 2005 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 /
SG
97 S
lide
set]
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 8
Projections – Planar
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 9
Projections – Cubical
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 10
Projections – Cylindrical
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 11
Projections – Spherical
Computer Graphics • Texture Mapping © 2005 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
Computer Graphics • Texture Mapping © 2005 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 © 2005 Fabio Pellacini • 14
Texture Mapping Artifacts
• tiling textures might introduce seems– discontinuities in the mapping function– change texture to be “tileable” when possible
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 15
Texture Mapping Artifacts
• mapping textures will introduce distorsions– unavoidable artifacts
• local scale and rotation differences
distorted undistorted
Computer Graphics • Texture Mapping © 2005 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
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 17
UV Mapping Subdivision Surfaces
Level 0 Level 1 Level 2
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 18
UV Mapping vs. Projection
Parameterization Projection
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 19
UV Mapping Parametric Surfaces[W
olfe
/ S
G97
Slid
e se
t]
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 20
UV Mapping Polygon Meshes
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 21
UV Mapping Polygon Meshes
[Pip
onie
t al.,
200
0]
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 22
UV Mapping Polygon Meshes
• break up model intro single texture
[©D
iscr
eet]
Computer Graphics • Texture Mapping © 2005 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 © 2005 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
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 25
Texture Magnification
• linearly interpolate closest pixels in texture
[MIT
Ope
nCou
rsew
are]
texture rendered image
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 26
Texture Minification
• compute average of texture pixels projected onto each view pixels
[MIT
Ope
nCou
rsew
are]
texture rendered image
Computer Graphics • Texture Mapping © 2005 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 © 2005 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]
Computer Graphics • Texture Mapping © 2005 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 /
SG
97 S
lide
set]
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 30
Types of Mapping
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 31
Texture Mapping Material Parameters
• diffuse coefficient
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 32
Texture Mapping Material Parameters
• specular coefficient
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 33
Displacement Mapping
• variations of surface positions, thus normals– requires fine tessellation of object geometry
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 34
Displacement Mapping
• update position by displacing points along normal
• recompute normals by evaluating derivatives– no clse form solution: do it numerically
NPP hd +=
vuvudddd
d ΔΔ
×ΔΔ
≈∂∂
×∂∂
∝PPPPN
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 35
Bump Mapping
• variation of surface normals– apply normal perturbation without updating positions
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 36
Bump Mapping
• simple example: bump mapping xy plane
zyxNPP),(),(),(),(
vuhvuvuhvuvud
++==+=
yxz
zyzxPPN
vh
uh
vh
uh
vudd
d
∂∂
−∂∂
−=
=⎟⎠⎞
⎜⎝⎛
∂∂
+×⎟⎠⎞
⎜⎝⎛
∂∂
+=∂∂
×∂∂
∝
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 37
Bump vs. Displacement Mapping
Bump map Displacement map
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 38
Bump vs. Displacement Mapping
Bump map Displacement map
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 39
Combining Maps Types
• conbine multiple maps to achieve realistic effects
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 40
Lighting Effects Using Texture Mapping
Computer Graphics • Texture Mapping © 2005 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
ritte
t al.]
Computer Graphics • Texture Mapping © 2005 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
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 43
Shadow Mapping Algorithm[N
VID
IA/E
verit
tet a
l.]
camera view light view shadow buffer
Computer Graphics • Texture Mapping © 2005 Fabio Pellacini • 44
Shadow Mapping Algorithm
[NV
IDIA
/Eve
ritte
t al.]
camera view light distance projected shadow buffer
Computer Graphics • Texture Mapping © 2005 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 © 2005 Fabio Pellacini • 46
Environment Mapping
• graphics pipeline does not allow reflections• we can use texturing and a multipass algorithm
[Wol
fe /
SG
97 S
lide
set]
Computer Graphics • Texture Mapping © 2005 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 © 2005 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
Computer Graphics • Texture Mapping © 2005 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 © 2005 Fabio Pellacini • 50
Texturing DemosOpenGL tutor:
texture.exe
NVidia samples:bumpy_shiny_patch.exe
hw_shadowmap_simple.exesimple_soft_shadows.exe