Here is a excerpt from Peter Shirley's Fundamentals of computer graphics:
11.1.2 Texture Arrays
We will assume the two dimensions to be mapped are called u and v. We also assume we have an nx and ny image that we use as the texture. Somehow we need every (u,v) to have an associated color found from the image. A fairly standard way to make texturing work for (u,v) is to first remove the integer portion of (u,v) so that it lies in the unit square. This has the effect of "tiling" the entire uv plane with copies of the now-square texture. We then use one of the three interpolation strategies to compute the image color for the coordinates.
My question is: What are the integer portion of (u,v)? I thought u,v are 0 <= u,v <= 1.0. If there is an integer portion, shouldn't we be dividing u,v by the texture image width and height to get the normalized u,v values?
UV values can be less than 0 or greater than 1. The reason for dropping the integer portion is that UV values use the fractional part when indexing textures, where (0,0), (0,1), (1,0) and (1,1) correspond to the texture's corners. Allowing UV values to go beyond 0 and 1 is what enables the "tiling" effect to work.
For example, if you have a rectangle whose corners are indexed with the UV points (0,0), (0,2), (2,0), (2,2), and assuming the texture is set to tile the rectangle, then four copies of the texture will be drawn on that rectangle.
The meaning of a UV value's integer part depends on the wrapping mode. In OpenGL, for example, there are at least three wrapping modes:
GL_REPEAT
- The integer part is ignored and has no meaning. This is what allows textures to tile when UV values go beyond 0 and 1.GL_MIRRORED_REPEAT
- The fractional part is mirrored if the integer part is odd.GL_CLAMP_TO_EDGE
- Values greater than 1 are clamped to 1, and values less than 0 are clamped to 0.