Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Is there a way to import pre-baked GI Atlas (Lightmap + Shadow Map)?

Discussion in 'Global Illumination' started by arsnyan2002, Jun 23, 2019.

  1. arsnyan2002

    arsnyan2002

    Joined:
    Apr 30, 2019
    Posts:
    25
    Hi! I have a lot of questions about Lightmapping process. I have a HUGE map and GIA (Global Illumination Atlas) for that. Baking everything from scratch is pain in neck, so I want to load pre-baked maps (which are size of 370 MB). I saw how one guy have done this with his own GIA Loader (here's the video). The thing is that he has Unity 5, I have Unity 2019.1.5f1.

    I've tried to make my own importer with that and that information (seriously, that's the only "useful" information I've found), but I think I didn't get it. There's not too much info to understand how everything works in Unity. I also couldn't find any API Documentation. I mean, I've found one, but there's nothing interesting, for my humble opinion.

    So, the code of importer by itself. Don't worry, it's awkward.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections;
    4. using System.IO;
    5. using System.Collections.Generic;
    6.  
    7. public class GIALoader : EditorWindow
    8. {
    9.     string path = "";
    10.     List<LightmapData> data = new List<LightmapData>();
    11.  
    12.     [MenuItem("SU/Open GIA Loader")]
    13.     private static void Open()
    14.     {
    15.         EditorWindow.GetWindow(typeof(GIALoader));
    16.     }
    17.  
    18.     private void OnGUI()
    19.     {
    20.         EditorGUI.LabelField(new Rect(10, 0, position.width - 20, 20), "GIA Folder Path", EditorStyles.boldLabel);
    21.         //string path = EditorUtility.OpenFolderPanel("Put the folder here", "", "");
    22.         //string[] files = Directory.GetFiles(path);
    23.         path = EditorGUI.TextField(new Rect(10, 50, position.width - 20, 20),
    24.             "Path to GIA Folder",
    25.             path);
    26.         if (GUILayout.Button("Generate Lightmap Data"))
    27.         {
    28.             Debug.Log(path);
    29.             DirectoryInfo dir = new DirectoryInfo(path);
    30.             FileInfo[] files = dir.GetFiles("*.*");
    31.             GenerateLightmapData(files);
    32.         }
    33.     }
    34.  
    35.     private void GenerateLightmapData(FileInfo[] files)
    36.     {
    37.         foreach (FileInfo file in files)
    38.         {
    39.             LightmapData ld = new LightmapData();
    40.             Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(file.FullName);
    41.             ld.lightmapDir = texture;
    42.             data.Add(ld);
    43.         }
    44.  
    45.         Debug.Log(data.ToArray());
    46.         LightmapSettings.lightmaps = data.ToArray();
    47.     }
    48. }
    49.  
     
unityunity