computer graphics • texture mapping © 2006 fabio pellacini • 1 why texture mapping?
• objects have spatially varying details • represent as geometry: correct, but very expensive
computer graphics • texture mapping © 2006 fabio pellacini • 2 why texture mapping?
• use simple geometry • store varying properties in images • map to objects [Wolfe / SG97 Slide set] [Wolfe / SG97
computer graphics • texture mapping © 2006 fabio pellacini • 3 why texture mapping?
• produces compelling results [Jeremy Birn]
computer graphics • texture mapping © 2006 fabio pellacini • 4 why texture mapping?
• easily change object appearance [Praun et al., 2001]
computer graphics • texture mapping © 2006 fabio pellacini • 5 mapping function
• surfaces are 2d domains • determine a function that maps them to images
Mapping Function
Surface Image
computer graphics • texture mapping © 2006 fabio pellacini • 6 mapping functions – projections
• maps 3d surface points to 2d image coordinates f ℜ3 → ]1,0[: 2
• different types of projections – often corresponding to simple shapes – useful for simple object [Wolfe / SG97 Slide set] [Wolfe / SG97 computer graphics • texture mapping © 2006 fabio pellacini • 7 projections – planar
computer graphics • texture mapping © 2006 fabio pellacini • 8 projections – cubical
computer graphics • texture mapping © 2006 fabio pellacini • 9 projections – cylindrical
computer graphics • texture mapping © 2006 fabio pellacini • 10 projections – spherical
computer graphics • texture mapping © 2006 fabio pellacini • 11 projections
• planar projection along xy plane of size (w,h) – use affine transform to orient the plane differently
f p = yx hpwp )/,/()( • spherical projection of unit sphere – consider point in spherical coordinates f p = φ θ ),()( • cylindrical projection of unit cylinder of height h – consider point in cylindrical coordinates – treat caps separately
f p = φ y hp )/,()(
computer graphics • texture mapping © 2006 fabio pellacini • 12 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 © 2006 fabio pellacini • 13 texture mapping artifacts
• tiling textures might introduce seems – discontinuities in the mapping function – change texture to be “tileable” when possible
computer graphics • texture mapping © 2006 fabio pellacini • 14 texture mapping artifacts
• mapping textures will introduce distortions – unavoidable artifacts • local scale and rotation differences
distorted undistorted computer graphics • texture mapping © 2006 fabio pellacini • 15 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 © 2006 fabio pellacini • 16 uv mapping subdivision surfaces
level 0 level 1 level 2
computer graphics • texture mapping © 2006 fabio pellacini • 17 uv mapping vs. projection
parameterization projection
computer graphics • texture mapping © 2006 fabio pellacini • 18 uv mapping parametric surfaces [Wolfe / SG97 Slide set] [Wolfe / SG97
computer graphics • texture mapping © 2006 fabio pellacini • 19 uv mapping polygon meshes
computer graphics • texture mapping © 2006 fabio pellacini • 20 uv mapping polygon meshes [Piponi et al., 2000]
computer graphics • texture mapping © 2006 fabio pellacini • 21 uv mapping polygon meshes
• break up model intro single texture [© Discreet]
computer graphics • texture mapping © 2006 fabio pellacini • 22 interpolating uv coordinates on meshes
• pay attention when rasterizing triangles – for raytracing just use baricentric coordinates
texture linear interp. perspective interp. [MIT OpenCourseware]
used also for colors computer graphics • texture mapping © 2006 fabio pellacini • 23 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 © 2006 fabio pellacini • 24 texture magnification
• linearly interpolate closest pixels in texture [MIT OpenCourseware]
texture rendered image computer graphics • texture mapping © 2006 fabio pellacini • 25 texture minification
• compute average of texture pixels projected onto each view pixels [MIT OpenCourseware]
texture rendered image computer graphics • texture mapping © 2006 fabio pellacini • 26 texture minification
• remember point-sampling introduces artifacts – need average of texture below a pixel [MIT OpenCourseware]
computer graphics • texture mapping © 2006 fabio pellacini • 27 mip-mapping
• approximate algorithm for computing filters • store texture at different resolution • look up the appropriate image based on its projected size [MIT OpenCourseware]
computer graphics • texture mapping © 2006 fabio pellacini • 28 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 [Wolfe / SG97 Slide set] [Wolfe / SG97
computer graphics • texture mapping © 2006 fabio pellacini • 29 types of mapping
computer graphics • texture mapping © 2006 fabio pellacini • 30 texture mapping material parameters
• diffuse coefficient
computer graphics • texture mapping © 2006 fabio pellacini • 31 texture mapping material parameters
• specular coefficient
computer graphics • texture mapping © 2006 fabio pellacini • 32 displacement mapping
• variations of surface positions, thus normals – requires fine tessellation of object geometry
computer graphics • texture mapping © 2006 fabio pellacini • 33 displacement mapping
• update position by displacing points along normal
d = + hNPP • recompute normals by evaluating derivatives – no closed form solution: do it numerically ∂ ∂ Δ ΔPPPP N ∝ × dd ≈ × dd d ∂ ∂ Δ Δvuvu
computer graphics • texture mapping © 2006 fabio pellacini • 34 bump mapping
• variation of surface normals – apply normal perturbation without updating positions
computer graphics • texture mapping © 2006 fabio pellacini • 35 bump mapping
• simple example: bump mapping xy plane
d = PP + vuhvuvu ),(),(),( N = ++= vuhvu ),( zyx
∂ ∂PP ⎛ ∂h ⎞ ⎛ ∂h ⎞ N ∝ × dd ⎜ += ⎟ ⎜ +× zyzx ⎟ = d ∂ ∂vu ⎝ ∂u ⎠ ⎝ ∂v ⎠ ∂h ∂h −= − yxz ∂u ∂v
computer graphics • texture mapping © 2006 fabio pellacini • 36 bump vs. displacement mapping
bump map displacement map
computer graphics • texture mapping © 2006 fabio pellacini • 37 bump vs. displacement mapping
bump map displacement map
computer graphics • texture mapping © 2006 fabio pellacini • 38 combining maps types
• combine multiple maps to achieve realistic effects
computer graphics • texture mapping © 2006 fabio pellacini • 39 lighting effects using texture mapping
computer graphics • texture mapping © 2006 fabio pellacini • 40 shadow mapping
• graphics pipeline does not allow shadow queries • we can use texturing and a multipass algorithm [NVIDIA/Everitt al.] et
project a color texture “project” a depth texture
computer graphics • texture mapping © 2006 fabio pellacini • 41 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 © 2006 fabio pellacini • 42 shadow mapping algorithm [NVIDIA/Everitt al.] et
camera view light view shadow buffer
computer graphics • texture mapping © 2006 fabio pellacini • 43 shadow mapping algorithm [NVIDIA/Everitt al.] et
camera view light distance projected shadow buffer
computer graphics • texture mapping © 2006 fabio pellacini • 44 shadow mapping limitations
• not enough resolution: blocky shadows – pixels in shadow buffer too large when projected
[Fernando et al., 2002]
• biasing: surfaces shadow themselves – remember the epsilon in raytracing – made much worst by resolution limitation computer graphics • texture mapping © 2006 fabio pellacini • 45 environment mapping
• graphics pipeline does not allow reflections • we can use texturing and a multipass algorithm [Wolfe / SG97 Slide set] [Wolfe / SG97
computer graphics • texture mapping © 2006 fabio pellacini • 46 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 © 2006 fabio pellacini • 47 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 © 2006 fabio pellacini • 48 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 © 2006 fabio pellacini • 49 texturing demos OpenGL tutor: texture.exe NVidia samples: bumpy_shiny_patch.exe hw_shadowmap_simple.exe simple_soft_shadows.exe computer graphics • texture mapping © 2006 fabio pellacini • 50