| name | threejs-textures |
| allowed-tools | Read, Glob |
| description | Three.js textures - texture types, UV mapping, environment maps, texture settings. Use when working with images, UV coordinates, cubemaps, HDR environments, or texture optimization. |
Three.js Textures
Iron Law
Always set texture.colorSpace = THREE.SRGBColorSpace for albedo/color maps — omitting this causes washed-out colors in physically-based rendering.
Quick Start
import * as THREE from "three";
const loader = new THREE.TextureLoader();
const texture = loader.load("texture.jpg");
const material = new THREE.MeshStandardMaterial({
map: texture,
});
Texture Loading
Basic Loading
const loader = new THREE.TextureLoader();
loader.load(
"texture.jpg",
(texture) => console.log("Loaded"),
(progress) => console.log("Progress"),
(error) => console.error("Error"),
);
const texture = loader.load("texture.jpg");
material.map = texture;
Promise Wrapper
function loadTexture(url) {
return new Promise((resolve, reject) => {
new THREE.TextureLoader().load(url, resolve, undefined, reject);
});
}
const [colorMap, normalMap, roughnessMap] = await Promise.all([
loadTexture("color.jpg"),
loadTexture("normal.jpg"),
loadTexture("roughness.jpg"),
]);
Texture Configuration
Color Space
Critical for accurate color reproduction.
colorTexture.colorSpace = THREE.SRGBColorSpace;
Wrapping Modes
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
Repeat, Offset, Rotation
texture.repeat.set(4, 4);
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.offset.set(0.5, 0.5);
texture.rotation = Math.PI / 4;
texture.center.set(0.5, 0.5);
Filtering
texture.minFilter = THREE.LinearMipmapLinearFilter;
texture.minFilter = THREE.NearestFilter;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.magFilter = THREE.NearestFilter;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
Generate Mipmaps
texture.generateMipmaps = true;
texture.generateMipmaps = false;
texture.minFilter = THREE.LinearFilter;
Texture Types
Texture Type Quick Reference
| Type | Class | When to Use |
|---|
| Image file | TextureLoader | JPG, PNG, WebP — most textures |
| Raw pixel data | DataTexture | Procedural/computed textures |
| HTML Canvas | CanvasTexture | Dynamic labels, HUD, sprite sheets |
| Video | VideoTexture | Playing video on a mesh (auto-updates) |
| Compressed | KTX2Loader | Production, mobile — smallest file size |
Detailed examples for DataTexture, CanvasTexture, VideoTexture, KTX2 → references/advanced-textures.md
Cube Textures
For environment maps and skyboxes.
CubeTextureLoader
const loader = new THREE.CubeTextureLoader();
const cubeTexture = loader.load([
"px.jpg",
"nx.jpg",
"py.jpg",
"ny.jpg",
"pz.jpg",
"nz.jpg",
]);
scene.background = cubeTexture;
scene.environment = cubeTexture;
material.envMap = cubeTexture;
Equirectangular to Cubemap
import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader.js";
const pmremGenerator = new THREE.PMREMGenerator(renderer);
pmremGenerator.compileEquirectangularShader();
new RGBELoader().load("environment.hdr", (texture) => {
const envMap = pmremGenerator.fromEquirectangular(texture).texture;
scene.environment = envMap;
scene.background = envMap;
texture.dispose();
pmremGenerator.dispose();
});
HDR Textures
RGBELoader
import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader.js";
const loader = new RGBELoader();
loader.load("environment.hdr", (texture) => {
texture.mapping = THREE.EquirectangularReflectionMapping;
scene.environment = texture;
scene.background = texture;
});
EXRLoader
import { EXRLoader } from "three/examples/jsm/loaders/EXRLoader.js";
const loader = new EXRLoader();
loader.load("environment.exr", (texture) => {
texture.mapping = THREE.EquirectangularReflectionMapping;
scene.environment = texture;
});
Background Options
scene.background = texture;
scene.backgroundBlurriness = 0.5;
scene.backgroundIntensity = 1.0;
scene.backgroundRotation.y = Math.PI;
Material Texture Maps
PBR Texture Set
const material = new THREE.MeshStandardMaterial({
map: colorTexture,
normalMap: normalTexture,
normalScale: new THREE.Vector2(1, 1),
roughnessMap: roughnessTexture,
roughness: 1,
metalnessMap: metalnessTexture,
metalness: 1,
aoMap: aoTexture,
aoMapIntensity: 1,
emissiveMap: emissiveTexture,
emissive: 0xffffff,
emissiveIntensity: 1,
displacementMap: displacementTexture,
displacementScale: 0.1,
displacementBias: 0,
alphaMap: alphaTexture,
transparent: true,
});
geometry.setAttribute("uv2", geometry.attributes.uv);
Normal Map Types
material.normalMapType = THREE.TangentSpaceNormalMap;
material.normalMapType = THREE.ObjectSpaceNormalMap;
Performance Tips
- Use power-of-2 dimensions: 256, 512, 1024, 2048
- Compress textures: KTX2/Basis for web delivery
- Use texture atlases: Reduce texture switches
- Enable mipmaps: For distant objects
- Limit texture size: 2048 usually sufficient for web
- Reuse textures: Same texture = better batching
console.log(renderer.info.memory.textures);
const maxSize = renderer.capabilities.maxTextureSize;
const isMobile = /iPhone|iPad|Android/i.test(navigator.userAgent);
const textureSize = isMobile ? 1024 : 2048;
References
references/advanced-textures.md — DataTexture, CanvasTexture, VideoTexture, KTX2 compressed, render targets, CubeCamera, UV mapping, texture atlas, procedural textures, and memory management
See Also
threejs-materials - Applying textures to materials
threejs-loaders - Loading texture files
threejs-shaders - Custom texture sampling