notesonly.in

One notebook for every subject — open it anywhere.

Log in

Texture Mapping in Computer Graphics With easy examples.

Texture mapping wraps a two-dimensional image, called a texture, around a 3D object — like wrapping printed paper around a box. Instead of modelling every detail in 3D, it paints details from the image onto the surface — bricks on a wall, patterns on cloth, labels on bottles.

It makes graphics fast and realistic at once: a brick wall needs only a flat box plus one photograph to look almost real in a game, while modelling each brick would need thousands of shapes and slow everything down.

Key Concepts

  • Texture and texel — the 2D image applied to a surface; one pixel of it is called a texel.
  • UV coordinates — each vertex carries a (u, v) pair in the range 0 to 1 saying which texture point it touches — the shape is "unwrapped" into flat UV space, like peeling an orange and flattening the peel.
  • Texture filtering — when texels do not line up with screen pixels, neighbours are blended: Nearest picks the closest texel (fast but blocky); bilinear averages the 4 nearest (smoother); trilinear also blends mipmap levels.
  • Mipmaps — pre-computed smaller copies, each half the width and height of the previous one, so distant objects use a cheaper version without shimmering.
  • Wrapping modes — for UV coordinates outside the 0–1 range: repeat tiles the image, clamp stretches the edge pixels, mirror flips it back and forth.

Formulas

  • Texel lookup: UV (u, v) on a W × H texture maps to pixel (u × W, v × H): on a 256 × 256 texture, (0.5, 0.25) samples texel (128, 64).
  • Texture memory: memory = width × height × bytes per pixel: a 1024 × 1024 RGB texture needs about 3 MB, or about 4 MB with full mipmaps (roughly 4/3 of the base).
  • Bilinear blend: the sampled colour is the closeness-weighted average of the 4 surrounding texels — this removes blocky edges when a texture is magnified.

Worked Example

A 512 × 512 wood texture in RGB (3 bytes per pixel) is loaded with mipmaps. How much GPU memory does it use, and which texel sits at UV (0.75, 0.125)?

  1. Base level: 512 × 512 = 262,144 texels × 3 bytes = 786,432 bytes = 768 KB.
  2. Each mipmap level is one quarter the size of the previous one, so the series 768 KB + 192 KB + 48 KB + … sums to about 4/3 of the base: 768 × 4/3 ≈ 1,024 KB = 1 MB.
  3. Texel lookup: x = 0.75 × 512 = 384, y = 0.125 × 512 = 64, so the renderer samples texel (384, 64).
  4. Result: 1 MB of GPU memory, one texel lookup — tiny costs for a richly detailed surface.

Common Misconceptions

  • "A bigger texture always looks better." Not on its own — a 4K texture on a small, far-away object wastes memory and can shimmer; what matters is resolution relative to on-screen size.
  • "Texture mapping changes the shape." It only paints the surface: a brick-textured wall keeps a flat silhouette; true bumps need normal maps or real geometry.

Real-World Applications

  • Video games and films wrap textures onto characters, terrain and props to look real without heavy geometry.
  • Architectural visualisation applies wood, marble and fabric textures so clients can preview the finished look.
  • Map apps drape satellite photographs over 3D terrain as textures to build the view you see from above.

Texture mapping lets a simple 3D shape wear a detailed skin. With UV coordinates, filtering and mipmaps, engines render sharp, realistic surfaces fast — which is why almost every textured object in games and films relies on it.