Unity Lighting -- bake lightmaps for scenes

What is baked lighting?

        There are two different lighting methods in Unity: real-time lighting and baked lighting.

realtime lighting

        Unity calculates lighting in real time at runtime. Realtime lights are calculated every frame, which means they are very responsive to characters and objects moving in the scene, but it is also expensive.

bake lighting

        Unity precomputes baked lighting before running. These lighting effects cannot be modified at runtime, and baked lighting will not respond to dynamic game objects.

        The process of calculating baked lighting involves generating UV coordinates for the entire scene, which are similar to the UV coordinates of the texture map in the material. A baked texture map is called a lightmap, and the process of creating a lightmap is called lightmapping or baking.

        Baked lighting is more efficient and can also be used to provide users with more realistic and experiential lighting effects.

change lighting mode

        In Unity, the Light Mode setting allows us to choose the lighting method we want to use:

  •         baked
  •         real-time
  •         Mixed

        If you want to change the lighting mode:

        1. Select a light source game object (such as Directional Light or Spot Light) in the scene, and check the Mode property of the LIght component in the Inspector:

         2. Change the Mode to Baked to modify the lighting mode

        3. If you want to configure the lighting mode of the light source more quickly, you can perform quick configuration in the Windows->Rendering->Light Explorer window (avoid searching one by one from the Hierarchy or scene):

Set the light source in the scene to Static

        A GameObject is considered static if it does not move at runtime. For such objects we can mark these game objects as static. When a game object is marked as static, Unity precomputes some relevant data, including lightmap data for global illumination.

        Before baking the lightmap, we need to set the light source in the scene to static. The following example uses two street lamp models as examples. For the street lamp set as static, the mode of the light source is Baked, and the other non-static one is real-time.

 

 

Baked Lightmaps

        We can choose between two backends for the Progressive Lightmapper. Unity uses the Progressive CPU Lightmapper by default, which uses the computer's CPU and system RAM for backend calculations. Another lightmapper, the Progressive GPU Lightmapper, uses the computing GPU and VRAM to calculate the lightmap.

        Using GPU-based lightmaps can greatly increase the speed of lightmap calculations, but only if the computer configuration can meet the relevant hardware and software requirements. Check this requirement here:

Unity - Manual: The Progressive GPU Lightmapper (preview)https://docs.unity3d.com/Manual/GPUProgressiveLightmapper.html

Baked Lightmaps

        1. In the Lighting window (Window -> Rendering -> Lighting), select the Scene tab, then click New Lighting Settings

        2. Name this lighting profile BakedLighting 

         3. Set Lighting Mode to Baked Indirect. If your machine meets the requirements of the GPU lightmapper, you can set Lightmapper to Progressive GPU (Preview) to speed up the baking

        4. In the Lighting window, select Generate Lighting to bake the lightmap. We will see the baking progress in the lower right corner of the Unity Editor.

        5. During the baking process, pay attention to observe the two street lights in the scene. What is the difference between the street light model with static and without static?

        6. After the baking is complete, move the static street lamp model, and you can see that its light and shadow have not changed with the movement of the street lamp.

Add an Area Light

        As mentioned in the previous notes, Area Light can only be baked. Let's add a model with an area light source to the scene to see.

        It can be seen that after this model is added to the scene, there is no lighting effect.

        

 

        Let's generate the baked lightmap again, and now we can see its effect.

        If we want to modify the parameters of the surface light source, after the modification, we must bake again to see the effect.

Set Mixed lighting mode

        We can also set the Light Mode to Mixed to create a mixed-mode light source that combines real-time shadows with baked lighting. It increases storage and runtime overhead compared to purely baked lighting, but also improves the quality of shadows. For a relatively small lightweight project, the Mixed method can usually be used, although it will consume a certain amount of performance but it is worth it.

        To switch the light source to Mixed mode, the operation is the same as the previous setting of Light mode, so I won't repeat it here.

         After selecting the Mixed mode, you need to click Generate Lighting in the Lighting window to update the baked light map.

Guess you like

Origin blog.csdn.net/vivo01/article/details/129391508