Computer Graphics (Fall 2005)To DoThis Lecture: Texture MappingAdding Visual DetailParameterizationOption: Varieties of projectionsOption: unfold the surfaceOption: make an atlasOption: it’s the artist’s problemOutlineHow to map object to texture?Idea: Use Map ShapePlanar mappingCylindrical MappingSpherical MappingCube MappingSlide 17Slide 181st idea: Gouraud interp. of texcoordsArtifactsInterpolating ParametersTexture MappingSlide 23Perspective-Correct InterpolationTexture Map FilteringMip MapsMIP-map ExampleSlide 28Texture Mapping ApplicationsModulation texturesBump MappingDisplacement MappingIllumination MapsEnvironment MapsSolid texturesProcedural Texture GallerySlide 37Slide 38Slide 39Slide 40Slide 41Where we’re going with courseComputer Graphics (Fall 2005)Computer Graphics (Fall 2005)COMS 4160, Lecture 20: Texture Mappinghttp://www.cs.columbia.edu/~cs4160Many slides from Greg Humphreys, UVA andRosalee Wolfe, DePaul tutorial teaching texture mapping visuallyTo DoTo DoWork on HW4 milestonePrepare for final push on HW 4No final exam. HW 4, written ass 2 Issues with OpenGL/coding? Some people difficulties with HW 3 Some issues with skeleton codeThis Lecture: Texture MappingThis Lecture: Texture MappingImportant topic: nearly all objects texturedWood grain, faces, bricks and so onAdds visual detail to scenesMeant as a fun and practically useful lectureBut not tested specifically on itPolygonal modelWith surface textureAdding Visual DetailAdding Visual DetailBasic idea: use images instead of more polygons to represent fine scale color variationParameterizationParameterizationgeometrygeometry++==imageimagetexture maptexture map•Q: How do we decide where on the geometryeach color from the image should go?Option: Varieties of projectionsOption: Varieties of projections[Paul Bourke][Paul Bourke]Option: unfold the surfaceOption: unfold the surface[Piponi2000]Option: make an atlasOption: make an atlas[Sander2001]charts atlas surfaceOption: it’s the artist’s problemOption: it’s the artist’s problemOutlineOutlineTypes of projectionsInterpolating texture coordinates Broader use of texturesHow to map object to texture?How to map object to texture?To each vertex (x,y,z in object coordinates), must associate 2D texture coordinates (s,t)So texture fits “nicely” over objectIdea: Use Map ShapeIdea: Use Map ShapeMap shapes correspond to various projectionsPlanar, Cylindrical, SphericalFirst, map (square) texture to basic map shapeThen, map basic map shape to objectOr vice versa: Object to map shape, map shape to squareUsually, this is straightforwardMaps from square to cylinder, plane, sphere well definedMaps from object to these are simply spherical, cylindrical, cartesian coordinate systemsPlanar mappingPlanar mappingLike projections, drop z coord (s,t) = (x,y)Problems: what happens near z = 0?Cylindrical MappingCylindrical MappingCylinder: r, θ, z with (s,t) = (θ/(2π),z)Note seams when wrapping around (θ = 0 or 2π)Spherical MappingSpherical MappingConvert to spherical coordinates: use latitude/long.Singularities at north and south polesCube MappingCube MappingCube MappingCube MappingOutlineOutlineTypes of projectionsInterpolating texture coordinates Broader use of textures11stst idea: Gouraud interp. of texcoords idea: Gouraud interp. of texcoordsScan line1I2I3I1y2y3ysyaIbI1 2 2 11 2( ) ( )s saI y y I y yIy y- + -=-1 3 3 11 3( ) ( )s saI y y I y yIy y- + -=-( ) ( )a b p b p aab aI x x I x xIx x- + -=-pIActual implementation efficient: difference equations while scan convertingArtifactsArtifactsMcMillan’s demo of this is at http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide05.htmlAnother example http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide06.htmlWhat artifacts do you see?Why?Why not in standard Gouraud shading?Hint: problem is in interpolating parametersInterpolating ParametersInterpolating ParametersThe problem turns out to be fundamental to interpolating parameters in screen-spaceUniform steps in screen space uniform steps in world spaceTexture MappingTexture MappingLinear interpolationof texture coordinatesCorrect interpolationwith perspective divideHill Figure 8.42Interpolating ParametersInterpolating ParametersPerspective foreshortening is not getting applied to our interpolated parametersParameters should be compressed with distanceLinearly interpolating them in screen-space doesn’t do thisPerspective-Correct InterpolationPerspective-Correct InterpolationSkipping a bit of math to make a long story short…Rather than interpolating u and v directly, interpolate u/z and v/z These do interpolate correctly in screen spaceAlso need to interpolate z and multiply per-pixelProblem: we don’t know z anymoreSolution: we do know w 1/zSo…interpolate uw and vw and w, and compute u = uw/w and v = vw/w for each pixelThis unfortunately involves a divide per pixelhttp://graphics.lcs.mit.edu/classes/6.837/F98/Lecture21/Slide14.htmlTexture Map FilteringTexture Map FilteringNaive texture mapping aliases badly Look familiar?int uval = (int) (u * denom + 0.5f);int vval = (int) (v * denom + 0.5f);int pix = texture.getPixel(uval, vval);Actually, each pixel maps to a region in texture|PIX| < |TEX| Easy: interpolate (bilinear) between texel values |PIX| > |TEX|Hard: average the contribution from multiple texels|PIX| ~ |TEX|Still need interpolation!Mip MapsMip MapsKeep textures prefiltered at multiple resolutionsFor each pixel, linearly interpolate between two closest levels (e.g., trilinear filtering) Fast, easy for hardwareWhy “Mip” maps?MIP-map ExampleMIP-map ExampleNo filtering:MIP-map texturing:AAAAAAAGHMY EYES ARE BURNINGWhere are my glasses?OutlineOutlineTypes of projectionsInterpolating texture coordinates Broader use of texturesTexture Mapping ApplicationsTexture Mapping ApplicationsModulation, light mapsBump mappingDisplacement mappingIllumination or Environment MappingProcedural texturingAnd many moreModulation texturesModulation textures)))()(((),(SSTTLLLnSDAAEIKIKISRVKLNKIKItsTI --)))()(((),(SSTTLLLnSDAAEIKIKISRVKLNKIKItsTI --Map texture values to scale factorWood textureTexturevalueBump MappingBump MappingTexture = change in surface normal!Sphere
View Full Document