Bake lighting in Blender for Three.js
Updated on . Tested with three.js r180, R3F 9 and drei 10.
Sometimes you want your three.js scene to have the beautiful, soft light of a Blender render. This could be when you're building a product showroom and the default three.js lights just look flat. The fix is to bake the lighting in Blender and use it in three.js. The scene then looks rendered and still runs fast on a phone.
To bake lighting in Blender and use it in three.js, do the following:
- Give every object a second UV map where no two faces overlap.
- Bake the light into one image with the rendering engine Cycles, using the Diffuse bake type with Color turned off.
- Save the image as a Radiance HDR file.
- Export the model as a
.glbfile. The lightmap is not inside it. - In three.js, set the image as
lightMapon every material, withchannel = 1,flipY = falseandlightMapIntensity = Math.PI. - Remove the lights you baked from the three.js scene.

Bake the lighting in Blender
The bake writes the light that reaches every surface into one image, called a lightmap. These steps are for a finished scene with its lights in place.
- Select every object you want to bake. In Object Data Properties, open UV Maps and add a second UV map to each object. Name it
Lightmapand click it so it is the selected one. - With all the objects still selected, go to Edit Mode and select all faces. Choose UV, then Smart UV Project, and set Island Margin to 0.03. Blender places every face of every object in one square, with a gap between the pieces.
- In the Image Editor, create a new image. Use 1024 or 2048 pixels, turn off Alpha and turn on 32-bit Float.
- In every material, add an Image Texture node with the new image. Do not connect it to anything. Click the node so it is the active one, because Blender bakes into the active Image Texture node of each material.
- In Render Properties, set Render Engine to Cycles. Open the Bake panel and set Bake Type to Diffuse. Under Influence, turn off Color and keep Direct and Indirect on.
- Select all the objects and click Bake.
- In the Image Editor, choose Image, then Save As, and save the image as a Radiance HDR file.
With Color off, the image contains only light and shadow. The colors stay in the materials, so you can change a wall color in three.js later without a new bake.

Save the lightmap as HDR and not as PNG or JPEG. Sunlight on a floor is brighter than the brightest value a PNG can store, so the color is clamped at pure white. An HDR file keeps the full range. Blender saves Radiance HDR and OpenEXR files in a linear color space, which is what three.js expects from a lightmap.
Export the room and load the lightmap in three.js
Export the model with File, Export, glTF 2.0 as a .glb file. Then load the model and the lightmap, and put the lightmap on every material.
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { HDRLoader } from 'three/addons/loaders/HDRLoader.js';
// The room exported from Blender, and the lightmap baked for it.
async function loadBakedRoom() {
const [gltf, lightMap] = await Promise.all([
new GLTFLoader().loadAsync('/room.glb'),
new HDRLoader().loadAsync('/lightmap.hdr'),
]);
lightMap.channel = 1; // use the second UV map, the one made for the bake
lightMap.flipY = false; // a glTF model's UVs start at the top left
gltf.scene.traverse((object) => {
if (!(object instanceof THREE.Mesh)) return;
const material = object.material as THREE.MeshStandardMaterial;
material.lightMap = lightMap;
material.lightMapIntensity = Math.PI;
});
scene.add(gltf.scene);
return { room: gltf.scene, lightMap };
}The glTF format has no built-in place for a lightmap, so the .glb file contains the meshes, the materials and both UV maps, and the lightmap is a separate file. Blender exports the first UV map as TEXCOORD_0 and the second as TEXCOORD_1. GLTFLoader loads them as the attributes uv and uv1, and setting channel = 1 tells the lightmap to use uv1.
After the import the scene no longer needs lights since the lightmap adds light to the surface by itself. If the sun or the lamps you baked are also in the three.js scene, their light are added twice.
The light lands in the wrong place
If the light is scattered around the room, set flipY = false on the lightmap. glTF places UV (0, 0) at the top left of an image, but three.js places it at the bottom left. HDRLoader sets flipY to true, so every mesh gets the wrong part of the image until you change this.

If the light is correct on some objects and wrong on others, check the UV maps in Blender. Every object needs the Lightmap UV map selected when you bake, and you must unwrap all of them together. No two objects can share an area of the image.
The room is too dark
If the room is much darker than it was in Blender, set lightMapIntensity to Math.PI. A Diffuse bake with Color off stores how bright a white surface looks. Three.js treats a lightmap as the light that falls on the surface and divides it by π when it draws, so at the default intensity of 1 the room is about three times too dark.

With Math.PI the room in three.js had the same brightness as our render of it in Blender. The article about lightmaps in three.js explains the other settings of a lightMap.
The baked light is grainy
If the walls look grainy, bake with more samples. You can specify Samples under Render in the Cycles settings before you bake. This picture is the same room baked with 16 samples.

