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

Using Lightmaps from Multiple Scenes in One Scene?

Discussion in 'General Graphics' started by ZackLaznick, Jan 5, 2015.

  1. ZackLaznick

    ZackLaznick

    Joined:
    Nov 5, 2014
    Posts:
    6
    Hi all,

    I'm currently trying to get myself out of a lightmapping issue. I've been working on a Unity arch/viz project for a client for a few months now. Being a novice at lightmappign before starting this project, I've been able to teach myself most of what I need to know.

    I'm taking 3 sections of a skyscraper that are meant to be turned on/off to show off major sections of the building. The bottom floor is the "Lobby" slice, the middle is the "Office" slice, and the top is the "Roof". In order to get the baked lighting look I'm looking for, I've decided to put each slice into their own individual scenes and bake each slice separately.

    I have been able to get my separate bakes, but whenever I try to merge one slice from a separate scene into my current scene (ex: try to take the Office slice from one scene and put it into the Lobby scene), the lightmapping looks all wonky and bad. I assume it has to do with the current scene trying to write it's current lightmap data onto the merged slice rather than merging the lightmaps from the other scene.

    I've tried copy/pasting the slice and also making a prefab of the slice, but it still looks wrong. Is there any way around this or is it impossible to use lightmaps from two separate scenes? I apologize if this isn't a good explanation. :/
     
  2. OllyNicholson

    OllyNicholson

    Unity Technologies

    Joined:
    Jun 17, 2011
    Posts:
    142
    When Unity lightmaps a scene it uses a separate 2nd UV channel and the appropriate UV layout as specified for each of model files (e.g. 'apply light-mapping UV's' or imported UV mapping) then on a per scene basis it generates lightmaps based on bouncing light (GI) in the scene between the objects in regard of scene lightmapping parameters, e.g. number of maps, resolution etc. as specified in the docs:

    http://docs.unity3d.com/Manual/LightmappingInDepth.html

    Unity has no concept of merging scenes in regard of lightmapping as lightmapping would need to treat any merged objects from different scenes together as one scene in order to calculate the influence of light between each other. To that end you have a choice to load separate scenes together at run-time or in your game view e.g

    http://docs.unity3d.com/ScriptReference/Application.LoadLevelAsync.html

    Or simply re-lightmap the new merged scene, to the best of my knowlegde.
     
  3. Neodrop

    Neodrop

    Joined:
    Oct 24, 2008
    Posts:
    1,358
    But, when I load scene, all my lightmaps seems broken. The objects from additively loaded scene lost lightmaps and gone white, and original scene objects has change lightmaps in wrong way.

    LightmapBug.png
     
    IgorAherne likes this.
  4. jnt

    jnt

    Joined:
    Sep 30, 2014
    Posts:
    15
  5. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    984
    It's not clear if the OP was talking about at run-time, or in the editor. In the editor, I don't think so. But at run-time I can get baked lightmaps to come in fine, but not real-time. If I try to load real-time GI, only the last loaded scene works, and at that the contrast is off. And loading the baked maps, I do get errors about missing GI files, even tho I dont have real-time GI in the scenes i'm trying to load.

    What's adding to my problems is the whole chasing thing. It's tough to get clean tests because if you have baked real-time GI into a scene once, it thinks it's still there. You can clear the cache of the project, but that wipes everything out.

    I've heard you can get the GI snapshot into a scene by creating an asset bundle of the scene, loading it, then loading that scene. But i've not worked through that yet.
     
  6. jnt

    jnt

    Joined:
    Sep 30, 2014
    Posts:
    15
    I'm not trying to load realtime GI, just baked GI. Not working at all for me.
    How did you get it to work?

    Are you talking about importing the asset bundle in the editor? That wouldn't help for additive loading though right?
     
  7. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    984
    I'm simply loading the scenes with loadleveladditive. I'm not doing any other coding regarding the index or anything. (see link below)

    No, importing the asset bundle at runtime then loading the level as you normally would. Sounds like it just makes the lightmap snapshot available, but like I said, I haven't tried or worked through it yet.

    http://www.topofsteel.com/images/2015-03-12_0842.swf
     
  8. jnt

    jnt

    Joined:
    Sep 30, 2014
    Posts:
    15
    Thanks for the reply. I created a new project just to test if I was missing something. But nope, it's still the same. Unless anyone can spot another reason why this might not be working for me?



    This project is super simple, and my script is just

    Code (CSharp):
    1. void Start ()
    2.     {
    3.         Application.LoadLevelAdditive("scene1");
    4.         Application.LoadLevelAdditive("scene2");
    5.     }
    But unfortunately no luck. Are we on different versions of Unity here? I'm on 5.0.0f2 Pro.

    I'm gonna give it a try on my other PC later today to see if it's a problem with my install or my system or something...
     
  9. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    984
    @jnt What rendering path you using? I just did another test project and It didn't work, I couldn't see the lightmaps. I was in was in forward. Switched to deffered and it worked.
     
  10. jnt

    jnt

    Joined:
    Sep 30, 2014
    Posts:
    15
    I have tried that before, and just tried again in 2 different scenes, but no change, lightmaps sill not loading...
     
  11. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    I have the same issue as you, I even think mine is worst.
    simple scene with loadLevelAdditive

     
  12. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    984
    Baked or realtime?
     
  13. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
  14. FrancisDuranceau

    FrancisDuranceau

    Joined:
    Aug 13, 2012
    Posts:
    10
    If you check the settings of your Directional Light from the first scene, is it setup for mixed mode? Because it should be baked.
     
  15. jnt

    jnt

    Joined:
    Sep 30, 2014
    Posts:
    15
  16. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    984
  17. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    411
    Released version of Unity is 5.0.0f4, so please verify your use cases against that, especially that there were some fixes to baked lightmaps wrt additive level loading in one of the last release candidates.

    Once you confirm that baked lightmaps don't behave as expected when additively loading levels, please submit a bug report and post the case number here. Thanks a bunch!

    Please note that additive loading of light probes is not supported yet, but we want to make that work ASAP. See: http://forum.unity3d.com/threads/unity-5-additive-light-probes.307897/#post-2027535
     
  18. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    411
  19. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    @topofsteel thanks for your scene! It helped me find from where the issue is coming from. So in your project if you bake pre computed Realtime GI in the Hall_Bake scene or Room_Bake you do have the issue even if lights are set to bake only and that was my issue too.
     
    Last edited: Mar 19, 2015
  20. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    984
    I believe I removed everything from the scene except the mesh. But yes, I had my point lights set to bake only. If it helped you, great!
     
  21. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    so that means at the moment there is no way to have pre-computed real time GI in multiple scene and merge them at run time right?
     
  22. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    411
    That is correct. We'll lift that limitation ASAP; I'll poke back here when we'll know the exact timing.
     
    OllyNicholson likes this.
  23. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    Great, one of our project desperately need this kind of feature because the levels will be generated proceduraly.
     
  24. Lasse Juul-Jensen

    Lasse Juul-Jensen

    Joined:
    Aug 21, 2014
    Posts:
    7
    I'm unsure whether our problem is directly related, but we have problems saving changes to
    lightmapScaleOffset / m_LightmapTilingOffset on our objects.
    The value is succesfully set and used when launching the scene in the editor,
    but the changes are removed when loading a new scene.
    Specifically, we do the following using a ScriptableObject:

    private static void SetLightInfoOnObject(LightmapOffsetInfo lightmapOffsetInfo)
    {
    Renderer renderer = lightmapOffsetInfo.GetComponent<Renderer>();
    renderer.lightmapScaleOffset = lightmapOffsetInfo.lightmapOffset;
    EditorUtility.SetDirty(renderer);
    }

    We have tried setting lightmapScaleOffset on a normal MonoBehaviour Awake() aswell.
    This works well, when running the scene in the editor, but does not work when building the game for e.g. PC.

    Is this problem related and is there any way to force Unity to save the changes to lightmapScaleOffset?
     
  25. FeynmanRen100

    FeynmanRen100

    Joined:
    Sep 6, 2013
    Posts:
    22
    I have the same issue with you ~~


     
  26. Julinoleum

    Julinoleum

    Joined:
    Aug 31, 2011
    Posts:
    39
    We've been able to load an additive scene with the lightmaps and the tiling offset still correct on the objets but what about using prefabs? Previously, it was possible to save the index while applying a prefab but now I havent been able to make it work that way. Additive scenes are cool but we're building platforms with prefabs in a lightmap template scene. I've been doing that for a few game and now I'm stuck without that option. :(
     
  27. SpiriTx

    SpiriTx

    Graphics QA Unity Technologies

    Joined:
    Apr 12, 2012
    Posts:
    252
    Indeed, there's already a bug on that in the system
    http://issuetracker.unity3d.com/iss...baked-gameobject-to-prefab-with-lightmap-info
     
  28. Julinoleum

    Julinoleum

    Joined:
    Aug 31, 2011
    Posts:
    39
  29. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    411
    This is by design, as it's generated data and it shouldn't be stored in the scene and it shouldn't dirty the scene.
    See my answer here: http://forum.unity3d.com/threads/lightmapping-nightmare.317008/#post-2060995

    Also, this is not related to this thread. :)
     
  30. Julinoleum

    Julinoleum

    Joined:
    Aug 31, 2011
    Posts:
    39
  31. DarekLosu

    DarekLosu

    Joined:
    Feb 19, 2015
    Posts:
    2
    I was able to find a way around it. I'm loading prefab objects and meshes from resources with correct lightmap data on them. But in editor, even if I just duplicate lightmapped object (prefab) the copy has got broken lightmapping...

    When saving my prefabs to resources I was copying lightmapIndex and lightmapScaleOffset, but to properly copy an object (preserving lightmapping) you need to also copy realtimeLightmapScaleOffset. Once this is copied to a new object, all of the lightmap data is preserved.

    So for all of you who are assigning lightmapIndex and lightmapScaleOffset, try additionally assigning realtimeLightmapScaleOffset.

    Hope this helps some of you.
     
  32. polope

    polope

    Joined:
    Apr 1, 2015
    Posts:
    3
    Found the properties on the MeshRenderer. I made a little component that store the values so they can be applied at runtime when the Awake is called. It works fine in the Editor but not on mobile.
    Any chance you tested your script on mobile?
     
    Last edited: May 20, 2015
  33. DarekLosu

    DarekLosu

    Joined:
    Feb 19, 2015
    Posts:
    2
    My project works on mobile but my use case is slightly different. I'm using a script to create prefabs in resources.
    As source I'm using lightmapped prefabs which are set up properly on a scene (with working lightmaps).
    Then in game I'm loading and instantiating prefabs from resources.

    So my scenes don't have any lightmap data. I'm loading objects and setting lightmap array after scene is loaded.
     
    locbui likes this.
  34. locbui

    locbui

    Joined:
    Nov 4, 2013
    Posts:
    13
    Hi there,
    Can you share your snippet for loading lightmap at runtime ?
    Thanks,
     
  35. Maffew

    Maffew

    Joined:
    Jan 22, 2014
    Posts:
    14
    This is STILL an issue for me in Unity 5.1.1.f1 - I've got it looking ALMOST correct in the editor but the lightmaps are not getting loaded in a build.
     
  36. NorthernVisionStudio

    NorthernVisionStudio

    Joined:
    Oct 18, 2013
    Posts:
    60
    I was just able to merge a scene with realtime GI into an existing scene using 5.2.0b6. Not only this, but from an asset bundle. I hope this functionality makes it to release. My product is depending on it now. Great work, devs at Unity ( and Kuba)
     
  37. rzigura

    rzigura

    Joined:
    May 26, 2015
    Posts:
    2
    I use Unity 5.2.0f3. Unable to merge Realtime GI from another scene LoadLevelAdditive. Is this feature still missing from the release?
    Thanks,

    Edit: Managed to make it work by disabling Auto realtime GI calculation
     
    Last edited: Sep 20, 2015
  38. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    882
    any idea about prefab ?
     
  39. deekpyro

    deekpyro

    Joined:
    Oct 16, 2012
    Posts:
    62
    I am converting one of my Unity 4 projects over to Unity 5.2.3 and I'm running into a lightmapping snag. I have a main scene which the game loads into and then I load in scenes (different environments) additively. Most work but one scene loads in usually dark.

    Here it is in it's own scene:


    And here it is additively loaded in (no changes to the lights in the scene):


    I only have one light that's affecting the scene and it's a baked light loaded in with the scene. Is anyone else having this type of issue?
     
  40. SpiriTx

    SpiriTx

    Graphics QA Unity Technologies

    Joined:
    Apr 12, 2012
    Posts:
    252
    Is that in editor? Does the scene use "Auto" bake?
     
  41. deekpyro

    deekpyro

    Joined:
    Oct 16, 2012
    Posts:
    62
    Nope, Auto Bake is off.

    Edit: Thankfully I found it was one of my own scripts that was doing the color adjusting, problem solved.
     
    Last edited: Dec 6, 2015
  42. Actiview

    Actiview

    Joined:
    Dec 4, 2013
    Posts:
    33
    Hello everybody,
    I would like to know if there is any progress regarding the workflow pointed out in this thread?

    What I'm trying to achieve workflow wise, is be able to take a gameobject (or several for that matter) from my main scene, separate it into a different scene, bake it there with my own lighting scheme, then bring it back into the main scene and have it use the baked data there.

    Is that workflow possible now?

    Also, as the baking process creates an exr file, maybe its possible to make a modification to the standard shader, in which there is also a slot for baked lighting, in which I will be able to drop my baked lightmap and have it projected onto the object. What do you think??

    Any help/insights regarding how to achieve this will be much appreciated.
     
  43. jnt

    jnt

    Joined:
    Sep 30, 2014
    Posts:
    15
    We are creating a 3D game with dynamically loading levels:
    1. Create prefabs for all your Art.
    2. Create levels using these Art prefabs.
    3. Bake lightmaps for each level separately and store the lightmaps.
    4. Serialize each level using your own choice of serialization method (we use json), we serialize the following properties for each prefab:
      • Position and rotation.
      • Renderer lightmap index.
      • Renderer lightmap scale.
      • Renderer lightmap offset.
    5. Dynamically deserialize the sections, load the required lightmaps into the lightmap data array, and set the lightmap index, scale and offset manually for each renderer in each prefab that you load. For this to work, you need to change the "Lightmaps mode" to "Manual" in Edit > Project Settings > Graphics.
    6. Set all baked lights inside deserialized prefabs to be off, or, if you are using mixed lights, set the "HasBeenLightmapped" property to true, otherwise objects that have been baked will still be lit by these lights.
    I hope that gives you some idea of how it could work, and at least somewhere to start. It is working for us. If you need more details of how we did it and what I've learnt in the process let me know. We are planning on doing a proper post on all of this when we're not spending every free moment working on the game! ;)
     
    Arkade likes this.
  44. Actiview

    Actiview

    Joined:
    Dec 4, 2013
    Posts:
    33
    Thanks for the awesome response jnt.
    I actually spent the last 2 days trying to figure out the correct workflow for us, and surprisingly came up with one pretty similar to yours, so looks like we're on the right track ;)
    What i'm facing now is the deserialization and loading of lightmaps part, so if you have any scripts/insights to share would be amazing!
    Also, the change the "Lightmaps mode" to "Manual" trick was really helpful.
    Can't wait to read your blog post regarding the workflow! Please also post it here once written.

    Cheers
     
  45. Actiview

    Actiview

    Joined:
    Dec 4, 2013
    Posts:
    33
    Ok, So I've managed bringing all the lightmaps, and all the objects baking parameters into the main scene.
    Now what I'm having trouble with is that I load the lightmaps dynamically into the LightingData.asset file, and it shows up ok in runtime, but once I get back to editing mode, all the changes I've made to the LightingData.asset file are not saved.

    Is there anyway of saving those changes I've made to the LightingData.asset file??

    Many thanks
     
  46. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    Hey, I still have problem loading a scene with SceneManager.LoadScene (LevelName, LoadSceneMode.Additive);

    My first scene is a completely empty scene with no Baked GI or RealTime GI and Auto bake is off.
    The scene I want to load uses Baked GI only and Auto bake is off, all lights are baked except one directional that is in mixed mode and we are using forward rendering.

    we are on unity 5.3.1

    When I load my scene the meshes are all white or black. Is it a bug or is it still not possible to do this?

    thanks!


    Edit:
    I found out that I also had to have Baked GI on in my first scene, now it's working!
     
    Last edited: Jan 27, 2016
  47. NGC6543

    NGC6543

    Joined:
    Jun 3, 2015
    Posts:
    213
    Hi, I have a question about the lightmap in Unity.
    I have a scene with a baked lightmap. But I want another scene with some modification to this scene, so I duplicated(CMD+D) the scene from the Project pad, renamed and opened it. I tweaked some objects, and re-bake the scene.
    But the problem is, the baked lightmap atlas is saved(overwritten) at the original scene's lightmap folder. What I intended to do is to have two seperate scenes with different lightmap data.
    I thought Unity creates lightmap folder with respect to the name of the scene file(*.unity), but it seems like there are some bug, maybe?? Those to scene have different name, obviously. Or, did I do something wrong, like not using 'save as' or so?
     
  48. TANGSTENcq

    TANGSTENcq

    Joined:
    Mar 30, 2015
    Posts:
    7
    I am having the exact same issue as NGC6543. The problem in my project consists of:
    - The project uses 2 separate scenes.
    - Each scene uses the same terrain prefab and the scene element prefabs,
    - Each scene is baked using the same GI Baked only settings on.
    - Each scene uses the same light probe prefab and the same reflection probe prefab.

    Each scene has the same settings for the Baked GI.

    Problem: When I bake the lightmap in one scene. The other scene's lightmap is overwritten. Very frustrating. I tried making two separate folders with the baked lightmaps but it still caused the same issue when loading scene to scene. One had beautiful lighting the other was completely black.
    Next, I tried to copy the good reflection probe exr and lightmap atlases from one scene folder into the other scenes folder and re-imported them. Still not working. I get an error that it was unable to re-import the settings and that i need to rebake. But I know if I rebake the lightmap in this scene my other good scene will be back to square 1.

    What am I doing wrong exactly? I'm using Unity 5.3.2f1.

    Thanks - Joe
     
  49. TANGSTENcq

    TANGSTENcq

    Joined:
    Mar 30, 2015
    Posts:
    7
    I figured it out.
    1 Project
    2 Scenes
    1 Prefab Terrain (Exists in both scenes.)
    2 Prefab Light Groups (Each light group consisting of Directional, Point, or Area lights all set to baked. The reflections probes and light probes also need to be assigned per scene using separate prefabs.)
    These 2 Light group each have their own reflection probes and light probes.
    You just gotta keep em separated. ;)
    • The trick to not overwriting your lightmaps is that you bake 2 different sets of lights, 2 different sets of reflection probes, and 2 different sets of light probes.
    • Use 2 separate light groups that have their own individual reflection probe prefabs and light probe prefab. Using one overwrites itself. Why this started to happen in 5.3? I don't know. But this works. I also don't do additive scene loads. I just replace the whole scene.
    • Make sure you name the lightmaps for the scene you're baking simply so you won't get confused about which lightmap is being used for which scene. It avoids the whole missing lightmap issue. If someone has a better explanation I'd love to know.
    Thanks -Joe
     
    NGC6543 likes this.
  50. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    558
    Heya Joe,
    With this solution could you in theory:
    -have a prefab in each scene with static geo and lights/light probs effecting that geo.
    -bake each scene separately
    -Manually or through code put all those prefabs into the same scene.


    I have an issue with floating point precision errors (unity really needs a better solutions for this) but also need to use static geo. So I'm currently enabling/disabling "Blocks" of static geo and warping the player to new locations. Does the above workflow match what you are doing to preserve light maps?
     
unityunity