Search Unity

Problems with instantiating baked prefabs

Discussion in 'Global Illumination' started by GSdev, May 8, 2015.

Thread Status:
Not open for further replies.
  1. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Hi, Your before edited script works in editor play mode but not in final build (showing blackness), and this edited one giving blackness in editor too....
     
    Last edited: Jan 4, 2016
  2. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    In the "Asset/Resource/Lightmap" folder. Is there missing lightmaps as compared to the folder by the same name as your scene?
     
  3. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Also I should mention the build does NOT override existing lightmaps. You need to delete all lightmaps in the "Asset/Resource/Lightmaps" folder first.
     
  4. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Yes deleting lightmaps in resources folder worked in editor playmode,yet blackness in build persists ...
     
  5. FreddieL

    FreddieL

    Joined:
    Jan 4, 2016
    Posts:
    4
    Hi, I'm getting this error when trying to use the new script:

    NullReferenceException: Object reference not set to an instance of an object
    PrefabLightmapData.ApplyLightmaps (.RendererInfo[] rendererInfo, UnityEngine.Texture2D[] lightmaps) (at Assets/Scripts/PrefabLightmapData.cs:82)
    PrefabLightmapData.GenerateLightmapInfo () (at Assets/Scripts/PrefabLightmapData.cs:154)


    Also using the prior script, there seemed to be an issue with the lightmaps being assigned to the wrong prefabs. If I moved around the elements in the lightmaps array it fixed the issue but this is obviously inconvenient
     
  6. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Which platform are you building to?
     
    idurvesh likes this.
  7. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    I will look into it and get back too you withing soon (may be a day).
     
  8. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Windows...
     
  9. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Can you perhaps make a simplified project that has the same problem that you can share?
     
    idurvesh likes this.
  10. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Or rather non proprietary project
     
  11. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
  12. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Rebaking lightmap and then using script works fine, sorry for trouble...

    thank you so much for your time and efforts....you nailed it manh ...kudos
     
  13. bolang

    bolang

    Joined:
    Mar 26, 2015
    Posts:
    5
    I baked scene in Unity, and split into many prefabs. I have already save lightmap data for each model. When play the game, I will instantiate these prefabs and restore the lightmap data.
    It looks very well in editor and pc build. But in android and ios build, it looks too bright. But if I call LoadLevel function to load the baked scene in android and ios build, it looks the same in editor.
    There is no lights in scene, so maybe it is not due to double lighting.
     
  14. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Here is updated code that should fix @idurvesh 's and @FreddieL 's bugs with my prior code. I added code to save the second lightmap in the LightmapData structure. I also refactored the code a bit. I also increasesd the size of the combined lightmap array by one. I updated the doe also to replace assisting assets in "Assets/Resources/Lightmaps".
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEditor;
    3. #endif
    4. using UnityEngine;
    5. using System.Collections.Generic;
    6. public class PrefabLightmapData : MonoBehaviour
    7. {
    8.     [System.Serializable]
    9.     struct RendererInfo
    10.     {
    11.         public Renderer renderer;
    12.         public int lightmapIndex;
    13.         public Vector4 lightmapOffsetScale;
    14.     }
    15.     [SerializeField]
    16.     RendererInfo[] m_RendererInfo;
    17.     [SerializeField]
    18.     Texture2D[] m_Lightmaps;
    19.     [SerializeField]
    20.     Texture2D[] m_Lightmaps2;
    21.     const string LIGHTMAP_RESOURCE_PATH = "Assets/Resources/Lightmaps/";
    22.     [System.Serializable]
    23.     struct Texture2D_Remap
    24.     {
    25.         public int originalLightmapIndex;
    26.         public Texture2D originalLightmap;
    27.         public Texture2D lightmap;
    28.         public Texture2D lightmap2;
    29.     }
    30.     static List<Texture2D_Remap> sceneLightmaps = new List<Texture2D_Remap>();
    31.     void Awake()
    32.     {
    33.         ApplyLightmaps(m_RendererInfo, m_Lightmaps, m_Lightmaps2);
    34.     }
    35.     static void ApplyLightmaps(RendererInfo[] rendererInfo, Texture2D[] lightmaps, Texture2D[] lightmaps2)
    36.     {
    37.         bool existsAlready = false;
    38.         int counter = 0;
    39.         int[] lightmapArrayOffsetIndex;
    40.         if (rendererInfo == null || rendererInfo.Length == 0)
    41.             return;
    42.         var settingslightmaps = LightmapSettings.lightmaps;
    43.         var combinedLightmaps = new List<LightmapData>();
    44.         lightmapArrayOffsetIndex = new int[lightmaps.Length];
    45.         for (int i = 0; i < lightmaps.Length; i++)
    46.         {
    47.             existsAlready = false;
    48.             for (int j = 0; j < settingslightmaps.Length; j++)
    49.             {
    50.                 if (lightmaps[i] == settingslightmaps[j].lightmapFar)
    51.                 {
    52.                     lightmapArrayOffsetIndex[i] = j;
    53.                     existsAlready = true;
    54.                 }
    55.             }
    56.             if (!existsAlready)
    57.             {
    58.                 lightmapArrayOffsetIndex[i] = counter + settingslightmaps.Length;
    59.                 var newLightmapData = new LightmapData();
    60.                 newLightmapData.lightmapFar = lightmaps[i];
    61.                 newLightmapData.lightmapNear = lightmaps2[i];
    62.                 combinedLightmaps.Add(newLightmapData);
    63.                 ++counter;
    64.             }
    65.         }
    66.         var combinedLightmaps2 = new LightmapData[settingslightmaps.Length + counter];
    67.         settingslightmaps.CopyTo(combinedLightmaps2, 0);
    68.         if (counter > 0)
    69.         {
    70.             for (int i = 0; i < combinedLightmaps.Count; i++)
    71.             {
    72.                 combinedLightmaps2[i + settingslightmaps.Length] = new LightmapData();
    73.                 combinedLightmaps2[i + settingslightmaps.Length].lightmapFar = combinedLightmaps[i].lightmapFar;
    74.                 combinedLightmaps2[i + settingslightmaps.Length].lightmapNear = combinedLightmaps[i].lightmapNear;
    75.             }
    76.         }
    77.         ApplyRendererInfo(rendererInfo, lightmapArrayOffsetIndex);
    78.         LightmapSettings.lightmaps = combinedLightmaps2;
    79.     }
    80.     static void ApplyRendererInfo(RendererInfo[] infos, int[] arrayOffsetIndex)
    81.     {
    82.         for (int i = 0; i < infos.Length; i++)
    83.         {
    84.             var info = infos[i];
    85.             info.renderer.lightmapIndex = arrayOffsetIndex[info.lightmapIndex];
    86.             info.renderer.lightmapScaleOffset = info.lightmapOffsetScale;
    87.         }
    88.     }
    89. #if UNITY_EDITOR
    90.     [MenuItem("Assets/Update Scene with Prefab Lightmaps")]
    91.     static void UpdateLightmaps()
    92.     {
    93.         PrefabLightmapData[] prefabs = FindObjectsOfType<PrefabLightmapData>();
    94.         foreach (var instance in prefabs)
    95.         {
    96.             ApplyLightmaps(instance.m_RendererInfo, instance.m_Lightmaps, instance.m_Lightmaps2);
    97.         }
    98.         Debug.Log("Prefab lightmaps updated");
    99.     }
    100.     [MenuItem("Assets/Bake Prefab Lightmaps")]
    101.     static void GenerateLightmapInfo()
    102.     {
    103.         Debug.ClearDeveloperConsole();
    104.         if (Lightmapping.giWorkflowMode != Lightmapping.GIWorkflowMode.OnDemand)
    105.         {
    106.             Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps and Auto mode is disabled.");
    107.             return;
    108.         }
    109.         Lightmapping.Bake();
    110.         sceneLightmaps = new List<Texture2D_Remap>();
    111.         var scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
    112.         var resourcePath = LIGHTMAP_RESOURCE_PATH + scene.name;
    113.         var scenePath = System.IO.Path.GetDirectoryName(scene.path) + "/" + scene.name + "/";
    114.         PrefabLightmapData[] prefabs = FindObjectsOfType<PrefabLightmapData>();
    115.         foreach (var instance in prefabs)
    116.         {
    117.             var gameObject = instance.gameObject;
    118.             var rendererInfos = new List<RendererInfo>();
    119.             var lightmaps = new List<Texture2D>();
    120.             var lightmaps2 = new List<Texture2D>();
    121.             GenerateLightmapInfo(scenePath, resourcePath, gameObject, rendererInfos, lightmaps, lightmaps2);
    122.             instance.m_RendererInfo = rendererInfos.ToArray();
    123.             instance.m_Lightmaps = lightmaps.ToArray();
    124.             instance.m_Lightmaps2 = lightmaps2.ToArray();
    125.             var targetPrefab = PrefabUtility.GetPrefabParent(gameObject) as GameObject;
    126.             if (targetPrefab != null)
    127.             {
    128.                 //Prefab
    129.                 PrefabUtility.ReplacePrefab(gameObject, targetPrefab);
    130.             }
    131.             ApplyLightmaps(instance.m_RendererInfo, instance.m_Lightmaps, instance.m_Lightmaps2);
    132.         }
    133.         Debug.Log("Update to prefab lightmaps finished");
    134.     }
    135.     static void GenerateLightmapInfo(string scenePath, string resourcePath, GameObject root, List<RendererInfo> rendererInfos, List<Texture2D> lightmaps, List<Texture2D> lightmaps2)
    136.     {
    137.         var renderers = root.GetComponentsInChildren<MeshRenderer>();
    138.         foreach (MeshRenderer renderer in renderers)
    139.         {
    140.             if (renderer.lightmapIndex != -1)
    141.             {
    142.                 RendererInfo info = new RendererInfo();
    143.                 info.renderer = renderer;
    144.                 info.lightmapOffsetScale = renderer.lightmapScaleOffset;
    145.                 Texture2D lightmap = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapFar;
    146.                 Texture2D lightmap2 = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapNear;
    147.                 int sceneLightmapIndex = AddLightmap(scenePath, resourcePath, renderer.lightmapIndex, lightmap, lightmap2);
    148.                 info.lightmapIndex = lightmaps.IndexOf(sceneLightmaps[sceneLightmapIndex].lightmap);
    149.                 if (info.lightmapIndex == -1)
    150.                 {
    151.                     info.lightmapIndex = lightmaps.Count;
    152.                     lightmaps.Add(sceneLightmaps[sceneLightmapIndex].lightmap);
    153.                     lightmaps2.Add(sceneLightmaps[sceneLightmapIndex].lightmap2);
    154.                 }
    155.                 rendererInfos.Add(info);
    156.             }
    157.         }
    158.     }
    159.     static int AddLightmap(string scenePath, string resourcePath, int originalLightmapIndex, Texture2D lightmap, Texture2D lightmap2)
    160.     {
    161.         int newIndex = -1;
    162.         for (int i = 0; i < sceneLightmaps.Count; i++)
    163.         {
    164.             if (sceneLightmaps[i].originalLightmapIndex == originalLightmapIndex)
    165.             {
    166.                 return i;
    167.             }
    168.         }
    169.         if (newIndex == -1)
    170.         {
    171.             var lightmap_Remap = new Texture2D_Remap();
    172.             lightmap_Remap.originalLightmapIndex = originalLightmapIndex;
    173.             lightmap_Remap.originalLightmap = lightmap;
    174.             var filename = scenePath + "Lightmap-" + originalLightmapIndex;
    175.             lightmap_Remap.lightmap = GetLightmapAsset(filename + "_comp_light.exr", resourcePath + "_light", originalLightmapIndex, lightmap);
    176.             if (lightmap2 != null)
    177.             {
    178.                 lightmap_Remap.lightmap2 = GetLightmapAsset(filename + "_comp_dir.exr", resourcePath + "_dir", originalLightmapIndex, lightmap2);
    179.             }
    180.             sceneLightmaps.Add(lightmap_Remap);
    181.             newIndex = sceneLightmaps.Count - 1;
    182.         }
    183.         return newIndex;
    184.     }
    185.     static Texture2D GetLightmapAsset(string filename, string resourcePath, int originalLightmapIndex, Texture2D lightmap)
    186.     {
    187.         AssetDatabase.ImportAsset(filename, ImportAssetOptions.ForceUpdate);
    188.         var importer = AssetImporter.GetAtPath(filename) as TextureImporter;
    189.         importer.isReadable = true;
    190.         AssetDatabase.ImportAsset(filename, ImportAssetOptions.ForceUpdate);
    191.         var assetLightmap = AssetDatabase.LoadAssetAtPath<Texture2D>(filename);
    192.         var assetPath = resourcePath + "-" + originalLightmapIndex + ".asset";
    193.         var newLightmap = Instantiate<Texture2D>(assetLightmap);
    194.         AssetDatabase.CreateAsset(newLightmap, assetPath);
    195.         newLightmap = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
    196.         importer.isReadable = false;
    197.         AssetDatabase.ImportAsset(filename, ImportAssetOptions.ForceUpdate);
    198.         return newLightmap;
    199.     }
    200. #endif
    201. }
    202.  
     
    Last edited: Jan 11, 2016
  15. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Are you using code from this forum thread? If so, which one?
     
  16. bolang

    bolang

    Joined:
    Mar 26, 2015
    Posts:
    5
    I don't use any code from this forum thread. But I write similar code to save lightmap data and restore. I put all the assets and data into assetbundle, does't it have effect on the problem?
     
  17. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Are you using different shaders across the mobile and desktop platforms? You could try comparing the lighting methods they're using. The line would start with "#pragma surface".
     
  18. lordnedox

    lordnedox

    Joined:
    Jan 7, 2016
    Posts:
    24
    Same problem here, it works fine in the editor but in the Android build is all black.

    I'm using single non-directional lightmap, latest version of the script (but same result with the previous one that handled a single lightmap).

    Any suggestion?
     
  19. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Which Android version are you building to? Which phone or tablet are you deploying to? And finally are you using different shaders on the mobile build?
     
  20. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Also which texture compression are you using in your Android build settings?
     
  21. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Some suggestions:
    1. Try re-baking the scene lighting and then re-run the prefab lightmap baking
    2. Try using the default android data compression (ETC) in your build settings
    3. Try using the same material shaders on the mobile that you're using on the desktop. If this fixes it, then your mobile shaders may have a compatibility problem with your mobile device.
     
  22. lordnedox

    lordnedox

    Joined:
    Jan 7, 2016
    Posts:
    24
    Thanks, I will try something, but please consider:

    - Already tried several times cleaning the lightmaps and rebuilding them, same resul
    - Everything was working on Unity 5.2, with an earlier version of the script
    - I don't have a desktop version, it's mobile only so the shaders are the standard one in the mobile folder (diffuse, specular etc.)

    I also feel it could be something about the compression, but the fact that it was working on a previous version could also mean that's not the issue.

    Running on Android 5, building with latest sdk tools (I think 23.x), Unity 5.3.1p1.

    Will update the thread if can find a solution, any other suggestion is more than welcome.

    Thank you!
     
  23. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    They did something in 5.3.1 that broke it for the desktop version as well. The PrefabUtility.ReplacePrefab will no longer save the lightmaps into the prefab from the LIghtmapData.asset file. So the code I created is a work around. It basically copies the intermediate lightmap data files into a resource folder and links the Prefabs to the copies rather than the instances in the LightmapData.asset file. You can look at my code as an example of how to modify your own in copying the lightmap files and using those instead. The code is in a post earlier in this forum thread.
     
  24. lordnedox

    lordnedox

    Joined:
    Jan 7, 2016
    Posts:
    24
    Yes I understand your code very well, and that's exactly what I'm trying to do at the moment.
    Instead of packing the lightmap into one asset, I would instead use AssetDatabase.Copy to create a copy in the resource folder, then at runtime just plugin the correct lightmap.

    In fact, if I set the lightmap manually into the scene, and skip the lightmap setup and go straight to ApplyRendererInfo, it works on Android.
    The problem then must be in the conversion between the original lightmap and the copy version in the Resource folder.

    Is there a specific reason you packed the lightmap that way, not simply using CopyAsset to copy the exr file into the resource folder?

    Regards
     
  25. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    My solution is more of a hack. I played around with a lot of different ways of copying the asset. I'm not sure why CreateAsset works and CopyAsset does not. I tested my solution on Android Gingerbread (2.3.1) using the ETC compression and it does work for me. It's possible that the original lightmap asset has properties that do not get copied over with CreateAsset that allow it to work.
     
  26. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    I just tried my code on Android Lollipop (build 23) and it works there as well.
     
  27. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    You could make a very simple demo project using the code I provided and see if it's still black for you. This would tell us that there could be some kind of port problem.
     
  28. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    This is my test project I use with Android Gingerbread and Lollipop
     

    Attached Files:

  29. lordnedox

    lordnedox

    Joined:
    Jan 7, 2016
    Posts:
    24
    So I was able to use CopyAsset by changing the method GetLightMapAsset as follows:

    var assetPath = resourcePath + "-" + originalLightmapIndex + ".exr";
    AssetDatabase.CopyAsset(filename, assetPath);
    AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
    var newLightmap = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
    return newLightmap;


    But didn't work anyway.
    Tried your test project and it doesn't work as well, everything is black. Tried on both Galaxy A5 and HTC One S (4.1.1).

    No more ideas :(
     
    Last edited: Jan 8, 2016
  30. lordnedox

    lordnedox

    Joined:
    Jan 7, 2016
    Posts:
    24
    I came to a conclusion that loading lightmaps at runtime is problematic on Unity 5.3.1p1.
    After several tries, I ended up with this solution which works in my case:

    - Store only renderer info in the prefabs, no reference to the lightmap
    - Create a Loading Scene for the level, one for each lightmap (as I have one light map for each dungeon/level type)
    - The loading scene will load the Game scene in additive mode, this way the game inherits the light map from the loading scene

    Everything is working fine so far.

    Tried also the other way around, where the game scene would load the scene with the lightmap in additive mode. It works but only if the lightmap is applied at the beginning of the level. If the lightmap info is applied after the level is loaded (for example when a character moves inside a room), then it doesn't work.

    Cheers
     
  31. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Does your scene has same lightmap data asset as in scene where you baked lightning onto prefabs? Also make sure settings of lightmaps matches to it....
     
  32. FreddieL

    FreddieL

    Joined:
    Jan 4, 2016
    Posts:
    4
    Hi, I am getting this error now:
    NullReferenceException: Object reference not set to an instance of an object
    PrefabLightmapData.ApplyLightmaps (.RendererInfo[] rendererInfo, UnityEngine.Texture2D[] lightmaps, UnityEngine.Texture2D[] lightmaps2) (at Assets/Scripts/PrefabLightmapData.cs:86)
    PrefabLightmapData.GenerateLightmapInfo () (at Assets/Scripts/PrefabLightmapData.cs:161)


    Also my scene has multiple prefabs to which I am trying to bake the lightmaps, however running the script only seems to affect the first prefab in the list. Do I need a different scene for every prefab?
     
  33. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    You should not need a scene per prefab. I tested it with multiple prefabs. I'll see if I can reproduce it though.
     
  34. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Try this version @FreddieL. Likely, it stopped associating the prefabs to the lightmap after the error occurred. This would result in the remaining prefabs looking black.

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEditor;
    3. #endif
    4. using UnityEngine;
    5. using System.Collections.Generic;
    6. public class PrefabLightmapData : MonoBehaviour
    7. {
    8.     [System.Serializable]
    9.     struct RendererInfo
    10.     {
    11.         public Renderer renderer;
    12.         public int lightmapIndex;
    13.         public Vector4 lightmapOffsetScale;
    14.     }
    15.     [SerializeField]
    16.     RendererInfo[] m_RendererInfo;
    17.     [SerializeField]
    18.     Texture2D[] m_Lightmaps;
    19.     [SerializeField]
    20.     Texture2D[] m_Lightmaps2;
    21.     const string LIGHTMAP_RESOURCE_PATH = "Assets/Resources/Lightmaps/";
    22.     [System.Serializable]
    23.     struct Texture2D_Remap
    24.     {
    25.         public int originalLightmapIndex;
    26.         public Texture2D originalLightmap;
    27.         public Texture2D lightmap;
    28.         public Texture2D lightmap2;
    29.     }
    30.     static List<Texture2D_Remap> sceneLightmaps = new List<Texture2D_Remap>();
    31.     void Awake()
    32.     {
    33.         ApplyLightmaps(m_RendererInfo, m_Lightmaps, m_Lightmaps2);
    34.     }
    35.     static void ApplyLightmaps(RendererInfo[] rendererInfo, Texture2D[] lightmaps, Texture2D[] lightmaps2)
    36.     {
    37.         bool existsAlready = false;
    38.         int counter = 0;
    39.         int[] lightmapArrayOffsetIndex;
    40.         if (rendererInfo == null || rendererInfo.Length == 0)
    41.             return;
    42.         var settingslightmaps = LightmapSettings.lightmaps;
    43.         var combinedLightmaps = new List<LightmapData>();
    44.         lightmapArrayOffsetIndex = new int[lightmaps.Length];
    45.         for (int i = 0; i < lightmaps.Length; i++)
    46.         {
    47.             existsAlready = false;
    48.             for (int j = 0; j < settingslightmaps.Length; j++)
    49.             {
    50.                 if (lightmaps[i] == settingslightmaps[j].lightmapFar)
    51.                 {
    52.                     lightmapArrayOffsetIndex[i] = j;
    53.                     existsAlready = true;
    54.                 }
    55.             }
    56.             if (!existsAlready)
    57.             {
    58.                 lightmapArrayOffsetIndex[i] = counter + settingslightmaps.Length;
    59.                 var newLightmapData = new LightmapData();
    60.                 newLightmapData.lightmapFar = lightmaps[i];
    61.                 newLightmapData.lightmapNear = lightmaps2[i];
    62.                 combinedLightmaps.Add(newLightmapData);
    63.                 ++counter;
    64.             }
    65.         }
    66.         var combinedLightmaps2 = new LightmapData[settingslightmaps.Length + counter];
    67.         settingslightmaps.CopyTo(combinedLightmaps2, 0);
    68.         if (counter > 0)
    69.         {
    70.             for (int i = 0; i < combinedLightmaps.Count; i++)
    71.             {
    72.                 combinedLightmaps2[i + settingslightmaps.Length] = new LightmapData();
    73.                 combinedLightmaps2[i + settingslightmaps.Length].lightmapFar = combinedLightmaps[i].lightmapFar;
    74.                 combinedLightmaps2[i + settingslightmaps.Length].lightmapNear = combinedLightmaps[i].lightmapNear;
    75.             }
    76.         }
    77.         ApplyRendererInfo(rendererInfo, lightmapArrayOffsetIndex);
    78.         LightmapSettings.lightmaps = combinedLightmaps2;
    79.     }
    80.     static void ApplyRendererInfo(RendererInfo[] infos, int[] arrayOffsetIndex)
    81.     {
    82.         for (int i = 0; i < infos.Length; i++)
    83.         {
    84.             var info = infos[i];
    85.             info.renderer.lightmapIndex = arrayOffsetIndex[info.lightmapIndex];
    86.             info.renderer.lightmapScaleOffset = info.lightmapOffsetScale;
    87.         }
    88.     }
    89. #if UNITY_EDITOR
    90.     [MenuItem("Assets/Update Scene with Prefab Lightmaps")]
    91.     static void UpdateLightmaps()
    92.     {
    93.         PrefabLightmapData[] prefabs = FindObjectsOfType<PrefabLightmapData>();
    94.         foreach (var instance in prefabs)
    95.         {
    96.             ApplyLightmaps(instance.m_RendererInfo, instance.m_Lightmaps, instance.m_Lightmaps2);
    97.         }
    98.         Debug.Log("Prefab lightmaps updated");
    99.     }
    100.     [MenuItem("Assets/Bake Prefab Lightmaps")]
    101.     static void GenerateLightmapInfo()
    102.     {
    103.         Debug.ClearDeveloperConsole();
    104.         if (Lightmapping.giWorkflowMode != Lightmapping.GIWorkflowMode.OnDemand)
    105.         {
    106.             Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps and Auto mode is disabled.");
    107.             return;
    108.         }
    109.         Lightmapping.Bake();
    110.         sceneLightmaps = new List<Texture2D_Remap>();
    111.         var scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
    112.         var resourcePath = LIGHTMAP_RESOURCE_PATH + scene.name;
    113.         var scenePath = System.IO.Path.GetDirectoryName(scene.path) + "/" + scene.name + "/";
    114.         PrefabLightmapData[] prefabs = FindObjectsOfType<PrefabLightmapData>();
    115.         foreach (var instance in prefabs)
    116.         {
    117.             var gameObject = instance.gameObject;
    118.             var rendererInfos = new List<RendererInfo>();
    119.             var lightmaps = new List<Texture2D>();
    120.             var lightmaps2 = new List<Texture2D>();
    121.             GenerateLightmapInfo(scenePath, resourcePath, gameObject, rendererInfos, lightmaps, lightmaps2);
    122.             instance.m_RendererInfo = rendererInfos.ToArray();
    123.             instance.m_Lightmaps = lightmaps.ToArray();
    124.             instance.m_Lightmaps2 = lightmaps2.ToArray();
    125.             var targetPrefab = PrefabUtility.GetPrefabParent(gameObject) as GameObject;
    126.             if (targetPrefab != null)
    127.             {
    128.                 //Prefab
    129.                 PrefabUtility.ReplacePrefab(gameObject, targetPrefab);
    130.             }
    131.             ApplyLightmaps(instance.m_RendererInfo, instance.m_Lightmaps, instance.m_Lightmaps2);
    132.         }
    133.         Debug.Log("Update to prefab lightmaps finished");
    134.     }
    135.     static void GenerateLightmapInfo(string scenePath, string resourcePath, GameObject root, List<RendererInfo> rendererInfos, List<Texture2D> lightmaps, List<Texture2D> lightmaps2)
    136.     {
    137.         var renderers = root.GetComponentsInChildren<MeshRenderer>();
    138.         foreach (MeshRenderer renderer in renderers)
    139.         {
    140.             if (renderer.lightmapIndex != -1)
    141.             {
    142.                 RendererInfo info = new RendererInfo();
    143.                 info.renderer = renderer;
    144.                 info.lightmapOffsetScale = renderer.lightmapScaleOffset;
    145.                 Texture2D lightmap = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapFar;
    146.                 Texture2D lightmap2 = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapNear;
    147.                 int sceneLightmapIndex = AddLightmap(scenePath, resourcePath, renderer.lightmapIndex, lightmap, lightmap2);
    148.                 info.lightmapIndex = lightmaps.IndexOf(sceneLightmaps[sceneLightmapIndex].lightmap);
    149.                 if (info.lightmapIndex == -1)
    150.                 {
    151.                     info.lightmapIndex = lightmaps.Count;
    152.                     lightmaps.Add(sceneLightmaps[sceneLightmapIndex].lightmap);
    153.                     lightmaps2.Add(sceneLightmaps[sceneLightmapIndex].lightmap2);
    154.                 }
    155.                 rendererInfos.Add(info);
    156.             }
    157.         }
    158.     }
    159.     static int AddLightmap(string scenePath, string resourcePath, int originalLightmapIndex, Texture2D lightmap, Texture2D lightmap2)
    160.     {
    161.         int newIndex = -1;
    162.         for (int i = 0; i < sceneLightmaps.Count; i++)
    163.         {
    164.             if (sceneLightmaps[i].originalLightmapIndex == originalLightmapIndex)
    165.             {
    166.                 return i;
    167.             }
    168.         }
    169.         if (newIndex == -1)
    170.         {
    171.             var lightmap_Remap = new Texture2D_Remap();
    172.             lightmap_Remap.originalLightmapIndex = originalLightmapIndex;
    173.             lightmap_Remap.originalLightmap = lightmap;
    174.             var filename = scenePath + "Lightmap-" + originalLightmapIndex;
    175.             lightmap_Remap.lightmap = GetLightmapAsset(filename + "_comp_light.exr", resourcePath + "_light", originalLightmapIndex, lightmap);
    176.             if (lightmap2 != null)
    177.             {
    178.                 lightmap_Remap.lightmap2 = GetLightmapAsset(filename + "_comp_dir.exr", resourcePath + "_dir", originalLightmapIndex, lightmap2);
    179.             }
    180.             sceneLightmaps.Add(lightmap_Remap);
    181.             newIndex = sceneLightmaps.Count - 1;
    182.         }
    183.         return newIndex;
    184.     }
    185.     static Texture2D GetLightmapAsset(string filename, string resourcePath, int originalLightmapIndex, Texture2D lightmap)
    186.     {
    187.         AssetDatabase.ImportAsset(filename, ImportAssetOptions.ForceUpdate);
    188.         var importer = AssetImporter.GetAtPath(filename) as TextureImporter;
    189.         importer.isReadable = true;
    190.         AssetDatabase.ImportAsset(filename, ImportAssetOptions.ForceUpdate);
    191.         var assetLightmap = AssetDatabase.LoadAssetAtPath<Texture2D>(filename);
    192.         var assetPath = resourcePath + "-" + originalLightmapIndex + ".asset";
    193.         var newLightmap = Instantiate<Texture2D>(assetLightmap);
    194.         AssetDatabase.CreateAsset(newLightmap, assetPath);
    195.         newLightmap = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
    196.         importer.isReadable = false;
    197.         AssetDatabase.ImportAsset(filename, ImportAssetOptions.ForceUpdate);
    198.         return newLightmap;
    199.     }
    200. #endif
    201. }
    202.  
     
    Last edited: Jan 11, 2016
  35. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    In all the script versions on this thread, it applies the lightmaps in the prefabs to the scene when the script's Awake method is called on the Prefab. The prefabs are just storing a referencing the needed lightmaps. They're not automatically added to the scene by Unity. This is done in the Awake method. Also, the existing lights in the scene will add their light to the prefab unless the prefab renders are set to receive shadows. Ambient light will also affect the lighting of the prefabs in the scene.
     
  36. FreddieL

    FreddieL

    Joined:
    Jan 4, 2016
    Posts:
    4
    Ok, firstly you are an actual angel and it is almost working perfectly. However now I am getting these two errors:

    'Assets/Scenes/SewerRooms/Lightmap-12_comp_light.exr' does not exist
    UnityEditor.AssetDatabase:ImportAsset(String, ImportAssetOptions)
    PrefabLightmapData:GetLightmapAsset(String, String, Int32, Texture2D) (at Assets/Scripts/PrefabLightmapData.cs:234)
    PrefabLightmapData:AddLightmap(String, String, Int32, Texture2D, Texture2D) (at Assets/Scripts/PrefabLightmapData.cs:219)
    PrefabLightmapData:GenerateLightmapInfo(String, String, GameObject, List`1, List`1, List`1) (at Assets/Scripts/PrefabLightmapData.cs:184)
    PrefabLightmapData:GenerateLightmapInfo() (at Assets/Scripts/PrefabLightmapData.cs:152)


    NullReferenceException: Object reference not set to an instance of an object
    PrefabLightmapData.GetLightmapAsset (System.String filename, System.String resourcePath, Int32 originalLightmapIndex, UnityEngine.Texture2D lightmap) (at Assets/Scripts/PrefabLightmapData.cs:236)
    PrefabLightmapData.AddLightmap (System.String scenePath, System.String resourcePath, Int32 originalLightmapIndex, UnityEngine.Texture2D lightmap, UnityEngine.Texture2D lightmap2) (at Assets/Scripts/PrefabLightmapData.cs:219)
    PrefabLightmapData.GenerateLightmapInfo (System.String scenePath, System.String resourcePath, UnityEngine.GameObject root, System.Collections.Generic.List`1 rendererInfos, System.Collections.Generic.List`1 lightmaps, System.Collections.Generic.List`1 lightmaps2) (at Assets/Scripts/PrefabLightmapData.cs:184)
    PrefabLightmapData.GenerateLightmapInfo () (at Assets/Scripts/PrefabLightmapData.cs:152)


    It seems that a few parts of some prefabs are remaining without attached lightmaps for some reason
     
  37. lordnedox

    lordnedox

    Joined:
    Jan 7, 2016
    Posts:
    24
    Yeah, but I can't make it work. A previous post of mine has been withheld for moderation and it's stuck since yesterday, but basically I was saying that even your sample project doesn't work for me, it displays only black objects.
    Tested on 2 different devices, Android 4.1.1 and Android 5.

    I also managed to use AssetDatabase.CopyAsset instead of the other code, but the result was the same.

    I'm glad I found a workaround, at least I can continue my work.

    Cheers
     
  38. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
     
  39. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Does 'Assets/Scenes/SewerRooms/Lightmap-12_comp_light.exr' exist in your project? If not, have you tried baking your scene lightmaps normally (not using the script)? Does it still not exist after that?
     
  40. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Try this version @FreddieL

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEditor;
    3. #endif
    4. using UnityEngine;
    5. using System.Collections.Generic;
    6.  
    7. public class PrefabLightmapData : MonoBehaviour
    8. {
    9.     [System.Serializable]
    10.     struct RendererInfo
    11.     {
    12.         public Renderer renderer;
    13.         public int lightmapIndex;
    14.         public Vector4 lightmapOffsetScale;
    15.     }
    16.  
    17.     [SerializeField]
    18.     RendererInfo[] m_RendererInfo;
    19.     [SerializeField]
    20.     Texture2D[] m_Lightmaps;
    21.     [SerializeField]
    22.     Texture2D[] m_Lightmaps2;
    23.  
    24.     const string LIGHTMAP_RESOURCE_PATH = "Assets/Resources/Lightmaps/";
    25.  
    26.     [System.Serializable]
    27.     struct Texture2D_Remap
    28.     {
    29.         public int originalLightmapIndex;
    30.         public Texture2D originalLightmap;
    31.         public Texture2D lightmap;
    32.         public Texture2D lightmap2;
    33.     }
    34.  
    35.     static List<Texture2D_Remap> sceneLightmaps = new List<Texture2D_Remap>();
    36.  
    37.     void Awake()
    38.     {
    39.         ApplyLightmaps(m_RendererInfo, m_Lightmaps, m_Lightmaps2);
    40.     }
    41.  
    42.     static void ApplyLightmaps(RendererInfo[] rendererInfo, Texture2D[] lightmaps, Texture2D[] lightmaps2)
    43.     {
    44.         bool existsAlready = false;
    45.         int counter = 0;
    46.         int[] lightmapArrayOffsetIndex;
    47.  
    48.         if (rendererInfo == null || rendererInfo.Length == 0)
    49.             return;
    50.  
    51.         var settingslightmaps = LightmapSettings.lightmaps;
    52.         var combinedLightmaps = new List<LightmapData>();
    53.         lightmapArrayOffsetIndex = new int[lightmaps.Length];
    54.  
    55.         for (int i = 0; i < lightmaps.Length; i++)
    56.         {
    57.             existsAlready = false;
    58.             for (int j = 0; j < settingslightmaps.Length; j++)
    59.             {
    60.                 if (lightmaps[i] == settingslightmaps[j].lightmapFar)
    61.                 {
    62.                     lightmapArrayOffsetIndex[i] = j;
    63.                     existsAlready = true;
    64.                 }
    65.             }
    66.  
    67.             if (!existsAlready)
    68.             {
    69.                 lightmapArrayOffsetIndex[i] = counter + settingslightmaps.Length;
    70.                 var newLightmapData = new LightmapData();
    71.                 newLightmapData.lightmapFar = lightmaps[i];
    72.                 newLightmapData.lightmapNear = lightmaps2[i];
    73.                 combinedLightmaps.Add(newLightmapData);
    74.                 ++counter;
    75.             }
    76.         }
    77.  
    78.         var combinedLightmaps2 = new LightmapData[settingslightmaps.Length + counter];
    79.         settingslightmaps.CopyTo(combinedLightmaps2, 0);
    80.  
    81.         if (counter > 0)
    82.         {
    83.             for (int i = 0; i < combinedLightmaps.Count; i++)
    84.             {
    85.                 combinedLightmaps2[i + settingslightmaps.Length] = new LightmapData();
    86.                 combinedLightmaps2[i + settingslightmaps.Length].lightmapFar = combinedLightmaps[i].lightmapFar;
    87.                 combinedLightmaps2[i + settingslightmaps.Length].lightmapNear = combinedLightmaps[i].lightmapNear;
    88.             }
    89.         }
    90.  
    91.         ApplyRendererInfo(rendererInfo, lightmapArrayOffsetIndex);
    92.  
    93.         LightmapSettings.lightmaps = combinedLightmaps2;
    94.     }
    95.  
    96.     static void ApplyRendererInfo(RendererInfo[] infos, int[] arrayOffsetIndex)
    97.     {
    98.         for (int i = 0; i < infos.Length; i++)
    99.         {
    100.             var info = infos[i];
    101.             info.renderer.lightmapIndex = arrayOffsetIndex[info.lightmapIndex];
    102.             info.renderer.lightmapScaleOffset = info.lightmapOffsetScale;
    103.         }
    104.     }
    105.  
    106. #if UNITY_EDITOR
    107.     [MenuItem("Assets/Update Scene with Prefab Lightmaps")]
    108.     static void UpdateLightmaps()
    109.     {
    110.         PrefabLightmapData[] prefabs = FindObjectsOfType<PrefabLightmapData>();
    111.  
    112.         foreach (var instance in prefabs)
    113.         {
    114.             ApplyLightmaps(instance.m_RendererInfo, instance.m_Lightmaps, instance.m_Lightmaps2);
    115.         }
    116.  
    117.         Debug.Log("Prefab lightmaps updated");
    118.     }
    119.  
    120.     [MenuItem("Assets/Bake Prefab Lightmaps")]
    121.     static void GenerateLightmapInfo()
    122.     {
    123.         Debug.ClearDeveloperConsole();
    124.  
    125.         if (Lightmapping.giWorkflowMode != Lightmapping.GIWorkflowMode.OnDemand)
    126.         {
    127.             Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps and Auto mode is disabled.");
    128.             return;
    129.         }
    130.  
    131.         Lightmapping.Bake();
    132.  
    133.         sceneLightmaps = new List<Texture2D_Remap>();
    134.  
    135.         var scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
    136.         var resourcePath = LIGHTMAP_RESOURCE_PATH + scene.name;
    137.         var scenePath = System.IO.Path.GetDirectoryName(scene.path) + "/" + scene.name + "/";
    138.  
    139.         PrefabLightmapData[] prefabs = FindObjectsOfType<PrefabLightmapData>();
    140.  
    141.         foreach (var instance in prefabs)
    142.         {
    143.             var gameObject = instance.gameObject;
    144.             var rendererInfos = new List<RendererInfo>();
    145.             var lightmaps = new List<Texture2D>();
    146.             var lightmaps2 = new List<Texture2D>();
    147.  
    148.             GenerateLightmapInfo(scenePath, resourcePath, gameObject, rendererInfos, lightmaps, lightmaps2);
    149.  
    150.             instance.m_RendererInfo = rendererInfos.ToArray();
    151.             instance.m_Lightmaps = lightmaps.ToArray();
    152.             instance.m_Lightmaps2 = lightmaps2.ToArray();
    153.  
    154.             var targetPrefab = PrefabUtility.GetPrefabParent(gameObject) as GameObject;
    155.             if (targetPrefab != null)
    156.             {
    157.                 //Prefab
    158.                 PrefabUtility.ReplacePrefab(gameObject, targetPrefab);
    159.             }
    160.  
    161.             ApplyLightmaps(instance.m_RendererInfo, instance.m_Lightmaps, instance.m_Lightmaps2);
    162.         }
    163.  
    164.         Debug.Log("Update to prefab lightmaps finished");
    165.     }
    166.  
    167.     static void GenerateLightmapInfo(string scenePath, string resourcePath, GameObject root, List<RendererInfo> rendererInfos, List<Texture2D> lightmaps, List<Texture2D> lightmaps2)
    168.     {
    169.         var renderers = root.GetComponentsInChildren<MeshRenderer>();
    170.         foreach (MeshRenderer renderer in renderers)
    171.         {
    172.             if (renderer.lightmapIndex != -1)
    173.             {
    174.                 RendererInfo info = new RendererInfo();
    175.                 info.renderer = renderer;
    176.                 info.lightmapOffsetScale = renderer.lightmapScaleOffset;
    177.  
    178.                 Texture2D lightmap = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapFar;
    179.                 Texture2D lightmap2 = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapNear;
    180.                 int sceneLightmapIndex = AddLightmap(scenePath, resourcePath, renderer.lightmapIndex, lightmap, lightmap2);
    181.  
    182.                 info.lightmapIndex = lightmaps.IndexOf(sceneLightmaps[sceneLightmapIndex].lightmap);
    183.                 if (info.lightmapIndex == -1)
    184.                 {
    185.                     info.lightmapIndex = lightmaps.Count;
    186.                     lightmaps.Add(sceneLightmaps[sceneLightmapIndex].lightmap);
    187.                     lightmaps2.Add(sceneLightmaps[sceneLightmapIndex].lightmap2);
    188.                 }
    189.  
    190.                 rendererInfos.Add(info);
    191.             }
    192.         }
    193.     }
    194.  
    195.     static int AddLightmap(string scenePath, string resourcePath, int originalLightmapIndex, Texture2D lightmap, Texture2D lightmap2)
    196.     {
    197.         int newIndex = -1;
    198.  
    199.         for (int i = 0; i < sceneLightmaps.Count; i++)
    200.         {
    201.             if (sceneLightmaps[i].originalLightmapIndex == originalLightmapIndex)
    202.             {
    203.                 return i;
    204.             }
    205.         }
    206.  
    207.         if (newIndex == -1)
    208.         {
    209.             var lightmap_Remap = new Texture2D_Remap();
    210.             lightmap_Remap.originalLightmapIndex = originalLightmapIndex;
    211.             lightmap_Remap.originalLightmap = lightmap;
    212.  
    213.             var filename = scenePath + "Lightmap-" + originalLightmapIndex;
    214.  
    215.             lightmap_Remap.lightmap = GetLightmapAsset(filename + "_comp_light.exr", resourcePath + "_light", originalLightmapIndex, lightmap);
    216.             if (lightmap2 != null)
    217.             {
    218.                 lightmap_Remap.lightmap2 = GetLightmapAsset(filename + "_comp_dir.exr", resourcePath + "_dir", originalLightmapIndex, lightmap2);
    219.             }
    220.  
    221.             sceneLightmaps.Add(lightmap_Remap);
    222.             newIndex = sceneLightmaps.Count - 1;
    223.         }
    224.  
    225.         return newIndex;
    226.     }
    227.  
    228.     static Texture2D GetLightmapAsset(string filename, string resourcePath, int originalLightmapIndex, Texture2D lightmap)
    229.     {
    230.         AssetDatabase.ImportAsset(filename, ImportAssetOptions.ForceUpdate);
    231.         var importer = AssetImporter.GetAtPath(filename) as TextureImporter;
    232.         importer.isReadable = true;
    233.         AssetDatabase.ImportAsset(filename, ImportAssetOptions.ForceUpdate);
    234.  
    235.         var assetLightmap = AssetDatabase.LoadAssetAtPath<Texture2D>(filename);
    236.  
    237.         var assetPath = resourcePath + "-" + originalLightmapIndex + ".asset";
    238.         var newLightmap = Instantiate<Texture2D>(assetLightmap);
    239.  
    240.         AssetDatabase.CreateAsset(newLightmap, assetPath);
    241.  
    242.         newLightmap = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
    243.  
    244.         importer.isReadable = false;
    245.         AssetDatabase.ImportAsset(filename, ImportAssetOptions.ForceUpdate);
    246.  
    247.         return newLightmap;
    248.     }
    249. #endif
    250.  
    251. }
    252.  
     
  41. FreddieL

    FreddieL

    Joined:
    Jan 4, 2016
    Posts:
    4
    Working absolutely perfectly now, thank you so much you are a lifesaver
     
  42. Arganth

    Arganth

    Joined:
    Jul 31, 2015
    Posts:
    277
    just to clarify:

    there is no way to do this with directional lightmaps? (may not even be possible?)

    and this cant be done someway with precomputed realtime GI?

    considering to buy
    GI proxy
    https://www.assetstore.unity3d.com/en/#!/content/21197
    to get rid of all this problems
     
  43. tripknotix

    tripknotix

    Joined:
    Apr 21, 2011
    Posts:
    744
    as soon as you rotate prefabs that are lightmapped with directional lighting, they seem to turn black-gray. the lighting information i guess doesnt match up or something.
     
  44. tripknotix

    tripknotix

    Joined:
    Apr 21, 2011
    Posts:
    744
    Does this copy of the file, happen at run time, or at editor time?

    I created a temporary Editor utility for my scene that only has 1 lightmap that finds all PrefabLightmapData and fills in the 1 lightmap. But this is a very specific case to me, as i only have 1 lightmap. it was mainly a temporary solution until they fix the issue.

    Thats why i was asking if the whole thing happens at run time, because i'd rather avoid any additional loadtime/cpu usage and any additional apk size that the fix you posted would cause.
     
  45. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    That hat would make sense. The maps are directional. You'd need to make multiple bakes per direction you want the light to shine in.
     
  46. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    The lightmap copying is done in the editor. Asset manipulation cannot be easily done at runtime since they use the UnityEditor library.
     
  47. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    It does add to the scene. to avoid additional lightmaps, you could remove the original lightmaps from the scene.
     
  48. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    Directional lights should work unless you rotate the prefab. In that cause you'll need to bake the lightmaps per direction you want to rotate it to. You'll need to add additional code to swap the lightmaps.
     
  49. Arganth

    Arganth

    Joined:
    Jul 31, 2015
    Posts:
    277
    thx for the answers :)

    last time i tried the script from the beginning of this thread and with directional (even without rotation)
    the demoscene went half-black (plane and half of sphere)

    but havent tried the newer scripts here
    ill take a look
     
  50. Centripetal

    Centripetal

    Joined:
    May 31, 2013
    Posts:
    96
    I plan on adding support for rotating prefabs with directional light. It'll be a few days or so though since I'm waiting for a replacement for my desktop's motherboard.
     
    idurvesh likes this.
Thread Status:
Not open for further replies.