Course contentsShow
← Unity Game Development
Lesson 590 of 8289. Rendering and VisualsFree lesson

Blending Baked and Real-time Lighting Workflows

You will implement mixed lighting modes to combine the performance benefits of baked lighting with the visual flexibility of real-time shadows.

In this lesson, you will learn how to configure Unity’s Mixed Lighting modes to leverage the efficiency of pre-computed lightmaps while retaining the dynamic visual fidelity of real-time shadows.

The Hybrid Approach

Baked lighting is incredibly performant because it stores light calculations in textures, but it fails when objects move. Conversely, real-time lighting is flexible but computationally expensive. Mixed lighting allows us to bridge this gap. By setting a Light component to Mixed, we instruct Unity to bake static environment lighting into lightmaps while calculating shadows for dynamic objects in real-time.

Configuring Mixed Lighting

To implement this, ensure your scene is set to a "Subtractive" or "Shadowmask" lighting mode under Lighting > Scene.

  1. Subtractive: This is the most performance-friendly mode. Static objects are baked into lightmaps, and dynamic objects cast real-time shadows onto those static surfaces. The dynamic objects themselves don't receive baked GI, which works well for mobile.
  2. Shadowmask: This is the industry standard for high-fidelity projects. It combines baked GI with a "shadow mask" texture that tells the engine exactly where real-time shadows should be rendered on static geometry.

Practical Implementation

When you set a Light mode to Mixed, Unity behaves differently based on your project settings. If you want a dynamic player character to interact with a baked scene, ensure the Light is set to Mixed and your environment meshes are marked as Static.

// Example: Dynamically toggling a mixed light's shadow strength 
// to balance performance during intense gameplay sequences.
public Light directionalLight;

void Update() {
    if (isHighPerformanceMode) {
        directionalLight.shadows = LightShadows.Soft; // High fidelity
    } else {
        directionalLight.shadows = LightShadows.Hard; // Optimized
    }
}

The beauty of this workflow is that the baked light data provides the "bounce" and ambient color (Global Illumination), while the real-time component ensures that as your characters move through the environment, their shadows ground them firmly in the space. By balancing these, you maintain visual consistency without tanking the frame rate.

Key Takeaway: Use Mixed Lighting to bake static global illumination into lightmaps while delegating dynamic shadow casting to real-time calculations, ensuring your scene looks alive without sacrificing performance.