Resources

Essentials of Materials in Three.js: A Complete Guide

Essentials of Materials in Three.js: A Complete Guide

You load a glTF model into a Three.js scene and it comes out dark, flat or oddly shiny, and the lights are fine. Often the problem sits in the material or its textures: a color map in the wrong color space, a roughness map read from the wrong channel, or a material type that ignores the lights altogether. Fixing those takes a basic grasp of how Three.js builds a surface. Browsers reach worldwide users without an install, which is the reason people put up with this kind of tuning at all.

Fix the textures first

A texture is a 2D image applied to a 3D surface, and the same JPG or PNG file can serve very different jobs. A photo of a wooden board is meant to be looked at. A normal map or a roughness map looks like noise or a purple smear when you open it, because it stores data for the renderer, not something for people to see.

That difference causes one of the most common bugs in this area.

Color textures such as base color need to be marked as sRGB in Three.js (texture.colorSpace = THREE.SRGBColorSpace), while data textures stay linear. Mark a normal map as sRGB and the lighting looks subtly wrong everywhere. Skip it on the base color and everything looks washed out.

A physically based surface usually needs three kinds of input: a base color texture (sometimes called diffuse or albedo), a normal map, and metalness and roughness values. In glTF, metalness and roughness share one image, with roughness in the green channel and metalness in the blue channel, and Three.js reads them from those channels. A studio that exports them as two separate files has to repack them.

Automatic projections such as cubic, spherical or cylindrical mapping can also leave stretching at the poles or across polygons. Use proper UV unwrapping instead.

It takes longer, and it is the right call.

Standard or Physical material

Three.js ships many material classes. The docs list line, points, sprite, shadow and shader materials alongside the mesh ones, so the old “12 materials” count is out of date and not worth memorizing. For ordinary models the choice comes down to five mesh materials, shown from cheapest to most expensive.

Five Three.js mesh materials from MeshBasicMaterial to MeshPhysicalMaterial, ordered by realism and rendering cost

MaterialReacts to lightsTypical use
MeshBasicMaterialNoFlat color, UI, debug views
MeshLambertMaterialYes, matte onlyCheap lit surfaces on weak devices
MeshPhongMaterialYes, with shiny highlightsOlder projects
MeshStandardMaterialYes, physically basedMost models
MeshPhysicalMaterialYes, plus extra effectsGlass, car paint, fabric

MeshBasicMaterial

It ignores lighting. Obviously, a lit scene with Basic materials looks flat.

MeshStandardMaterial

This is the default for most work, since it follows the metalness and roughness model glTF uses. Models exported from Blender or bought from a marketplace usually arrive as Standard materials already, which is why it fits the rest of the pipeline so well, from the exporter to the loader and the lights, with no conversion step in between.

MeshPhysicalMaterial

It extends Standard with clearcoat, transmission, sheen, iridescence and anisotropy. Transmission is the costly one, because the renderer needs an extra pass to see what sits behind the surface. A scene with a dozen glass objects will slow down on a phone. Use Physical for the single hero object that needs it, and keep everything else on Standard.

Phong and Lambert still have a place on low-power devices. Well, it depends on how many of those you still support.

Blender export

Blender works well with web 3D because of its glTF/GLB exporter, which maps the Principled BSDF node onto the metallic-roughness inputs that Three.js expects. Only part of that node survives the trip. Base color, metallic, roughness, emission, alpha and normal map are the inputs to rely on. Anything fancier gets dropped or approximated, so a Blender render and a Three.js scene will not match exactly.

That is a limit of the format, and nothing in Three.js fixes it.

Bake what you need, such as ambient occlusion, into textures before export.

For embedding finished models without writing code, a 3D viewer plugin is the shorter route.

Debugging

If a model is black, check that a light exists and that the material is not Basic by accident. If it is too bright or washed out, look at the color space on the base color texture. And if reflections are missing on a shiny surface, there is probably no environment map, since a metal surface has nothing to reflect. Pure metals with metalness at 1 are the worst case, because they take almost all their color from reflections.

Bogdan Sandu

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.