Baked vs realtime
- Game Development course
- Intermediate
- Lesson 10/83
- 4 min
Learn the difference between baked and realtime lighting.
Baked and Realtime
Lights can be computed in two ways: Realtime and Baked. A realtime light is recomputed every frame and reacts to moving objects at once. A baked light is computed once before the game starts and written to a lightmap file.
isik.lightmapBakeType = LightmapBakeType.Realtime;
isik.lightmapBakeType = LightmapBakeType.Baked;A baked light does not change during the game but runs much faster.
Lightmap
A lightmap is the texture where baked light and shadows are stored. Baked light is written to this texture and only read during the game. This way, no matter how complex the scene is, light calculations do not slow down the game.
isik.lightmapBakeType = LightmapBakeType.Baked;
// result: Lightmap fileBaked suits unchanging objects, Realtime suits moving ones.
Practice Set the light mode
In a class named IsikModu, define a public string mod field with the value "Realtime" and add an int kare field. In the Start method, set the mod value to "Baked" and print the text "Pisirme modu: " joined with mod using Debug.Log. In the Update method, increase the kare counter by one every frame.
Starter code
using UnityEngine;
public class IsikModu : MonoBehaviour
{
// public string mod alanini "Realtime" degeriyle tanimla
// int kare alanini tanimla
void Start()
{
// mod degerini "Baked" yap
// "Pisirme modu: " metnini mod ile birlestirip yazdir
}
void Update()
{
// kare sayacini bir artir
}
}Sample solution
using UnityEngine;
public class IsikModu : MonoBehaviour
{
public string mod = "Realtime";
int kare;
void Start()
{
mod = "Baked";
Debug.Log("Pisirme modu: " + mod);
}
void Update()
{
kare++;
}
}Expected output
Pisirme modu: Baked
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 If the shadow of a character moving during the game must change immediately, which light computation should be used?
- Lightmap file
- Ambient light
- Realtime light Correct answer
- Baked light
Explanation: A realtime light is recomputed every frame, so the shadows of moving objects update at once.
2 Make the light baked
isik.lightmapBakeType = LightmapBakeType.____;
isik.lightmapBakeType = LightmapBakeType.Baked;
Explanation: LightmapBakeType.Baked makes the light baked before the game starts.
3 Light computation types
| Term | Meaning |
|---|---|
Realtime ışık |
Recomputed every frame |
Baked ışık |
Computed once before the game starts |
Lightmap |
The texture that stores baked light |
Hareketli nesne |
Uses realtime light |