Atlaslog
Atlaslog / three.js / Tutorial / Textures and mapping
three.js · Tutorial

Textures and mapping

Quick answer

This tutorial focuses on texture color space and sampling settings, the usual causes of dark or blurry surfaces. It loads a color map with TextureLoader, marks it SRGBColorSpace, sets RepeatWrapping, repeat and maximum anisotropy, then shows how data maps must stay linear. It builds a one-dimensional gradient CanvasTexture for thematic ramps and explains how UV coordinates control tiling. Readers can texture terrain and custom geometry without color shifts or stretching.

Last verified 2026-11-03 · three.js 0.160.0 · Cite this page
Key points
Example
const loader = new THREE.TextureLoader();

const colorMap = loader.load('/textures/terrain-color.jpg', function (tex) {
  tex.colorSpace = THREE.SRGBColorSpace;
  tex.wrapS = THREE.RepeatWrapping;
  tex.wrapT = THREE.RepeatWrapping;
  tex.repeat.set(4, 4);
  tex.anisotropy = renderer.capabilities.getMaxAnisotropy();
  tex.needsUpdate = true;
});

const material = new THREE.MeshStandardMaterial({
  map: colorMap,
  roughness: 0.9,
  metalness: 0.0
});
function makeGradientTexture(stops) {
  const canvas = document.createElement('canvas');
  canvas.width = 256;
  canvas.height = 1;
  const ctx = canvas.getContext('2d');

  const gradient = ctx.createLinearGradient(0, 0, 256, 0);
  stops.forEach(function (s) {
    gradient.addColorStop(s.at, s.color);
  });
  ctx.fillStyle = gradient;
  ctx.fillRect(0, 0, 256, 1);

  const texture = new THREE.CanvasTexture(canvas);
  texture.colorSpace = THREE.SRGBColorSpace;
  texture.minFilter = THREE.LinearFilter;
  texture.magFilter = THREE.LinearFilter;
  texture.wrapS = THREE.ClampToEdgeWrapping;
  return texture;
}

const ramp = makeGradientTexture([
  { at: 0.0, color: '#1f5fd0' },
  { at: 0.5, color: '#f0a020' },
  { at: 1.0, color: '#d0453a' }
]);
Notes
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Textures and mapping. https://www.jingweizhi.com/en/three/tutorials/textures.html (accessed 2026-11-03).