In this lesson, you will learn how to shift the computational burden of complex indirect lighting from your players' hardware to Unity's offline Progressive CPU Lightmapper.
While real-time lighting is perfect for dynamic objects, calculating light bounces (indirect lighting) every frame is extremely expensive. By utilizing the Progressive CPU Lightmapper, we can "bake" these calculations into lightmap textures, allowing your game to display realistic color bleeding and soft shadows at zero runtime cost.
Setting Up for the Bake
Before initiating the bake, you must ensure your scene geometry is configured correctly:
- Mark as Static: Select your static environment objects (walls, floors, large structures) and check the Static toggle in the Inspector. This informs the lightmapper that these objects will never move, making them candidates for lightmap data.
- Configure Materials: Ensure your materials are not using Unlit shaders; the lightmapper needs to know how a surface responds to light.
- Lighting Window: Open Window > Rendering > Lighting. Under the Lightmapping Settings, ensure the Lightmapper is set to Progressive CPU.
The Progressive Workflow
The "Progressive" aspect of this lightmapper is its most powerful feature. Unlike older legacy systems, the Progressive CPU lightmapper provides a real-time preview of the bake. It generates lightmap texels incrementally, meaning you can see the lighting quality improve in the Scene view while the bake is still running.
You can trigger the bake via script if you are building an automated pipeline:
using UnityEditor;
public class LightmapBaker : MonoBehaviour
{
public void StartBaking()
{
Lightmapping.Bake();
}
}
Optimization Tip
To achieve high-quality results without ballooning your build size, pay close attention to Lightmap Resolution (texels per unit) and Lightmap Padding in the Lighting window. Higher resolution improves the sharpness of shadow edges but increases the disk space required for your lightmap textures. Always verify your progress by switching the Scene View to Baked Lightmap mode to visualize how light data is being packed into the UV sets.
Key Takeaway: By marking static geometry and utilizing the Progressive CPU Lightmapper, you capture complex global illumination as high-performance textures, providing cinematic visual fidelity that remains completely static at runtime.