Texture MappingSlide 2Texture MapTexture CoordinatesSlide 5Vertex ClassTexture InterpolationPerspective CorrectionPixel RenderingSlide 10TilingSlide 12ClampingMirroringCombinationsTexture SpaceMagnificationSlide 18MinificationSlide 20Slide 21MipmappingSlide 23Mipmapping LimitationsAnisotropic MipmappingEliptical Weighted AveragingAntialiasingBasic Texture MappingTexture Coordinate AssignmentOrthographic MappingPerspective MappingSpherical MappingCylindrical MappingSkin MappingsEnvironment MappingSlide 36Cube MappingSolid TexturesTexture CombiningBump MappingDisplacement MappingTexture MappingCSE167: Computer GraphicsInstructor: Steve RotenbergUCSD, Fall 2005Texture MappingTexture mapping is the process of mapping an image onto a triangle in order to increase the detail of the renderingThis allows us to get fine scale details without resorting to rendering tons of tiny trianglesThe image that gets mapped onto the triangle is called a texture map or texture and is usually a regular color imageTexture MapWe define our texture map as existing in texture space, which is a normal 2D spaceThe lower left corner of the image is the coordinate (0,0) and the upper right of the image is the coordinate (1,1)The actual texture map might be 512 x 256 pixels for example, with a 24 bit color stored per pixelTexture CoordinatesTo render a textured triangle, we must start by assigning a texture coordinate to each vertexA texture coordinate is a 2D point [tx ty] in texture space that is the coordinate of the image that will get mapped to a particular vertexTexture Mappingv0v1v2t2t0t1(1,1)(0,0)xyTexture Space Triangle (in any space)Vertex ClassWe can extend our concept of a Model to include texture coordinatesWe can do this by simply extending the Vertex class:class Vertex {Vector3 Position;Vector3 Color;Vector3 Normal;Vector2 TexCoord;public:void Draw() {glColor3f(Color.x, Color.y, Color.z);glNormal3f(Normal.x, Normal.y, Normal.z);glTexCoord2f(TexCoord.x, TexCoord.y);glVertex3f(Position.x, Position.y, Position.z); // This has to be last}};Texture InterpolationThe actual texture mapping computations take place at the scan conversion and pixel rendering stages of the graphics pipelineDuring scan conversion, as we are looping through the pixels of a triangle, we must interpolate the txty texture coordinates in a similar way to how we interpolate the rgb color and z depth valuesAs with all other interpolated values, we must precompute the slopes of each coordinate as they vary across the image pixels in x and yOnce we have the interpolated texture coordinate, we look up that pixel in the texture map and use it to color the pixelPerspective CorrectionThe scan conversion process usually uses linear interpolation to interpolate values across the triangle (colors, z, etc.)If we use linear interpolation to interpolate the texture coordinates, we may run into inaccuraciesThis is because a straight line of regularly spaced points in 3D space maps to a straight line of irregularly spaced points in device space (if we are using a perspective transformation)The result is that the texture maps exactly onto the triangle at the vertices, but may warp and stretch within the triangle as the viewing angle changesThis is known as texture swimming and can be quite distracting on large trianglesTo fix the problem, we must perform a perspective correct interpolation, or hyperbolic interpolationThis requires interpolating the w coordinate across the triangle and performing a perspective division for each pixelSee page 121 & 128 in the book for more infoPixel RenderingUsually, we want to combine texture mapping with lightingLet’s assume that we are doing vertex lighting and using Gouraud shading to interpolate the lit colors across the triangleAs we render each pixel, we compute the interpolated light color and multiply it by the texture color to get our final pixel colorOften, when we are using texture maps, we don’t need to use vertex colors, and so they are implicitly set to (1,1,1)The texture map itself usually defines the material color of the object, and it is allowed to vary per pixel instead of only per vertexPixel RenderingLet’s consider the scan conversion process once again and look at how the pixel rendering process fits inRemember that in scan conversion of a triangle, we loop from the top row down to the bottom row in y, and then loop from left to right in x for each rowAs we are looping over these pixels, we are incrementing various interpolated values (such as z, r, g, b, tx, and ty)Each of these increments requires only 1 addition per pixel, but perspective correction requires 1 an additional divide per pixel and 1 additional multiply per pixel for each perspective corrected valueBefore actually writing the pixel, we compare the interpolated z value with the value written into the zbuffer, stored per pixel. If it is further than the existing z value, we don’t render the pixel and proceed to the next one. If it is closer, we finish rendering the pixel by writing the final color into the framebuffer and the new z value into the zbufferIf we are doing expensive per-pixel operations (such as Phong interpolation & per-pixel lighting), we can postpone them until after we are sure that the pixel passes the zbuffer comparison. If we are doing a lot of expensive per-pixel rendering, it is therefore faster if we can render closer objects firstTilingThe image exists from (0,0) to (1,1) in texture space, but that doesn’t mean that texture coordinates have to be limited to that rangeWe can define various tiling or wrapping rules to determine what happens when we go outside of the 0…1 rangeTilingxyTexture Space(0,0)(1,1)ClampingxyTexture Space(0,0)(1,1)MirroringxyTexture Space(0,0)(1,1)CombinationsOne can usually set the tiling modes independently in x and ySome systems support independent tiling modes in x+, x-, y+, and y-Texture SpaceLet’s take a closer look at texture spaceIt’s not quite like the normalized image space or device spaces we’ve seen so farThe image itself ranges from 0.0 to 1.0, independent of the actual pixel resolutionIt allows tiling of values <0 and >1The individual pixels of the texture are called texelsEach texel maps to a uniform sized box in texture space. For example, a 4x4 texture would have pixel centers at 1/8, 3/8, 5/8, and
View Full Document