Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Two lightmaps in the same scene - Unity 5

Discussion in 'Global Illumination' started by Victor_Kallai, Mar 30, 2015.

  1. Victor_Kallai

    Victor_Kallai

    Joined:
    Mar 5, 2014
    Posts:
    123
    I have only a scene for my game - it's easier to edit the whole game, and the transitions between screens are instantaneous. But now after I've switched to Unity 5, I can't make 2 lightmaps for different levels in the same scene.
    Did anyone find a simple workaround for this problem?
    No matter how many lightmaps I bake, the same LightmapSnapshot keeps overriding all the light settings from the scene.
     
  2. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    It should work with Baked GI only. If the scene contains Realtime GI also, it will not work.
     
  3. Victor_Kallai

    Victor_Kallai

    Joined:
    Mar 5, 2014
    Posts:
    123
    I only want Baked GI. The problem is that Baked Selected button is gone in Unity 5. So I enable and disable different maps and only bake them. After I bake a map, I move the texture and the LightmapSnapshot in a different folder, and rebake a different map.
    On each map I have a script that changes the current lightmap:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [ExecuteInEditMode]
    4. public class LightmapEnable : MonoBehaviour
    5. {
    6.     public Texture2D lightmapFar;
    7.     public Texture2D lightmapNear;
    8.     private LightmapData[] _lightmapDatas;
    9.     public LightmapData[] lightmapDatas
    10.     {
    11.         get
    12.         {
    13.             if ((lightmapFar != null || lightmapNear != null) && _lightmapDatas == null)
    14.             {
    15.                 _lightmapDatas = new[] { new LightmapData { lightmapFar = lightmapFar, lightmapNear = lightmapNear } };
    16.             }
    17.             return _lightmapDatas;
    18.         }
    19.     }
    20.     void OnEnable()
    21.     {
    22.         LightmapSettings.lightmapsMode = LightmapsMode.NonDirectional;
    23.         if (lightmapDatas != null)
    24.             LightmapSettings.lightmaps = lightmapDatas;
    25.     }
    26.     void OnDisable()
    27.     {
    28.         if (LightmapSettings.lightmaps.Length > 0 && lightmapDatas != null && LightmapSettings.lightmaps[0].lightmapFar == lightmapDatas[0].lightmapFar)
    29.             LightmapSettings.lightmaps = null;
    30.     }
    31. }
    32.  
    This worked in Unity 4.x but it does not work anymore in Unity 5.
    I guess the UV info is lost once a new bake is done in the scene.
    If you find a simple solution, let me know.