Generated lightmaps are removed on unity play

Forums: Generated lightmaps are removed on unity play
A public forum for discussing and asking questions about the Octane for Unity Alpha

Moderator: ChrisHekman

Generated lightmaps are removed on unity play

Postby monkeybrother_1 » Sun Jun 24, 2018 4:45 pm

monkeybrother_1 Sun Jun 24, 2018 4:45 pm
I'm playing around with the lightmapper, but when I press play, all lightmaps are cleared. Is this correct beta behaviour or am I missing something?
monkeybrother_1
 
Posts: 2
Joined: Sun Jun 24, 2018 4:38 pm

Re: Generated lightmaps are removed on unity play

Postby ChrisHekman » Mon Jun 25, 2018 9:14 am

ChrisHekman Mon Jun 25, 2018 9:14 am
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.
ChrisHekman
OctaneRender Team
OctaneRender Team
 
Posts: 968
Joined: Wed Jan 18, 2017 3:09 pm

Re: Generated lightmaps are removed on unity play

Postby monkeybrother_1 » Mon Jun 25, 2018 9:52 am

monkeybrother_1 Mon Jun 25, 2018 9:52 am
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.


Ok. Do you have an example that shows how this could look in code?
monkeybrother_1
 
Posts: 2
Joined: Sun Jun 24, 2018 4:38 pm

Re: Generated lightmaps are removed on unity play

Postby ChrisHekman » Mon Jun 25, 2018 11:58 am

ChrisHekman Mon Jun 25, 2018 11:58 am
Similar to this
Code: Select all
   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;   
   }
ChrisHekman
OctaneRender Team
OctaneRender Team
 
Posts: 968
Joined: Wed Jan 18, 2017 3:09 pm

Re: Generated lightmaps are removed on unity play

Postby OnlyVR » Wed Jun 27, 2018 3:34 am

OnlyVR Wed Jun 27, 2018 3:34 am
How to bake the lightmaps? I can successfully render in PBR Viewport but "PBR Lightmapping" creates black PBRLightmap_N_LIGHT_DIRECTION.png and PBRLightmap_N_IRRADIANCE.exr files.
What am I missing ? Any special settings for camera etc?

My bad, I forgot to set my light as static.
OnlyVR
 
Posts: 5
Joined: Wed Jun 27, 2018 2:57 am

Re: Generated lightmaps are removed on unity play

Postby ChrisHekman » Thu Jun 28, 2018 8:12 am

ChrisHekman Thu Jun 28, 2018 8:12 am
OnlyVR wrote:My bad, I forgot to set my light as static.



:) I have run into that problem so many times.
ChrisHekman
OctaneRender Team
OctaneRender Team
 
Posts: 968
Joined: Wed Jan 18, 2017 3:09 pm

Re: Generated lightmaps are removed on unity play

Postby OnlyVR » Mon Jul 02, 2018 5:32 pm

OnlyVR Mon Jul 02, 2018 5:32 pm
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?
OnlyVR
 
Posts: 5
Joined: Wed Jun 27, 2018 2:57 am

Re: Generated lightmaps are removed on unity play

Postby ChrisHekman » Tue Jul 03, 2018 9:58 am

ChrisHekman Tue Jul 03, 2018 9:58 am
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?

This looks correct.

Couple of possible issues
- "Baked Lightmap" atlas info was not saved to scene.
You can check this by selecting a static MeshRenderer. In the inspector check Lightmap Settings -> Baked Lightmap
If the atlas is 65535 that means it did not save its atlas info.
AtlasData.png

- Textures are not found by the assetdatabase and the lightmapsettings are filled by null textures

- Script start function is not called when going into play mode.


Additional comment
- "UnityEditor.AssetDatabase" is not useable from a standalone build of your game.
My advice would be to do the following:
Code: Select all
public Texture2D[] LightMaps;
public Texture2D[] DirectionalMaps;
void Start () {
...
}

And then fill those lists manually.
ChrisHekman
OctaneRender Team
OctaneRender Team
 
Posts: 968
Joined: Wed Jan 18, 2017 3:09 pm

Return to Octane for Unity


Who is online

Users browsing this forum: No registered users and 6 guests

Thu Mar 28, 2024 3:18 pm [ UTC ]