Moderator: ChrisHekman
ChrisHekman wrote:Unity uses an object called LightingDataAsset to store its lightmaps. Regrettably unity does not expose the data in this object.
Ref: https://docs.unity3d.com/ScriptReferenc ... Asset.html https://docs.unity3d.com/Manual/LightmapSnapshot.html
In order to make them work in play mode you will need to set them via script at the start of your scene load.
Ref: https://docs.unity3d.com/ScriptReferenc ... pData.html
We are looking into making a script to do this for the user.
void SetLightmaps( List<Texture2D> LightMaps, List<Texture2D> DirectionMaps)
{
LightmapData[] lightmapData= new LightmapData[LightMaps.Size];
for(int i = 0; i < LightMaps.Size; i++)
{
lightmapData[i] = new LightmapData();
lightmapData[i].lightmapColor = LightMaps[i];
lightmapData[i].lightmapDir = DirectionalMaps[i];
}
LightmapSettings.lightmapsMode = LightmapsMode.CombinedDirectional;;
LightmapSettings.lightmaps = lightmapData;
}
OnlyVR wrote:My bad, I forgot to set my light as static.
OnlyVR wrote:I've tried to use the script to assign the lightmaps in runtime mode but it doesn't work form. Actually my script is a little bit more complicated:
void Start () {
string m_Scene = SceneManager.GetActiveScene().name;
string m_pathLigtmap = "Assets/" + m_Scene + "/Octane/";
DirectoryInfo m_dir = new DirectoryInfo(m_pathLigtmap);
FileInfo[] fileInfoLightMaps = m_dir.GetFiles("*_BEAUTY_DENOISER_OUTPUT.exr");
FileInfo[] fileInfoDirectionalMaps = m_dir.GetFiles("*_LIGHT_DIRECTION.png");
LightmapData[] lightmapData = new LightmapData[fileInfoLightMaps.Length];
for (int i = 0; i < fileInfoLightMaps.Length; i++)
{
lightmapData[i] = new LightmapData();
lightmapData[i].lightmapColor = (Texture2D)UnityEditor.AssetDatabase.LoadAssetAtPath(m_pathLigtmap + fileInfoLightMaps[i].Name, typeof(Texture2D));
lightmapData[i].lightmapDir = (Texture2D)UnityEditor.AssetDatabase.LoadAssetAtPath(m_pathLigtmap + fileInfoDirectionalMaps[i].Name, typeof(Texture2D));
}
LightmapSettings.lightmapsMode = LightmapsMode.CombinedDirectional; ;
LightmapSettings.lightmaps = lightmapData;
}
I can see the script correctly assigned the lightmapper, but in the game window there is no GI light.
Any idea?
public Texture2D[] LightMaps;
public Texture2D[] DirectionalMaps;
void Start () {
...
}
Users browsing this forum: No registered users and 6 guests