Textures and Color Spaces

Load image textures with TextureLoader and learn UVs, color maps, normal maps, wrapping, and color space settings.

🎯 Introduction

By the end of this article, you will be able to apply images to geometry, understand how UVs position them, distinguish color, normal, roughness, and metalness maps, and avoid washed-out or overly dark colors.

🧱 TextureLoader and map

A texture is an image or pixel data used by the GPU. TextureLoader loads images, and a material's map uses one as a color map:

import * as THREE from 'three';

const texture = new THREE.TextureLoader().load(
    '/textures/wood-color.jpg',
    () => console.log('Texture loaded'),
    (event) => console.log(`Loaded ${event.loaded} bytes`),
    (error) => console.error('Failed to load texture', error)
);
texture.colorSpace = THREE.SRGBColorSpace;

const material = new THREE.MeshStandardMaterial({ map: texture });

map is not the texture file itself. It is the material property that selects an image for its base color. colorSpace tells Three.js how to interpret the image's numbers as visible colors. If either is missing, loading may succeed while the rendered result remains incorrect.

In a web project, place images in the static asset directory and load them from browser-accessible URLs such as /textures/wood-color.jpg. The current page must be able to access them. For assets on another domain, confirm that the server permits cross-origin loading. With a bundler, you can also use its asset import mechanism.

🧭 UVs, repeating, and filtering

UVs are two-dimensional coordinates on geometry, typically from 0 to 1: the bottom-left is near (0, 0) and the top-right near (1, 1). Built-in geometries include UVs; custom BufferGeometry requires you to supply them.

To repeat a pattern, configure wrapping and repeat counts. wrapS controls the horizontal direction and wrapT the vertical direction. The default ClampToEdgeWrapping stretches edge pixels. Switch to RepeatWrapping for repeat to tile the image:

texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(3, 2);

This repeats the image 3 times horizontally and 2 times vertically, useful for continuous patterns on floors and walls.

When magnifying an image, magFilter affects smoothness. When minifying it, Three.js uses mipmaps by default to help stabilize the result. Validate texture dimensions, compression, and repeat counts on actual devices.

Mipmaps are a precomputed set of smaller image versions. As an object recedes, an appropriately sized version reduces texture shimmering and sampling cost. They are auxiliary GPU versions for minification, rather than separate application images.

🎨 Common maps and color spaces

const material = new THREE.MeshStandardMaterial({
    map: colorTexture,
    normalMap,
    roughnessMap,
    metalnessMap,
});
  • Color maps define surface colors. Set colorSpace = THREE.SRGBColorSpace.
  • Normal maps encode small surface variations as colors without changing the actual silhouette.
  • Roughness maps control highlight spread across the surface.
  • Metalness maps control metallic behavior across the surface.

Color maps and data maps are processed differently. The renderer typically also needs this setting:

renderer.outputColorSpace = THREE.SRGBColorSpace;

Without an sRGB annotation, color maps may look washed out. Incorrectly treating normal or roughness data maps as sRGB also distorts lighting calculations.

Think of sRGB as a color encoding for displays and image files, and linear space as the numerical space suitable for lighting calculations. Color maps usually use sRGB input; normal, roughness, and metalness maps contain calculation data and must not be treated as color images.

This demo uses a procedurally generated pattern to show texture repeating and the resulting surface appearance:

Texture paths in the documentation must point to real files. If loading fails, check the public directory, case, filenames, and deployed static asset paths first.

🧾 Summary

  • TextureLoader loads images; a material's map uses a color texture.
  • UVs determine how 2D images map onto 3D surfaces.
  • RepeatWrapping and repeat tile patterns.
  • Color, normal, roughness, and metalness maps serve different purposes.
  • Color maps use sRGB; data maps retain linear data handling.

❓ Questions and answers

Q1: Why is there no image on the object after the texture loads?

Confirm that the material uses map, that the scene uses this material, and that the geometry has a UV attribute.

Q2: Why do the edges stretch after I set repeat?

Set both wrapS and wrapT to RepeatWrapping first. The default wrapping mode does not repeat.

Q3: Does a normal map make the model's silhouette more complex?

No. It only changes surface directions used in lighting calculations. Geometry vertices still determine the silhouette.

🧪 Exercise

Load an image onto a plane and repeat it 4 × 4 times. Then change magFilter and minFilter separately to compare magnification and minification.

// Write your code here

🎉 Textures add rich detail to simple geometry. Next, you will use a scene graph to manage related objects.