Lesson 89 +10 XP

Level of Detail (LOD)

Level of Detail (LOD)

Level of Detail (LOD) is an optimization technique where meshes with fewer polygons are displayed when a GameObject is far from the camera, reducing the rendering workload.

LOD Group Component

Add an LOD Group component to the root of a GameObject. It holds multiple LOD levels, each referencing different renderers.

  • LOD 0: Highest quality mesh (shown when closest to camera).
  • LOD 1: Medium quality mesh.
  • LOD 2: Low quality mesh.
  • Culled: The object is not rendered at all beyond this distance.

Setting Up LODs

  1. Prepare multiple versions of your mesh (high, medium, low poly) in a 3D DCC tool like Blender or Maya.
  2. Import them into Unity.
  3. Add an LOD Group component to a parent GameObject.
  4. Drag each mesh's renderer into the corresponding LOD slot.
  5. Adjust the percentage transition points on the LOD Group slider.

Scripting LOD

using UnityEngine;

public class ForceLOD : MonoBehaviour
{
    [SerializeField] private LODGroup _lodGroup;

    void Start()
    {
        // Force LOD level 1 (index 0 = LOD 0, index 1 = LOD 1)
        _lodGroup.ForceLOD(1);
    }
}

Cross-Fading LODs

To avoid visible mesh popping during transitions, enable Fade Mode on the LOD Group:

  • None: Instant swap (default).
  • Cross Fade: Blends between LOD levels using a dithering pattern.
  • Speed Tree: Used for SpeedTree vegetation assets.

LOD Bias and Max LOD Level

In Quality Settings (Edit > Project Settings > Quality), you can adjust:

  • LOD Bias: A multiplier that shifts all LOD transitions. Higher value = use higher detail for longer distances.
  • Maximum LOD Level: Forces a maximum LOD level globally, useful for mobile optimization.
// Adjust LOD bias at runtime (e.g., when switching quality levels)
QualitySettings.lodBias = 0.5f; // Use lower quality models earlier

TL;DR

  • LOD Group swaps between mesh variants based on the object's screen size.
  • LOD 0 is highest quality; Culled means not rendered.
  • Cross Fade mode avoids hard pop-in between levels.
  • Adjust LOD Bias in Quality Settings to tune globally across all LOD Groups.