Another in the series write-a-post-to-remind-myself-hot-to-do-it series.
It took me ages to get a decent understanding of bake lightmaps. Not becoming expert level, just to get a workflow that got the job done. Most of the time. Well, much of the time.
Some of this post is probably wrong. YMMV.
This post is about static objects that form your game’s scenery. Static objects don’t move. Walls, floors, furniture, trees, are usually static. Oh, and the screen shots are for URP.
Baked lighting isn’t just about the scene and its lights, but about the objects being lit as well. You have to check the model (like the FBX) underlying the game object you want to illuminate, and the settings of the game object itself, as well as the settings for lights, and scene settings.
Preparing game objects
Lightmap UVs
Here’s a lightmap:
Notice all the blue lines. That’s how the map wraps itself on game objects. Walls, crystals, like that.
To do this, Unity needs a UV map of the game objects to bake light for. That’s in the import settings of the game object’s model. Here’s a prefab for a wall:
The mesh is highlighted. Click on it to find it in the file system:
The file Wall_1.fbx is the thing that is imported. It has Wall_1_LOD etc. inside it.
It has a setting to generate UVs for lightmaps:
Make sure this is checked for every object you want to light with the lightmap. (It took me a while to figure this out.)
Mesh renderer settings
OK, that’s the file. You drop the prefab made from the file into your scene, making a game object (GO).
Check the mesh renderer component. It should contribute to global illumination (GI). It should get GI from lightmaps.
Static
Lightmaps are for things that don’t move, like walls, floors, and trees. You have to mark GOs as static, before they’ll participate in lightmaps:
OK, that’s the GOs. When you have hundreds of GOs, and you will, that’s a lot of things to check.
Lights
Some GOs have light components that emit light.
To put a light’s effects into a lightmap, set the mode to baked or mixed.
Baked lights only affect lightmaps, and have little effect on runtime performance. What gets baked?
- Direct light: light from an emitter falling directly on an object, and bouncing into the camera.
- Indirect light: light comes from an emitter, hits a surface, then reflects to one or more other surfaces before hitting the camera.
- Shadows: they’re, er, shadows.
For a baked light, all of its lighting effects are computed when lighting is generated in the editor.
Mixed lights are partly baked, and partly realtime. More below.
You can add realtime, mixed, and baked lights in the same scene.
Scene
If you’re using mixed lights and want them partially baked, tell Unity this:
The lighting mode tells Unity what is baked and what is not. Except for direct light. It’s always realtime for mixed lights. It’s indirect and shadows that are different.
Baked indirect omits shadows, baking indirect lighting, with direct lighting realtime. Subtractive baked shadows and indirect lighting, with direct lighting realtime. Shadowmask bakes indirect light, and shadows from static objects. Direct lighting and shadows for dynamic (non-static) GOs are left for realtime.
Pipeline settings
Other
Realtime spot lights cast no shadows when their outer angle is maximized (179).
OK with baked.