Install the skill above, then run this in your AI tool:
/threejs-textures <your description>
About
Targets three.js r186. Examples use WebGLRenderer; the WebGPU and TSL section uses WebGPURenderer.
Source
What gets added to your project
Preview every file this package writes on install before you run the command above.
Summary
js textures: image loading, color spaces, UV channels and transforms, texture types from canvas to HDR and KTX2, render targets, texture memory. Use when working with images on materials, UV coordinates, cubemaps, render targets or...
Skill instructions
Three.js Textures
Targets three.js r186. Examples use WebGLRenderer; the WebGPU and TSL section uses WebGPURenderer.
Quick Start
javascript
import * asTHREEfrom"three";
const renderer = newTHREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const scene = newTHREE.Scene();
const camera = newTHREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.set(0, 0, 2);
// Color images must be tagged sRGB or they render too bright and washed outconst texture = newTHREE.TextureLoader().load("diffuse.jpg");
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = newTHREE.Mesh(
newTHREE.PlaneGeometry(2, 2),
newTHREE.MeshBasicMaterial({ map: texture }),
);
scene.add(mesh);
renderer.setAnimationLoop(animate);
functionanimate() {
mesh.rotation.z += 0.01;
renderer.render(scene, camera);
}
Loading
javascript
// load() returns the texture at once; its image arrives asynchronouslyconst texture = newTHREE.TextureLoader().load("diffuse.jpg");
texture.colorSpace = THREE.SRGBColorSpace;
mesh.material.map = texture; // before the first render; afterwards also set mesh.material.needsUpdate = true// When the next step needs the loaded image, await itconst colorMap = awaitnewTHREE.TextureLoader().loadAsync("diffuse.jpg");
colorMap.colorSpace = THREE.SRGBColorSpace;
TextureLoader's onProgress parameter is unsupported and never fires; a LoadingManager reports progress as each file finishes:
Color management is on by default and every texture starts at NoColorSpace:
LDR color images get SRGBColorSpace: map, emissiveMap, specularMap, sheen color and specular color maps, LDR matcaps, and canvas or video used as color.
Scalar data keeps NoColorSpace: normal, bump, displacement, roughness, metalness, ambient-occlusion and alpha maps.
HDR environments are LinearSRGBColorSpace; the HDR loaders set that themselves. GLTFLoader sets the color spaces of the textures it loads.
javascript
const colorMap = newTHREE.TextureLoader().load("color.jpg");
colorMap.colorSpace = THREE.SRGBColorSpace; // authored color imageconst normalMap = newTHREE.TextureLoader().load("normal.jpg");
// normalMap stays at NoColorSpace: it is data, not color
MirroredRepeatWrapping tiles with a mirror flip on each repeat.
Filtering, Mipmaps, Anisotropy
javascript
const texture = newTHREE.TextureLoader().load("diffuse.jpg");
// Minification (many texture pixels per screen pixel)
texture.minFilter = THREE.LinearMipmapLinearFilter; // default: trilinear blend between mip levels
texture.minFilter = THREE.NearestFilter; // hard pixel look, samples only the base level// Magnification (texture magnified on screen)
texture.magFilter = THREE.LinearFilter; // default
texture.magFilter = THREE.NearestFilter; // pixelated// Mipmaps are generated whenever generateMipmaps is true, whatever the filters.// Turn generation off to save memory (UI sprites, data textures):
texture.generateMipmaps = false;
texture.minFilter = THREE.LinearFilter; // and do not request a mipmap filter// Sharper at grazing angles; clamp to what the hardware supports
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
VideoFrameTexture for WebCodecs: each decoded frame is pushed by hand:
javascript
const frameTexture = newTHREE.VideoFrameTexture();
frameTexture.colorSpace = THREE.SRGBColorSpace;
const decoder = newVideoDecoder({
output(frame) {
if (frameTexture.imageinstanceofVideoFrame) frameTexture.image.close(); // free the replaced frame, or decoding stalls
frameTexture.setFrame(frame);
},
error: (e) =>console.error(e),
});
HTMLTexture draws an HTML element through the browser's HTML-in-Canvas API: the renderer moves the element into its own canvas and re-uploads it on paint events; where the browser lacks that API the texture stays empty.
Compressed Textures (KTX2)
javascript
import { KTX2Loader } from"three/addons/loaders/KTX2Loader.js";
const ktx2Loader = newKTX2Loader();
// No setTranscoderPath call: the transcoder loads from the three package.// Set one only when self-hosting the decoders, pinned to this release.
ktx2Loader.detectSupport(renderer); // required before loading; works with both renderersconst compressedMap = await ktx2Loader.loadAsync("diffuse.ktx2");
// colorSpace comes from the file's transfer function; nothing to set by hand
Basis Universal KTX2 transcodes to a compressed format the GPU supports: smaller uploads and less memory than PNG or JPEG, which upload uncompressed (where the GPU supports none of the targets, KTX2Loader also falls back to uncompressed RGBA). Compressed textures cannot be flipped or mipmapped at upload: flipY stays false, so author the file in the orientation your UVs expect, and mipmaps must be embedded in the file.
Environment Maps
Cube maps (the loader tags the result sRGB itself):
javascript
const cubeTexture = newTHREE.CubeTextureLoader().load([
"px.jpg", "nx.jpg", // +X, -X"py.jpg", "ny.jpg", // +Y, -Y"pz.jpg", "nz.jpg", // +Z, -Z
]);
scene.background = cubeTexture;
scene.environment = cubeTexture; // lights Standard and Physical materials (WebGLRenderer also Lambert and Phong)
HDR equirectangular files — set mapping, then assign; both renderers prefilter the environment themselves:
javascript
import { HDRLoader } from"three/addons/loaders/HDRLoader.js";
const env = awaitnewHDRLoader().loadAsync("environment.hdr");
env.mapping = THREE.EquirectangularReflectionMapping; // without it the background draws as a flat screen quad
scene.environment = env;
scene.background = env;
EXRLoader (three/addons/loaders/EXRLoader.js) loads .exr files the same way and UltraHDRLoader loads Ultra HDR JPEGs; both set their own linear color space.
Both renderers convert an equirectangular environment into a cube map with a larger texture internally (better sampling, more memory); when memory matters, ship a lower-resolution equirect file.
PMREMGenerator is for generated environments — a scene such as RoomEnvironment captured with fromScene:
Do not run a loaded equirect file through PMREMGenerator "for better reflections" — direct assignment with mapping set produces the same prefiltering.
Render Targets
javascript
const renderTarget = newTHREE.WebGLRenderTarget(512, 512);
const rtScene = newTHREE.Scene(); // must not contain the mesh that samples the target
rtScene.add(newTHREE.Mesh(newTHREE.BoxGeometry(), newTHREE.MeshNormalMaterial())); // unlit, visible without lights
renderer.setRenderTarget(renderTarget);
renderer.render(rtScene, camera);
renderer.setRenderTarget(null); // back to the canvas// the output is a texture like any other
mesh.material.map = renderTarget.texture;
// MSAA: resolved into .texture automatically after renderingconst msaaTarget = newTHREE.WebGLRenderTarget(512, 512, { samples: 4 });
// MRT: N color attachments, read back through .texturesconst mrtTarget = newTHREE.WebGLRenderTarget(512, 512, { count: 2 });
const firstAttachment = mrtTarget.textures[0];
const secondAttachment = mrtTarget.textures[1];
Dynamic Reflections
javascript
const cubeRenderTarget = newTHREE.WebGLCubeRenderTarget(256, {
generateMipmaps: true,
minFilter: THREE.LinearMipmapLinearFilter,
});
const cubeCamera = newTHREE.CubeCamera(0.1, 1000, cubeRenderTarget);
scene.add(cubeCamera);
mesh.material.envMap = cubeRenderTarget.texture;
// each frame: hide the reflective mesh so it does not see itself
mesh.visible = false;
cubeCamera.position.copy(mesh.position);
cubeCamera.update(renderer, scene);
mesh.visible = true;
UV Channels
Every UV-mapped material texture samples the UV attribute chosen by texture.channel: 0 reads uv (the default), 1 reads uv1, 2 reads uv2, 3 reads uv3. So aoMap and lightMap work on the default uv set; a separately unwrapped set goes in uv1 with the texture pointed at it:
javascript
const aoTexture = newTHREE.TextureLoader().load("ao.jpg");
const geometry = newTHREE.BoxGeometry(1, 1, 1);
const uvAttribute = geometry.attributes.uv;
const aoUvs = newFloat32Array(uvAttribute.count * 2); // fill with the second unwrap
geometry.setAttribute("uv1", newTHREE.BufferAttribute(aoUvs, 2));
const material = newTHREE.MeshStandardMaterial({ aoMap: aoTexture });
material.aoMap.channel = 1; // sample "uv1" instead of "uv"const aoMesh = newTHREE.Mesh(geometry, material);
scene.add(aoMesh);
Texture Atlas
One image, many sprites, each selected with offset and repeat:
javascript
const atlas = awaitnewTHREE.TextureLoader().loadAsync("atlas.png");
atlas.colorSpace = THREE.SRGBColorSpace;
// filtering and mipmaps sample across sprite borders: leave padding around each sprite// one clone per sprite: clones share the image source, so WebGLRenderer uploads it oncefunctionspriteTexture(row, col, gridSize = 2) {
const sprite = atlas.clone();
sprite.offset.set(col / gridSize, 1 - (row + 1) / gridSize);
sprite.repeat.set(1 / gridSize, 1 / gridSize);
return sprite;
}
mesh.material.map = spriteTexture(0, 0); // top-left sprite of a 2x2 sheet
const colorMap = newTHREE.TextureLoader().load("color.jpg");
const emissiveMap = newTHREE.TextureLoader().load("emissive.jpg");
const normalMap = newTHREE.TextureLoader().load("normal.jpg");
colorMap.colorSpace = THREE.SRGBColorSpace;
emissiveMap.colorSpace = THREE.SRGBColorSpace;
// normalMap keeps NoColorSpace, as do roughness, metalness, ao, alpha and displacement mapsconst material = newTHREE.MeshStandardMaterial({
map: colorMap,
normalMap: normalMap,
normalScale: newTHREE.Vector2(1, 1),
emissiveMap: emissiveMap,
emissive: 0xffffff, // non-black, so the emissive map contributesroughness: 1, // scalar multipliers for the matching mapsmetalness: 0,
});
material.aoMap = newTHREE.TextureLoader().load("ao.jpg");
material.aoMapIntensity = 1;
alphaMap takes effect with transparent: true (blended) or alphaTest (cut out); displacementMap scales with displacementScale and displacementBias and wants a subdivided mesh; normalMapType defaults to TangentSpaceNormalMap, set ObjectSpaceNormalMap for object-space normal maps.
Disposal and Memory
texture.dispose() frees the GPU upload once no other undisposed texture shares it (the atlas clones above share one); the image object remains. Dispose only textures that no other material still uses:
javascript
functiondisposeMaterial(material) {
for (const key ofObject.keys(material)) {
const value = material[key];
if (value && value.isTexture) {
value.dispose();
}
}
material.dispose();
}
javascript
console.log(renderer.info.memory.textures); // texture count currently on the GPUconsole.log(renderer.capabilities.maxTextureSize); // largest supported dimension
Share one texture instance across materials rather than loading per mesh. Non-power-of-two sizes are fine: WebGL 2 supports mipmaps and repeat wrapping on them.
WebGPU and TSL
javascript
import * asTHREEfrom"three/webgpu";
import { texture, uv } from"three/tsl";
const renderer = newTHREE.WebGPURenderer({ antialias: true });
await renderer.init(); // before any other use of the renderer
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const scene = newTHREE.Scene();
scene.background = newTHREE.Color(0x111111); // the WebGPU canvas starts transparentconst camera = newTHREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.set(0, 0, 2);
const map = newTHREE.TextureLoader().load("diffuse.jpg");
map.colorSpace = THREE.SRGBColorSpace;
map.anisotropy = renderer.getMaxAnisotropy(); // no capabilities object under WebGPUconst mesh = newTHREE.Mesh(newTHREE.PlaneGeometry(2, 2), newTHREE.MeshBasicNodeMaterial());
mesh.material.colorNode = texture(map, uv().mul(0.5).add(0.25)); // custom UV transform in TSL: the center half, zoomed 2x
scene.add(mesh);
renderer.setAnimationLoop(animate);
functionanimate() {
mesh.rotation.z += 0.01;
renderer.render(scene, camera);
}
TSL sampling: texture(map) uses uv() plus the texture's own offset/repeat/rotation; an explicit node takes over the coordinates entirely. The classic slots (map, normalMap, roughnessMap, aoMap) work unchanged on node materials; colorNode is for custom sampling.
KTX2Loader.detectSupport(renderer) queries device features, so call it after await renderer.init(). For dynamic reflections use CubeRenderTarget (not WebGLCubeRenderTarget) with the same hide-update-show CubeCamera pattern.
javascript
import * asTHREEfrom"three/webgpu";
const cubeRenderTarget = newTHREE.CubeRenderTarget(256); // replaces WebGLCubeRenderTargetconst cubeCamera = newTHREE.CubeCamera(0.1, 1000, cubeRenderTarget);
scene.add(cubeCamera);
mesh.material.envMap = cubeRenderTarget.texture;
mesh.visible = false; // hide so the mesh does not reflect itself
cubeCamera.position.copy(mesh.position);
cubeCamera.update(renderer, scene);
mesh.visible = true;
Common Mistakes
geometry.setAttribute("uv2", geometry.attributes.uv) → material.aoMap = aoTexture;: aoMap samples the attribute picked by texture.channel (default 0, uv), so it needs no extra attribute and uv2 is read only by textures whose channel is 2; only a separate baked unwrap goes in uv1, with aoTexture.channel = 1.
new RGBELoader() → new HDRLoader(): renamed from RGBELoader to HDRLoader in r180; the old class still runs but logs a deprecation warning.
import { EXRLoader } from "three/examples/jsm/loaders/EXRLoader.js" → import { EXRLoader } from "three/addons/loaders/EXRLoader.js": the browser import maps map three/addons/ to examples/jsm/ and define no three/examples/ key, so the examples path fails to resolve there.
texture.encoding = THREE.sRGBEncoding → texture.colorSpace = THREE.SRGBColorSpace: encoding and the sRGBEncoding constant were removed; colorSpace replaced them.
const texture = loader.load("color.jpg") → const texture = loader.load("color.jpg"); texture.colorSpace = THREE.SRGBColorSpace;: an LDR color image left at NoColorSpace renders too bright and washed out.
texture.minFilter = THREE.LinearFilter; // no mipmaps → texture.generateMipmaps = false;: mipmaps are generated whenever generateMipmaps is true, whatever the filter, so LinearFilter alone still uploads them.
texture.generateMipmaps = false; texture.wrapS = THREE.ClampToEdgeWrapping; // non-power-of-two size → texture.wrapS = THREE.RepeatWrapping;: WebGL 2 supports mipmaps and repeat wrapping on non-power-of-two textures, so nothing has to be disabled for them.
texture.anisotropy = renderer.capabilities.getMaxAnisotropy() → texture.anisotropy = renderer.getMaxAnisotropy(): WebGPURenderer has no capabilities object; this is the call under WebGPU.
material.envMapIntensity = 0.5 → scene.environmentIntensity = 0.5: envMapIntensity scales only the material's own envMap, not scene.environment.
scene.environment = pmrem.fromEquirectangular(hdr).texture → hdr.mapping = THREE.EquirectangularReflectionMapping; scene.environment = hdr;: the renderer prefilters an equirectangular environment itself, so manual PMREM of a loaded file adds nothing.
scene.background = hdr → hdr.mapping = THREE.EquirectangularReflectionMapping; scene.background = hdr;: without mapping, an equirectangular texture draws as a flat screen-space quad instead of a surround.
ktx2Loader.detectSupportAsync(renderer) → await renderer.init(); ktx2Loader.detectSupport(renderer);: the async variant was deprecated in r181, and support detection needs the initialized device.
ktx2Loader.setTranscoderPath("libs/basis/") → const ktx2Loader = new KTX2Loader(); ktx2Loader.detectSupport(renderer);: the transcoder loads from the package, so a path is only needed when self-hosting, pinned to three@0.186.0.
new THREE.WebGLMultipleRenderTargets(width, height, 2) → new THREE.WebGLRenderTarget(width, height, { count: 2 }): removed in r162; the attachments are renderTarget.textures[0..count-1].
new THREE.WebGLCubeRenderTarget(256) → new THREE.CubeRenderTarget(256): under WebGPURenderer use CubeRenderTarget imported from three/webgpu; WebGLCubeRenderTarget is WebGL-only.
loader.load(url, onLoad, onProgress, onError) → manager.onProgress = (url, loaded, total) => console.log(url, loaded, total): TextureLoader's onProgress parameter is unsupported and never fires.
mesh.material.map = texture; // after the mesh has rendered → mesh.material.map = texture; mesh.material.needsUpdate = true;: WebGLRenderer builds a material's shader for the maps it has at its first render, so a map added later stays invisible until the shader is rebuilt, which needsUpdate forces.
normalMap.colorSpace = THREE.LinearSRGBColorSpace → normalMap.colorSpace = THREE.NoColorSpace: normal, roughness, metalness, ao, alpha and displacement maps hold data, not color, so they keep the default NoColorSpace.
const texture = await new Promise((resolve, reject) => loader.load(url, resolve, undefined, reject)) → const texture = await loader.loadAsync(url): loadAsync is that promise, built into the Loader base class.
cubeCamera.update(renderer, scene) → mesh.visible = false; cubeCamera.update(renderer, scene); mesh.visible = true;: while visible, the reflective mesh is drawn into the cube map that its own envMap reads.
See Also
threejs-materials — material properties, blending, and physical materials beyond texture slots.
threejs-loaders — loading managers, glTF models, and the loader family generally.
threejs-shaders — custom GLSL texture sampling under WebGLRenderer.
threejs-lighting — environment lighting and light units.
threejs-asset-pipeline — encoding a model's textures to KTX2, WebP or AVIF with gltf-transform.
Add this badge to a GitHub README so readers can open the package page and install the same version.
[](https://www.aipm-registry.com/skills/cloudai-x/threejs-textures/1.0.0?utm_source=github&utm_medium=readme&utm_campaign=package_badge)
This imported publisher has not claimed its AIPM account. A connected account confirms account control, but it does not guarantee that a package is safe.
AI assistant context
What this skill is for
@cloudai-x/threejs-textures@1.0.0 is an AIPM skill package for All tools. Use it when a project needs the reusable AI behavior described as: Three.js textures: image loading, color spaces, UV channels and transforms, texture types from canvas to HDR and KTX2, render targets, texture memory. Use when working with images on materials, UV coordinates, cubemaps, render targets or...
Shrinking glTF assets for three.js with gltf-transform: inspect, validate and optimize commands, Draco, meshopt and quantization, KTX2, WebP and AVIF textures, the loader setup each output needs, and gltfjsx for React. Use when compressi...
Loading three.js assets: glTF with Draco, meshopt and KTX2 compression, other model formats, textures, HDR and EXR environments, progress, caching, cloning and disposal. Use when loading 3D models, textures or environment maps, or managi...
Picking with raycasting, camera controls, transform gizmos, drag, hover and box selection for three.js, identical under WebGL and WebGPU. Use when handling mouse, touch or keyboard input, detecting clicks on 3D objects, adding camera con...
Run aipm add @cloudai-x/threejs-textures@1.0.0 in a project that has AIPM initialized.
Supported tools
@cloudai-x/threejs-textures@1.0.0 supports All tools.
Before installing
AIPM skills can add files to your project. Review the package name, target, description, license, and publisher before installing. Use a clean branch when trying a new skill.