threejs-materials-lighting
gamedev-skills/awesome-gamedev-agent-skills
Light and shade three.js scenes with PBR materials, shadows, and environment maps.
What is threejs-materials-lighting?
Choose the right material (MeshStandardMaterial for realism, MeshBasicMaterial for unlit), add lights (ambient, directional, point, spot), enable shadow maps, and use environment maps for physically-based reflections. Use this when a mesh looks black, flat, or wrong, or when working with three.js materials, lighting, shadows, or IBL.
- Pick materials by need: MeshStandardMaterial (PBR with roughness/metalness), MeshPhysicalMaterial (clearcoat/transmission), MeshBasicMaterial (unlit), or debug materials
- Add and configure lights: HemisphereLight/AmbientLight for fill, DirectionalLight/PointLight/SpotLight for key lighting with physically-based intensities
- Enable shadow maps in three places: renderer.shadowMap.enabled, light.castShadow, and mesh castShadow/receiveShadow flags
- Fit shadow camera frustum and adjust bias to avoid shadow artifacts (acne, peter-panning, cutoff)
- Apply PBR textures (color, normal, roughness, metalness maps) with correct color spaces
- Load and assign environment maps (HDR/PMREM) to scene.environment for realistic reflections and ambient lighting
How to install threejs-materials-lighting
npx skills add https://github.com/gamedev-skills/awesome-gamedev-agent-skills --skill threejs-materials-lighting- three.js r186 (or r155+; lighting is physically based by default)
- A scene, renderer, and camera already set up (use threejs-scene-setup if needed)
- Optional: HDR environment files or texture maps for PBR materials
How to use threejs-materials-lighting
- 1.Choose a material type based on your need (MeshStandardMaterial for lit surfaces, MeshBasicMaterial for unlit UI)
- 2.Add a HemisphereLight or AmbientLight for soft fill lighting
- 3.Add a DirectionalLight or PointLight as a key light with intensity 2–3 (physically-based)
- 4.If using shadows, enable renderer.shadowMap.enabled, set light.castShadow = true, and mark meshes with castShadow/receiveShadow
- 5.Fit the DirectionalLight's shadow.camera frustum (left, right, top, bottom, near, far) tightly to your scene
- 6.Optionally load an HDR environment map and assign it to scene.environment for reflections and ambient lighting
- 7.Verify the surface responds to lights (highlights move), shadows land correctly, and reflections look plausible
Use cases
- Fix a mesh rendering pure black by adding lights or an environment map to a lit material
- Set up a product-visualization scene with a 3-light rig (key, fill, back) and sharp shadows
- Apply brick or metal textures with normal and roughness maps to a MeshStandardMaterial
- Create a grounded reflection using an HDR environment map and tone mapping
- Debug geometry by temporarily swapping to MeshNormalMaterial or MeshBasicMaterial
- Game developers building 3D scenes with realistic lighting
- Web graphics engineers implementing product visualizations or architectural renders
- Artists and designers tuning material appearance and shadow quality
- Developers migrating from older three.js tutorials to physically-based lighting (r155+)
threejs-materials-lighting FAQ
A lit material (MeshStandardMaterial, MeshPhysicalMaterial) needs either a light source or a scene.environment. Add a HemisphereLight and DirectionalLight, or load an HDR environment map. To confirm geometry, temporarily use MeshBasicMaterial or MeshNormalMaterial.
Since three.js r155, lighting is physically based. A key DirectionalLight typically needs intensity 2–3; fill lights (AmbientLight, HemisphereLight) are usually 0.5–1.0. Older tutorials used much lower values; adjust upward if your scene is too dark.
Set three things: renderer.shadowMap.enabled = true, light.castShadow = true, and mesh.castShadow = true (for casters) and mesh.receiveShadow = true (for receivers). Then fit the light's shadow.camera frustum to your scene to avoid cutoff or blockiness.
Color (albedo) textures must have texture.colorSpace = THREE.SRGBColorSpace. Normal, roughness, and metalness maps should stay linear (leave colorSpace as NoColorSpace). Mixing them up causes incorrect appearance.
Load an HDR environment map (e.g., with HDRLoader) and assign it to scene.environment. PBR materials (MeshStandardMaterial, MeshPhysicalMaterial) automatically pick it up for reflections and ambient lighting. Optionally set scene.background to the same map and enable tone mapping (ACESFilmicToneMapping).
Full instructions (SKILL.md)
Source of truth, from gamedev-skills/awesome-gamedev-agent-skills.
name: threejs-materials-lighting description: > Light and shade a three.js scene: choose materials (MeshStandardMaterial PBR vs unlit MeshBasicMaterial), add ambient/hemisphere/directional/point/spot lights, turn on shadow maps, and use an environment map (IBL) for realistic reflections. Use when a three.js model looks black, flat, or wrong — when the user mentions three.js materials, MeshStandardMaterial, lights, shadows, envMap, or PBR. For renderer/loop setup use threejs-scene-setup; for loading models use threejs-gltf-loading.
three.js Materials & Lighting
Make three.js surfaces look right: pick the correct material, light the scene, enable shadows, and add image-based lighting. Patterns target r186, verified against r186 (lighting is physically based by default since r155).
When to use
- Use when a mesh renders black or flat, when choosing a material, adding lights, enabling shadows, or setting up environment-map reflections (IBL).
- Use when code constructs
MeshStandardMaterial,DirectionalLight, etc., or setsrenderer.shadowMap.enabledorscene.environment.
When not to use: the renderer/camera/loop → threejs-scene-setup. Loading
models (whose PBR materials this complements) → threejs-gltf-loading. Custom
GLSL/ShaderMaterial is its own topic; for the portable concept see
shader-programming.
Core workflow
- Pick a material by need.
MeshStandardMaterial(PBR:roughness,metalness, reacts to lights/IBL) for realism;MeshPhysicalMaterialfor clearcoat/transmission;MeshBasicMaterial(unlit, ignores lights) for UI/flat;MeshNormalMaterial/MeshDepthMaterialfor debugging. - Add light, or nothing shows. Lit materials need a light source and/or
scene.environment. Combine a soft fill (AmbientLight/HemisphereLight) with a keyDirectionalLight. - Mind light intensity. Since r155, lighting is physically based; modern
intensities are higher than old tutorials (a key
DirectionalLight≈ 1–3). - Enable shadows in three places.
renderer.shadowMap.enabled = true, the light'scastShadow = true, and each mesh'scastShadow/receiveShadow. Then fit the light's shadow camera to the scene. - Use an environment map for grounded reflections. Assign an equirectangular or
PMREM-processed texture to
scene.environment; PBR materials pick it up automatically. - Verify under real lighting — confirm the surface responds to the key light (highlights move), shadows land where expected, and reflections look plausible.
Patterns
1. PBR material under a 3-light rig
import * as THREE from 'three';
const material = new THREE.MeshStandardMaterial({
color: 0xcc4444,
roughness: 0.5, // 0 = mirror, 1 = fully matte
metalness: 0.0, // 0 = dielectric (plastic/wood), 1 = metal
});
const mesh = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 16), material);
scene.add(mesh);
// Soft sky/ground fill + a directional key light.
scene.add(new THREE.HemisphereLight(0xbbddff, 0x443322, 1.0)); // sky, ground, intensity
const key = new THREE.DirectionalLight(0xffffff, 2.5);
key.position.set(5, 10, 7);
scene.add(key);
2. Unlit material (no light needed)
// MeshBasicMaterial ignores lights — for flat color, UI, or sprites/labels.
const flat = new THREE.MeshBasicMaterial({ color: 0x44aa88 });
// A textured color map should be tagged sRGB so colors aren't washed out:
const tex = new THREE.TextureLoader().load('assets/logo.png');
tex.colorSpace = THREE.SRGBColorSpace;
const logo = new THREE.MeshBasicMaterial({ map: tex, transparent: true });
3. Shadows (the three required switches + camera fit)
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFShadowMap; // soft by default since r182
const sun = new THREE.DirectionalLight(0xffffff, 3);
sun.position.set(8, 12, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048); // default 512; raise for crisp
// DirectionalLight uses an OrthographicCamera — fit it tightly to the scene:
const cam = sun.shadow.camera;
cam.near = 1; cam.far = 40;
cam.left = -15; cam.right = 15; cam.top = 15; cam.bottom = -15;
scene.add(sun);
mesh.castShadow = true;
ground.receiveShadow = true; // a plane to catch the shadow
4. PBR textures on a material
const loader = new THREE.TextureLoader();
const colorMap = loader.load('assets/brick_color.jpg');
colorMap.colorSpace = THREE.SRGBColorSpace; // color maps are sRGB
const normalMap = loader.load('assets/brick_normal.jpg'); // data maps stay linear
const roughMap = loader.load('assets/brick_rough.jpg');
const brick = new THREE.MeshStandardMaterial({
map: colorMap,
normalMap,
roughnessMap: roughMap,
metalness: 0,
});
5. Image-based lighting from an HDR environment
import { HDRLoader } from 'three/addons/loaders/HDRLoader.js'; // RGBELoader before r180
new HDRLoader().load('assets/studio.hdr', (hdr) => {
hdr.mapping = THREE.EquirectangularReflectionMapping;
scene.environment = hdr; // lights + reflects all PBR materials
scene.background = hdr; // optional: show it as the backdrop
});
// Optional cinematic tone curve:
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.0;
Pitfalls
- Mesh is pure black → a lit material with no light and no
scene.environment. Add a light or an environment map; to confirm geometry, temporarily swap toMeshBasicMaterial/MeshNormalMaterial. - Scene too dark even with lights → old tutorial intensities. r155+ is physically based; raise intensities (key light ≈ 2–3) or add an environment map.
- Shadows don't appear → you missed one of the three switches
(
renderer.shadowMap.enabled,light.castShadow, meshcastShadow/receiveShadow). - Shadows are cut off or blocky → the
DirectionalLight's orthographicshadow.camerafrustum is too big/small or doesn't cover the scene; tightenleft/right/top/bottom/near/farand raiseshadow.mapSize. Visualise it withnew THREE.CameraHelper(light.shadow.camera). - Shadow acne / peter-panning → adjust
light.shadow.bias(small negative) andlight.shadow.normalBias. - Colors look washed out / too bright → color (albedo) textures need
texture.colorSpace = THREE.SRGBColorSpace; normal/roughness/metalness maps must stay linear (leave them asNoColorSpace). - PointLight shadows tank performance → a point light renders the scene 6 times
(cube map). Prefer one shadow-casting
DirectionalLight; use cheaper fakes elsewhere.
References
- For the material cheat-sheet (which
Mesh*Materialfor which look), light types and their parameters/units, transparency vsalphaTestordering, and thePMREMGenerator/RoomEnvironmentroute to IBL without an HDR file, readreferences/materials-lights-table.md.
Related skills
threejs-scene-setup— renderer, camera, and loop (setshadowMap, tone mapping).threejs-gltf-loading— models arrive with PBR materials this skill tunes.shader-programming— custom shader effects (engine-agnostic concept).
Related skills
More from gamedev-skills/awesome-gamedev-agent-skills and the wider catalog.

threejs-scene-setup
Bootstrap a three.js scene with camera, renderer, animation loop, and OrbitControls.

tower-defense
Build tower defense games with enemy pathing, wave spawning, tower targeting, and economy systems.

unity-animation
Drive character animation in Unity 6.3 LTS with Animator Controllers, parameters, blend trees, and IK.

unity-build-pipeline
Configure, script, and automate Unity 6.3 LTS player builds with platform targets, scripting backends, and CI integration.

unity-csharp-scripting
Write correct Unity 6 MonoBehaviour scripts with proper lifecycle, component caching, and coroutines.

unity-input-system
Wire player input in Unity 6.3 LTS with action-based, device-agnostic Input System package.