Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Graphics Serialize Lightmap Data

Discussion in '5.2 Beta' started by ObliviousHarmony, Jul 8, 2015.

  1. ObliviousHarmony

    ObliviousHarmony

    Joined:
    Jul 3, 2014
    Posts:
    79
    Hello,

    I'm not entirely sure that this question is 5.2 specific, so I apologize in advance if it isn't.

    With the new multi-scene building of lightmaps, is there any way to access this data? I know in the past (and present?) you could access the static data through LightmapSettings.lightmaps, but I'm wondering if there's a way to get/set the realtime data as well?

    I've been developing my game tools with the intention of releasing them to the public for modding, and one component of that is the ability to create new environment modules (small ship interior modules, containing the meshes for it, maybe some props and lighting). These environments will be saved to a unique data structure, and then loaded at run-time to create the environment using the modules. In an effort to make all of this look as nice as possible, I'd love to know if there's a way to leverage the full power of GI with this method.

    If this is not possible, would a viable alternative be to compile the scenes into an asset bundle and load that? Is there anything I have to look out for with this method? Right now, my mods are in two components (and then placed into Zip archives with a manifest to load them in order). A Json file for data that is volatile in nature, and binary files for data that is not (meshes, textures, materials, etc). Would replacing these binary files with an asset bundle be a better design? One bundle would still work on all standalone platforms/architectures right? (The main reason for avoiding it to begin with was to more effectively control the final imported/exported objects, such as keeping them from adding scripts that we don't want them to add. Though, the same effect could be achieved by removing any unexpected data :D)
     
  2. mikamikem

    mikamikem

    Joined:
    Mar 3, 2013
    Posts:
    10
    We also need getting/setting the realtime data in standalone builds for our game. We are currently swapping the lightmaps, but we would love to be able to do realtime GI swapping as well. I was hoping that the multi-scene light baking would be implemented in a way that exposed the realtime data, but it looks like that's not the case.

    Is there any possibility this will be exposed in 5.x?
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    In 5.2 we have Lightmapping.BakeMultipleLevels(string[] levels) which autoamtically bakes lightmaps and packs them for each scene.

    We are also working towards Application.UnloadLevel(string scene); which unloads the game objects of the scene but also the lightmaps and enlighten data. I am very curious about the use cases where you would like to access the enlighten lightmap data from code beyond load/unload.
     
  4. ObliviousHarmony

    ObliviousHarmony

    Joined:
    Jul 3, 2014
    Posts:
    79
    For me at least, the need for it was brought on by Asset Bundle scene loading not working in Unity 5.x. If that worked, I would simply use asset bundles for the binary data instead of a separate serialization method.

    I ran into a bug where the bundles wouldn't load more than one scene, and then after you guys fixed that, there was another bug where they lost all their references. As I couldn't afford to wait for a fix (I'd waited a month or so for the first fix), I was forced to use a different serialization method for these art prefabs (which I'm not sure if it has been fixed yet, I haven't read anything about it in the patch notes http://issuetracker.unity3d.com/iss...-references-if-the-assetbundle-has-two-scenes)

    That said, I suppose I could switch back to asset bundles if I limited them to one scene per bundle. When you load multiple bundles, will they automatically make use of materials and meshes that are already loaded, or will they create new instances altogether?

    Edit: Multi-scene loading fixed in 5.2! "Assets Loading: Fix non-first scene loading from streamed asset bundle with multiple scenes"
     
  5. mikamikem

    mikamikem

    Joined:
    Mar 3, 2013
    Posts:
    10
    Sorry ObliviousHarmony, I thought you were talking about the same thing that I was doing, didn't mean to hijack your thread.

    My use case was specifically for having one Scene that was used in different in-game days and times of day where we would be enabling and disabling objects based on the day and swapping the skybox and directional lights. I'm not sure how the data is currently being baked into the scenes on build, but even if it was possible to associate multiple LightmapSnapshots to the same level and activate one of them from code at runtime or even on level load, that would solve my issue as well. I can start another thread if you need more info about my use case since it's different then what ObliviousHarmony was asking for.
     
  6. ObliviousHarmony

    ObliviousHarmony

    Joined:
    Jul 3, 2014
    Posts:
    79
unityunity