What Is Texture Mapping?
Collapse the table of content
Expand the table of content

What Is Texture Mapping?

Texture mapping is the process of determining where in a particular space a texture will be applied.

A texture consists of a series of pixels (also called texels), each occupying a texture coordinate determined by the width and height of the texture. These texture coordinates are then mapped into values ranging from 0 to 1 along a u and v axes (u is width, v is height). This process is called UV mapping. The resulting coordinates are UV coordinates.

Whenever you render a polygon, a UV coordinate is calculated for each vertex in the triangle. These three UV coordinates dictate how a texture is applied to the polygon by the pixel shader. When the u or v values move below 0 or above 1, the polygon is applied according to the texture address mode that has been set. When TextureAddressMode.Border is in effect, any pixels where the UV mapping is outside the 0-1 range are colored with the border color. When TextureAddressMode.Clamp is in effect, the color of the nearest pixel is used. TextureAddressMode.Wrap indicates that the texture should repeat across the triangle. When you specify TextureAddressMode.Mirror, the texture wraps, but reverses itself when it crosses a UV boundary. Texture-addressing modes are specified for each axis separately, so you could wrap along the u-axis while clamping the v-axis.

If the texture is too large or too small for the polygon, the texture must be filtered to fit the space. There are two types of filtering that can be applied to textures: magnification and minification. A magnification filter enlarges a texture to fit a polygon. A minification filter reduces the texture to fit into a smaller area. Texture magnification is normally straightforward, and results in a blurrier image. Texture minification is more complicated, and improper minification can result in aliasing – that is, jagged edges.

The most popular approach to minification is to create mipmaps for each texture. A mipmap is a pre-shrunk texture, normally half the size of the original. The mipmap itself then gets mipmapped, and this process continues until a 1x1 texture is created. This is the final mipmap for the texture. You can think of mipmaps as a chain, starting with the original texture and becoming smaller and smaller until the 1 texel texture is reached. When minification is needed, first the appropriate mipmapped texture is chosen, then that mipmap is applied to the object, with real-time texture filtering if needed. The default Texture processor for the Content Pipeline has an option to generate mipmaps automatically.

XNA supports five texture filters. TextureFilter.Point uses the nearest corresponding point on the texture, with no filtering. TextureFilter.Linear uses bilinear interpolation to sample four neighboring texels and create an average value. TextureFilter.PyramidalQuad also uses four samples and favors texels nearer to the center of the resulting pixel when calculating the final result. The TextureFilter.GaussianQuad works the same way, using a different mathematical weighting - similar to a bell curve where the top of the curve is the center of the resulting pixel. TextureFilter.Anisotropic is a filtering method designed for surfaces that are not facing the camera (such as the ground near a horizon).

Community Additions

© 2016 Microsoft