Texturing Anthony Steed 1999, Celine Loscos 2000-2005, Jan Kautz 2006-2009 Texture Mapping Have seen: colour can be assigned to ver7ces But: don t want to represent all this detail with geometry Texture Mapping Considering small details We may not want to add polygons to represent every detail Instead, prefer to keep a large polygon and use an image to represent the details Images: Wikimedia 1
The Quest for Visual Realism Model Model + Shading Model + Shading + Textures Texture Mapping Increase the apparent complexity of simple geometry Efficient packing of flat detail Like wallpapering or gik wrapping with stretchy paper Texture Mapping Standard texture mapping modifies diffuse component Pas7ng a picture onto the polygon A texture is a 2D array of texels storing RGB (or RGBA) components 2
Difference between pixels and texels There can be a different match between the pixels of the display window and the texel of the texture Overview Texture mapping Inverse and Forward Mapping Bilinear interpola7on Perspec7ve correc7on Mipmapping Other forms of mapping Environment Bump mapping Inverse Mapping Each vertex is associated with a point on an image (u,v) 3
Forward Mapping For points in the image, map onto the polygon much harder to implement correctly, and harder to model Inverse mapping is much more commonly used Most 3D modelers output U,V co ordinates for texture applica7on Quick and Dirty Solu7on Yet more parameters in the ET! Bilinear interpola7on of u&v down polygon edges, and across scan lines Works, but is very ugly Does not consider fore shortening of image in depth The Problem Same problem exists with Phong and Gouraud shading, but MUCH less no7ceable 4
The Solu7on Need to compensate for fore shortening by interpola7ng over 1/z Interpolate (u,v,q) where q=1/z At ver7ces we know (u 1,v 1,z 1 ), (u 2,v 2,z 2 ) Interpolate between (u1/z1,v1/z1,1/z1) and (u 2 / z 2,v 2 /z 2,1/z 2 ) to get (u,v,q) Restore u,v, by dividing u and v by q Sanity Check p i =(x i,y i,z i,u i,v i ) p1=(15,15,20,0,1) p0=(10,5,10,0,0) scanlines Y=15 Y=10 Y=5 At p0 (u,v,q) = (0,0,0.1) At p1 (u,v,q) = (0,0.05,0.05) On scanline 10 (u,v,q) = (0,0.025,0.075) (u,v) = (0,0.333) z = 1/0.075 = 13.33 Minor Issues Now have two divisions per pixel! Some op7misa7ons only do the division at end of the spans and interpolate across spans or only do the division every n pixels Remaining problem we have not touched upon how to clip u,v values in 3D or 2D! 5
Picking your pixel! Major Issues image Sampling A pixel maps to a non rectangular region Usually only perform map on centre of pixel S7ll have a problem of over sampling (same texel maps to several pixels) or under sampling the image (pixels only sparsely sample the texels) Filtering Nearest neighbour Bilinear Pick pixel with closest centre Weighted average based on distance to pixel centre 6
Filtering Bilinear filtering (par7ally) solves the oversampling problem since it provides smooth shading between pixels scanline Mip Mapping When undersampling we use mip mapping Resample image at lower resolu7on Create a pyramid of textures. Interpolate texture between two adjacent layers Texture Pyramid 128x128 64x64 32x32... 1x1 7
Sampling Choose two layers based on texel span Choice is made selec7ng the two levels where the du and dv for dx and dy are closest to one Interpolate between four pixels in higher layer and four (or one) in lower layer Filtering Examples Nearest Neighbor Bilinear Filtering Bilinear Filtering (distinct mip map levels) Trilinear Filtering (Mip mapping) Images from: http://www.3dcenter.org/artikel/2003/10-26_a_english.php More Examples Nearest Neighbor Mip Mapping 8
Texture Mapping Difficul7es Tedious to specify texture coordinates Acquiring textures is surprisingly difficult Photographs have projec7ve distor7ons Varia7ons in reflectance and illumina7on Tiling problems Other Forms of Texture Mapping Bump Mapping Displacement Mapping Environment Mapping Bump Mapping Use textures to alter the surface normal Does not change the actual shape of the surface Just shaded as if it were a different shape Sphere w/diffuse Texture Swirly Bump Map Sphere w/diffuse Texture & Bump Map 9
Bump Mapping Treat the texture as a single valued height func7on Compute the normal from the par7al deriva7ves in the texture Another Bump Map Example Bump Map Cylinder w/diffuse Texture Map Cylinder w/texture Map & Bump Map What's Missing? There are no bumps on the silhouene of a bump mapped object Bump maps don t allow self occlusion or self shadowing 10
Displacement Mapping Use the texture map to actually move the surface point The geometry must be displaced before visibility is determined Displacement Mapping Image from: Geometry Caching for Ray Tracing Displacement Maps by Man Pharr and Pat Hanrahan. Note the detailed shadows cast by the stones Environment Maps We can simulate reflec7ons by using the direc7on of the reflected ray to index a spherical texture map at "infinity". Assumes that all reflected rays begin from the same point. 11
What's the Best Layout? Cube Map Environment Mapping Example Terminator II Rasteriza7on Z Buffer for visibility Recap Need to do perspec7ve correct rasteriza7on Texture Mapping Forward / backward Adds detail Need to take care of sampling issues 12