threejs-materials
Helps select and configure Three.js materials, from standard PBR surfaces to custom GLSL shaders.
Install
mkdir -p .claude/skills/threejs-materials && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/5353" && unzip -o skill.zip -d .claude/skills/threejs-materials && rm skill.zipInstalls to .claude/skills/threejs-materials
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Three.js materials - PBR, basic, phong, shader materials, material properties. Use when styling meshes, working with textures, creating custom shaders, or optimizing material performance.Key capabilities
- →Configure PBR and standard materials
- →Setup custom GLSL shader materials
- →Optimize material rendering performance
- →Apply textures and environment maps
- →Manage material cloning and disposal
How it works
The skill provides a reference for selecting and configuring Three.js materials, ranging from basic unlit materials to advanced PBR and custom shader implementations.
Inputs & outputs
When to use threejs-materials
- →Applying realistic PBR materials
- →Creating custom GLSL shaders
- →Optimizing material rendering performance
- →Setting up transparency and opacity
About this skill
Three.js Materials
Targets three.js r186. Examples use WebGLRenderer; the WebGPU and TSL section uses WebGPURenderer.
Quick Start
import * as THREE from "three";
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.set(0, 0, 3);
// PBR material - the default choice for lit, realistic surfaces
const material = new THREE.MeshStandardMaterial({
color: 0x00aaff,
roughness: 0.35,
metalness: 0.1,
});
const mesh = new THREE.Mesh(new THREE.SphereGeometry(1, 48, 32), material);
scene.add(mesh);
scene.add(new THREE.HemisphereLight(0xffffff, 0x444444, 1)); // lit materials render black without lights
const light = new THREE.DirectionalLight(0xffffff, 2);
light.position.set(3, 3, 3);
scene.add(light);
function animate() {
mesh.rotation.y += 0.01;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
Material Types Overview
| Material | Use case | Lighting |
|---|---|---|
| MeshBasicMaterial | Unlit color, textures, wireframes | None |
| MeshLambertMaterial | Matte diffuse surfaces | Diffuse |
| MeshPhongMaterial | Shiny plastic, cheap specular | Diffuse + specular |
| MeshStandardMaterial | PBR metal/rough workflow | PBR |
| MeshPhysicalMaterial | PBR plus clearcoat, transmission, sheen, iridescence | PBR |
| MeshToonMaterial | Cel shading | Toon steps |
| MeshMatcapMaterial | Lit look baked into a matcap texture, no lights needed | Baked |
| ShadowMaterial | Transparent surface that shows only the shadows it receives | Shadows only |
| PointsMaterial | Point clouds | None |
| LineBasicMaterial / LineDashedMaterial | Lines | None |
| ShaderMaterial / RawShaderMaterial | Custom GLSL, WebGLRenderer only | Custom |
Color data textures (map, emissiveMap, specularMap, sheenColorMap, specularColorMap, LDR matcap, a canvas or video used as color) need texture.colorSpace = THREE.SRGBColorSpace, or colors render washed out. Scalar maps (normal, bump, displacement, roughness, metalness, ao, alpha, toon gradientMap) keep the default. HDR loaders set their own color space.
MeshBasicMaterial
No lighting calculations. Fast, always visible. Supports envMap with reflectivity (0 to 1) and combine (THREE.MultiplyOperation, THREE.MixOperation, THREE.AddOperation); specularMap (sRGB) masks the env-map contribution.
const map = await new THREE.TextureLoader().loadAsync("color.jpg");
map.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.MeshBasicMaterial({
color: 0xffffff, // multiplied with the map
map,
transparent: true,
opacity: 0.5,
side: THREE.DoubleSide, // FrontSide (default), BackSide, DoubleSide
fog: true, // affected by scene fog
});
MeshLambertMaterial and MeshPhongMaterial
Lambert is diffuse-only. Phong adds a specular highlight; it is the cheap alternative when Standard is too heavy.
const lambert = new THREE.MeshLambertMaterial({
color: 0x00ff00,
emissive: 0x111111, // self-illumination color
emissiveIntensity: 1,
});
const phong = new THREE.MeshPhongMaterial({
color: 0x0000ff,
specular: 0x111111, // highlight color
shininess: 30, // higher = sharper highlight
flatShading: false, // flat vs smooth normals
});
Both also support map, emissiveMap, specularMap (sRGB; masks the env-map reflection, and the highlight on Phong), normalMap, bumpMap, displacementMap, aoMap, envMap, envMapIntensity and envMapRotation.
MeshStandardMaterial (PBR)
Physically-based rendering. Recommended for realistic results.
const map = await new THREE.TextureLoader().loadAsync("color.jpg");
map.colorSpace = THREE.SRGBColorSpace;
const ormMap = await new THREE.TextureLoader().loadAsync("orm.jpg"); // glTF ORM: ao red, roughness green, metalness blue; scalar: keep default
const material = new THREE.MeshStandardMaterial({
color: 0xffffff, // multiplied with the map
roughness: 1.0, // 0 = mirror, 1 = fully diffuse; multiplied by roughnessMap (green)
metalness: 1.0, // 0 = dielectric, 1 = metal; multiplied by metalnessMap (blue), so keep 1 with a map
map,
roughnessMap: ormMap,
metalnessMap: ormMap,
normalMap: null, // surface detail; scale with normalScale (a Vector2)
aoMap: ormMap, // ambient occlusion (red); intensity with aoMapIntensity
displacementMap: null, // vertex displacement; scale with displacementScale, offset with displacementBias
emissive: 0x000000,
emissiveIntensity: 1,
emissiveMap: null, // sRGB
envMap: null, // or rely on scene.environment (see below)
fog: true,
});
lightMap (with lightMapIntensity) bakes indirect light the same way aoMap bakes occlusion; an HDR or EXR lightMap is LinearSRGBColorSpace, which the loaders set.
UV channels: aoMap and lightMap read the channel you pick
Every UV-mapped texture samples the attribute selected by texture.channel: 0 reads uv (the default), 1 reads uv1, 2 reads uv2, 3 reads uv3. aoMap and lightMap need no second UV set - they sample uv unless you change channel. GLTFLoader loads TEXCOORD_1 as uv1 and sets channel itself.
const aoMap = await new THREE.TextureLoader().loadAsync("ao.jpg"); // scalar: keep default
const material = new THREE.MeshStandardMaterial({ aoMap }); // samples uv: no extra attribute needed
// Alternative for a separate unwrap (a baked AO or light map): copy your baker's u,v pairs into uv1
const bakedUv = new THREE.Float32BufferAttribute(mesh.geometry.attributes.position.count * 2, 2); // zero-filled until you copy them in
mesh.geometry.setAttribute("uv1", bakedUv); mesh.material = material;
aoMap.channel = 1; // this material now samples uv1 instead of uv
MeshPhysicalMaterial (Advanced PBR)
Extends MeshStandardMaterial with layer and volume features. Texture variants exist for most of them: clearcoatMap, clearcoatRoughnessMap, clearcoatNormalMap, transmissionMap, thicknessMap, iridescenceMap, iridescenceThicknessMap, sheenColorMap, sheenRoughnessMap, anisotropyMap, specularIntensityMap, specularColorMap.
const material = new THREE.MeshPhysicalMaterial({
// Clearcoat (car paint, lacquer)
clearcoat: 1.0, // 0 = none, 1 = full coat
clearcoatRoughness: 0.1,
// Transmission (glass, water) - refracts the opaque objects and scene.background behind it
transmission: 1.0, // 0 = opaque, 1 = fully transmissive
thickness: 0.5, // volume thickness for refraction
attenuationDistance: 1, // world units; Infinity (the default) = no absorption
attenuationColor: new THREE.Color(0xffaa66), // white light turns this color after attenuationDistance
ior: 1.5, // index of refraction, 1 to 2.333
// Sheen (fabric, velvet)
sheen: 1.0,
sheenColor: new THREE.Color(0xffffff),
sheenRoughness: 0.5,
// Iridescence (soap bubbles, oil slicks)
iridescence: 1.0,
iridescenceIOR: 1.3,
iridescenceThicknessRange: [100, 400], // nanometers
// Anisotropy (brushed metal); direction with anisotropyRotation
anisotropy: 1.0,
// Dispersion (prismatic glass); retroreflectivity (road signs, safety gear)
dispersion: 0.0,
retroreflectivity: 0.0,
// Specular overrides: specularIntensity, specularColor (plus their maps)
});
Glass - transmission with a smooth surface and something behind it to refract:
const glass = new THREE.MeshPhysicalMaterial({
color: 0xffffff,
metalness: 0,
roughness: 0,
transmission: 1,
thickness: 0.5,
ior: 1.5,
});
// transmission refracts the opaque objects and background behind it; scene.environment adds its reflections
MeshToonMaterial
Cel shading. The gradient map is non-color data - keep its default color space.
const steps = new Uint8Array([120, 200]); // two shading steps
const gradientMap = new THREE.DataTexture(steps, 2, 1, THREE.RedFormat);
gradientMap.minFilter = THREE.NearestFilter; // hard steps; LinearFilter blends them
gradientMap.magFilter = THREE.NearestFilter;
gradientMap.needsUpdate = true;
const material = new THREE.MeshToonMaterial({ color: 0x00ff00, gradientMap });
MeshNormalMaterial and MeshDepthMaterial
// Normals encoded as RGB - debugging and flat illustrative looks
const normals = new THREE.MeshNormalMaterial({ flatShading: false, wireframe: false });
// Depth as grayscale (BasicDepthPacking, the default); RGBADepthPacking packs it for reading back in a shader
const depth = new THREE.MeshDepthMaterial();
PointsMaterial
For point clouds. size is in pixels; with sizeAttenuation (the default, perspective cameras only) it is multiplied by half the canvas height and divided by the point's view-space depth.
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute([0, 0, 0, 1, 0.5, 0, 0.5, 1, 0], 3));
const material = new THREE.PointsMaterial({
color: 0xffffff,
size: 0.1,
sizeAttenuation: true, // scale with distance
alphaTest: 0.5, // with a map or alphaMap: discard fragments below this alpha
});
const points = new THREE.Points(geometry, material);
scene.add(points);
LineBasicMaterial and LineDashedMaterial
WebGL and WebGPU always draw line primitives 1 px wide; linewidth, linecap and linejoin only affect the SVGRenderer. For thick lines under WebGLRenderer use Line2 with LineGeometry and LineMaterial from three/addons/lines/ (linewidth in pixels); LineMaterial is a ShaderMaterial, so WebGPURenderer needs Line2 from three/addons/lines/webgpu/Line2.js, which uses Line2NodeMaterial.
const geometry = new THREE.BufferGeometry();
---
*Content truncated.*
When not to use it
- →When working with non-Three.js rendering engines
- →When the material requirements are too simple to justify Three.js overhead
Limitations
- →Performance tips are general and depend on the scene
- →Custom shaders require GLSL knowledge
How it compares
It offers a structured guide to material properties and performance optimization, whereas manual implementation requires deep knowledge of the Three.js API.
Compared to similar skills
threejs-materials side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| threejs-materials (this skill) | 1 | 10mo | No flags | Intermediate |
| zustand | 113 | 5mo | No flags | Intermediate |
| threejs-skills | 61 | 7mo | No flags | Intermediate |
| accessibility-compliance | 45 | 6mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by CloudAI-X
View all by CloudAI-X →You might also like
zustand
lobehub
Zustand state management guide. Use when working with store code (src/store/**), implementing actions, managing state, or creating slices. Triggers on Zustand store development, state management questions, or action implementation.
threejs-skills
sickn33
Three.js skills for creating 3D elements and interactive experiences
accessibility-compliance
wshobson
Implement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.
react-modernization
wshobson
Upgrade React applications to latest versions, migrate from class components to hooks, and adopt concurrent features. Use when modernizing React codebases, migrating to React Hooks, or upgrading to latest React versions.
3d-graphics
samhvw8
3D web graphics with Three.js (WebGL/WebGPU). Capabilities: scenes, cameras, geometries, materials, lights, animations, model loading (GLTF/FBX), PBR materials, shadows, post-processing (bloom, SSAO, SSR), custom shaders, instancing, LOD, physics, VR/XR. Actions: create, build, animate, render 3D scenes/models. Keywords: Three.js, WebGL, WebGPU, 3D graphics, scene, camera, geometry, material, light, animation, GLTF, FBX, OrbitControls, PBR, shadow mapping, post-processing, bloom, SSAO, shader, instancing, LOD, WebXR, VR, AR, product configurator, data visualization, architectural walkthrough, interactive 3D, canvas. Use when: creating 3D visualizations, building WebGL/WebGPU apps, loading 3D models, adding animations, implementing VR/XR, creating interactive graphics, building product configurators.
d3-visualization
lyndonkl
Use when creating custom, interactive data visualizations with D3.js—building bar/line/scatter charts from scratch, creating network diagrams or geographic maps, binding changing data to visual elements, adding zoom/pan/brush interactions, animating chart transitions, or when chart libraries (Highcharts, Chart.js) don't support your specific visualization design and you need low-level control over data-driven DOM manipulation, scales, shapes, and layouts.