Texture Mapping Objectives the Limits of Geometric Modeling
Total Page:16
File Type:pdf, Size:1020Kb
Objectives •Introduce Mapping Methods Texture Mapping - Texture Mapping - Environment Mapping - Bump Mapping CS 432 Interactive Computer Graphics •Consider basic strategies Prof. David E. Breen - Forward vs backward mapping Department of Computer Science - Point sampling vs area averaging E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 2 1 2 The Limits of Geometric Modeling an Orange Modeling •Although graphics cards can render over •Consider the problem of modeling an orange 20 million polygons per second, that (the fruit) number is insufficient for many phenomena •Start with an orange-colored sphere - Clouds - Too simple - Grass •Replace sphere with a more complex shape - Terrain - Does not capture surface characteristics (small - Skin dimples) - Takes too many polygons to model all the dimples E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 3 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 4 3 4 Modeling an Orange (2) Three Types of Mapping •Take a picture of a real orange, scan it, •Texture Mapping and “paste” onto simple geometric model - Uses images to fill inside of polygons - This process is known as texture mapping •Environment (reflection mapping) •Still might not be sufficient because - Uses a picture of the environment for texture resulting surface will be smooth maps - Need to change local shape - Allows simulation of highly specular surfaces - Bump mapping •Bump mapping - Emulates altering normal vectors during the rendering process E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 5 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 6 5 6 1 Texture Mapping Environment Mapping geometric model texture mapped E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 7 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 8 7 8 Bump Mapping Where does mapping take place? • Mapping techniques are implemented at the end of the rendering pipeline - Very efficient because few polygons make it past the clipper G eometry Fragment Frame Vertices Rasteriz ation processing processing buffer Pixel Pixels processing E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 9 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 10 9 10 Is it simple? Coordinate Systems •Although the idea is simple---map an •Parametric coordinates image to a surface---there are 3 or 4 - May be used to model curves and surfaces coordinate systems involved •Texture coordinates - Used to identify points in the image to be mapped •Object or World Coordinates - Conceptually, where the mapping takes place 2D image •Window Coordinates - Where the final image is really produced 3D surface E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 11 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 12 11 12 2 Texture Mapping Mapping Functions •Basic problem is how to find the maps parametric coordinates •Consider mapping from texture coordinates to a point a surface •Appear to need three functions (x,y,z) x = x(s,t) y = y(s,t) t z = z(s,t) •But we really want s texture coordinates to go the other way window coordinates world coordinates E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 13 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 14 13 14 Backward Mapping Two-part mapping • We really want to go backwards •One solution to the mapping problem is to - Given a pixel, we want to know to which point first map the texture to a simple on an object it corresponds intermediate surface - Given a point on an object, we want to know to which point in the texture it corresponds •Example: map to cylinder • Need a map of the form s = s(x,y,z) t = t(x,y,z) • Such functions are difficult to find in general E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 15 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 16 15 16 Cylindrical Mapping Spherical Map parametric cylinder We can use a parametric sphere x = r cos 2p u x = r cos 2pu y = r sin 2pu y = r sin 2pu cos 2pv z = v/h z = r sin 2pu sin 2pv maps rectangle in u,v space to cylinder of radius r and height h in world coordinates in a similar manner to the cylinder but have to decide where to put s = u the distortion t = v maps from texture space Spheres are used in environmental maps E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 17 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 18 17 18 3 Box Mapping Second Mapping •Easy to use with simple orthographic • Map from intermediate object to actual object projection - Normals from intermediate to actual •Also used in environment maps - Normals from actual to intermediate - Vectors from center of intermediate actual intermediate E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 19 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 20 19 20 Aliasing Area Averaging •Point sampling of the texture can lead to A better but slower option is to use area averaging aliasing errors miss blue stripes point samples in u,v (or x,y,z) space preimage pixel Note that preimage of pixel is curved point samples in texture space E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 21 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 22 21 22 WebGL Texture Mapping Go to ART Texture Mapping slides E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 23 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 24 23 24 4 Objectives Basic Stragegy •Introduce WebGL texture mapping Three steps to applying a texture - two-dimensional texture maps 1. specify the texture - assigning texture coordinates • read or generate image - forming texture images • assign to texture • enable texturing 2. assign texture coordinates to vertices • Proper mapping function is left to application 3. specify texture parameters • wrapping, filtering Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 25 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 26 25 26 Texture Mapping Texture Example •The texture (below) is a y 256 x 256 image that has been mapped to a z x geometry display rectangular polygon which is viewed in perspective t image s Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 27 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 28 27 28 Texture Mapping and the Specifying a Texture Image WebGL Pipeline •Images and geometry flow through • Define a texture image from an array of separate pipelines that join during texels (texture elements) in CPU memory fragment processing • Use an image in a standard format such as JPEG - “complex” textures do not affect geometric - Scanned image complexity - Generate by application code • WebGL1 only supports 2 dimensional texture maps vertices geometry pipeline - Dimensions should be power of 2 for mip-mapping fragment • These restrictions removed in WebGL 2, and now image texel pipeline processor supports many texture types • We’ll still focus on 2D textures E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 29 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 31 29 31 5 Define Image as a Texture A Checkerboard Image gl.texImage2D( target, level, internalformat, var image1 = new Uint8Array(4*texSize*texSize); w, h, border, format, type, texels ); for ( var i = 0; i < texSize; i++ ) { for ( var J = 0; J <texSize; J++ ) { target: type of texture, e.g. gl.TEXTURE_2D var patchx = Math.floor(i/(texSize/numChecks)); level: used for mipmapping (discussed later) var patchy = Math.floor(J/(texSize/numChecks)); internalformat: elements per texel if (patchx%2 ^ patchy%2) c = 255; w, h: width and height of texels in pixels else c = 0; border: width of the border. Must be 0. //c = 255*(((i & 0x8) == 0) ^ ((j & 0x8) == 0)) format: must be the same as internalformat image1[4*i*texSize+4*j] = c; type: data type of texel data image1[4*i*texSize+4*j+1] = c; texels: source of texel data image1[4*i*texSize+4*j+2] = c; image1[4*i*texSize+4*j+3] = 255; glTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 512, 512, } 0, gl.RGBA, gl.UNSIGNED_BYTE, my_texels); Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 32 } Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 33 32 33 Using a GIF image Mapping a Texture // specify image in JS file • Based on parametric texture coordinates var image = new Image(); image.src = "SA2011_black.gif” • Specify as a 2D vertex attribute • Interpolated by the rasterizer window.onload = function() { Texture Space Object Space configureTexture( image ); t } 1, 1 (s, t) = (0.2, 0.8) 0, 1 A a // or specify image in HTML file with <img> tag // <img id = "texImage" src = "SA2011_black.gif"></img> c (0.4, 0.2) b var image = document.getElementbyId("texImage”) B C window.onload = configureTexture( image ); 0, 0 1, 0 s (0.8, 0.4) Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 34 Angel and Shreiner: Interactive Computer