A room that gets most of its light from one window needs many samples, because most of the light has bounced before it reaches a wall. We baked this room with 1536 samples. In our test with Blender 5.1, the Denoise setting left this Diffuse bake grainy, so more samples was the way to a clean lightmap.
Bake the colors and the light into one picture
You can also bake everything into one image and show it as it is. Set Bake Type to Combined, turn off Denoise, bake into an image without 32-bit Float, and save it as a JPEG. In three.js, show it with a MeshBasicMaterial, which draws the picture without any lighting.
export async function showBakedColor(room: THREE.Object3D) {
const baked = await new THREE.TextureLoader().loadAsync('/baked.jpg');
baked.channel = 1; // the same second UV map
baked.flipY = false;
baked.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.MeshBasicMaterial({ map: baked });
room.traverse((object) => {
if (object instanceof THREE.Mesh) {
object.material = material;
}
});
}
Keep Denoise off for this bake and use more samples instead. In our test with Blender 5.1, Denoise left a dark line along the edge of every piece in the baked image. In three.js those lines show as seams where two pieces meet, for example across a round object or where parts of a wall join.
This is the simplest way, and it also bakes the look of materials that three.js does not have. The drawback is that the colors are now part of the picture. You cannot change the color of a wall or a sofa without a new bake, and a shiny surface no longer reflects anything. If your users change colors or materials, use the lightmap.
In React Three Fiber
In React Three Fiber, load the model with drei's useGLTF and the lightmap with useLoader. Set the lightmap in a layout effect.
import { useLayoutEffect } from 'react';
import * as THREE from 'three';
import { Canvas, useLoader } from '@react-three/fiber';
import { useGLTF } from '@react-three/drei';
import { HDRLoader } from 'three/addons/loaders/HDRLoader.js';
function BakedRoom() {
const { scene } = useGLTF('/room.glb');
const lightMap = useLoader(HDRLoader, '/lightmap.hdr');
useLayoutEffect(() => {
lightMap.channel = 1;
lightMap.flipY = false;
lightMap.needsUpdate = true;
scene.traverse((object) => {
if (!(object instanceof THREE.Mesh)) return;
object.material.lightMap = lightMap;
object.material.lightMapIntensity = Math.PI;
object.material.needsUpdate = true;
});
}, [scene, lightMap]);
return <primitive object={scene} />;
}Do not add <ambientLight> or <directionalLight> for the light you baked. drei's <Environment> also lights the scene, so leave it out or turn its intensity down.
How to bake, simply
A bake from Blender works well for a scene that is finished. The problem is the round trip. Every time you move a wall, change a lamp, or add a product, you go back to Blender, unwrap, bake, save, and export again. If the scene is built in three.js code, there is no Blender file to bake.
Bakery3 bakes the three.js scene you already have. It renders the light with a path tracer, the same way Blender's Cycles does, makes the second UV map, and puts the lightmaps back on your meshes.
import { createBakeSession } from '@oeave/bakery3/bake';
// An API key while you test. In production, use a token from your server instead:
// https://bakery3.com/docs#let-your-users-render-without-exposing-your-api-key
const bakery3 = createBakery3({ apiKey: 'bk_sk_…' });
bakery3.attach({ scene, camera, renderer });
export async function bakeWithBakery3() {
const job = await bakery3.bake();
const { bundle } = await job.result();
const session = createBakeSession({ scene });
await session.apply(session.addGeneration(bundle));
}The bake uses the lights and the environment map of your three.js scene, so you can call it again when the scene changes. Here is a whole room baked this way. You can walk around it in your browser.
Baked GIBoth frames are the real-time viewport. The second is the same scene after a traced bake was applied as lightmaps. Still interactive, still your meshes, and revertible in one call.
up to 512² lightmaps·standard quality·6 object(s) lit·2% of seams in view·3.3 MB to interact
Connecting your scene takes a few lines.
Common questions
Can a glTF file contain baked lighting from Blender?
No, not as a lightmap. The glTF format does not have a lightmap slot, and three.js's GLTFLoader never sets material.lightMap. Export the model as glTF, save the lightmap as a separate image, and set it as lightMap in three.js. The other way is to bake the light into the base color texture, and glTF does contain that.
Should I bake Combined or Diffuse in Blender for three.js?
Bake Diffuse with Color turned off when you want a lightmap that three.js adds to your own materials. This way you can still change colors later. Bake Combined when the scene never changes and you show the result on a MeshBasicMaterial. A Combined bake is simpler to set up. A Diffuse lightmap gives you more flexibility.
Why do I need a second UV map to bake lighting in Blender?
A lightmap needs every face to have its own spot in the image. Your first UV map often reuses one texture piece on many faces. Think of a wood texture that repeats across a floor. With that UV map, every repeat would get the same light. A second UV map made with Smart UV Project gives each face its own area.
Do I need lights in three.js when the lighting is baked in Blender?
No. A three.js lightMap adds light to the surface on its own, so a room with a lightmap looks lit even with no lights in the scene. Remove the lights you baked, or their light shows up twice. Keep a light only for something that moves, because a moving object cannot use the baked shadows.
Which image format should I use for a lightmap from Blender?
Pick Radiance HDR or OpenEXR. Both can store values that go above white, and a sunlit floor needs that range. Three.js loads them with HDRLoader and EXRLoader. A PNG or JPEG will clip the brightest light, and you will see bands in soft shadows. Use JPEG only for a Combined bake that you put on a MeshBasicMaterial.
