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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Lightmap Snapshot Backup

Discussion in 'Global Illumination' started by topofsteel, Mar 24, 2015.

  1. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    I'm almost through my first project using Unity5 and GI. I have had a lot of difficulty and it's been a lot of work getting this far. Can snapshots be backed up and reapplied? For that matter, can I switch between snapshots? Thanks.
     
  2. xLeng

    xLeng

    Joined:
    Feb 12, 2014
    Posts:
    19
    Hmm, how dose one save a snapshot in the first place?
     
  3. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    @xLeng the snapshot is generated when you hit the 'Build" button in the Lighting window.

    @topofsteel It would be interesting to hear more about your pain points, what worked well and what we could improve. Please PM me if you find the time.

    You can generate a snapshot, save the file for later and assign it in the Lighting window, but so far the snapshot is an Editor only concept. We are considering adding runtime support later in 5.x but right now additive scene loading is the way to go if you want to switch between different baked lighting.
     
  4. mikamikem

    mikamikem

    Joined:
    Mar 3, 2013
    Posts:
    10
    @KEngelstoft No runtime support and requiring us to use additive level loading for just the lighting snapshot is a major step back from 4.x. We currently have levels that we re-use for different in-game days that have different objects active and different skyboxes/light setups that we are able to swap at runtime in 4.x. This allows us to develop in one level without the need for duplicating our changes across multiple copies of the same level for different times of day and is a necessity for our development process.

    Just to clarify your suggestion, you are saying we can make a single empty level with just the lighting snapshot and additively load that into our current scene to apply the lighting snapshot data to our current scene?

    So if I have Home.unity with all the meshes and game data, but no LightmapSnapshot assigned in editor and then additively load in Home_Monday_Morning.unity which has no meshes or game data, but has a LightmapSnapshot assigned that was generated in Home.unity, that will apply the lightmap data to Home.unity?

    If that is what you're suggesting, I can try it and that will work fine as a workaround for now, but in our game that will increase our number of Unity scene files from 5 to 31 to account for all of our times of day changes, which is really not ideal.

    I'll try the additive level loading suggestion a little later today, but if I misunderstood you please let me know. We need to get this fixed for a conference we are presenting at in mid-April and I'm assuming that your possible runtime support won't happen before then.
     
    mh114 likes this.
  5. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    @mikamikem I don't understand it that way. Currently a published scene has one lightmap snapshot, thats it. You cannot change or share or combine the realtime GI data in that snapshot at runtime. It sound like in the editor you can create, save and reload as many as you want, only in the editor. But you CAN load baked GI lightmaps at runtime just like in Unity4.

    And if I understand correctly, the system they are working on for loading realtime GI data will involve creating one large scene and baking it. Then splitting that scene up into parts (smaller scenes) that can be reassembled at runtime. So no more hot swapping scenes. I'll take ANY solution they have at this point. But not being able to additively load independently created scenes that have realtime GI will be crippling.

    You can do all of your times of day in one scene using realtime GI and lights or emissive materials. SO technically you may not need to load scenes at all.
     
  6. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    Yes, you can load baked lightmaps at runtime and we are working on making it possible to load the other GI data as well...

    We will support both:
    1. Bake separately, merge at load time

    2. Open multiple scenes hit bake button, outputs one light map snapshot but at runtime the data is separated per scene.

    Depending on what you do you choose one or the other.
    2. is better if you want a continuous world with not lighting seams
    1. is better if you work in levels separate from each other.
     
  7. The-True-Zap

    The-True-Zap

    Joined:
    Jan 24, 2015
    Posts:
    3
    How does this work? Let's say I bake a scene with some lights, creating the first lightmap. To be able to bake another one, I have to move the lightmap folder outside of the Assets folder, open the scene again, change the lights and bake a second lightmap (for example day & night lightmap of the same scene). So after this hassle, I have the lightmap data for both scenarios. How can I change the currently assigned lightmaps? In the editor, if I assign it by hand it does have effect only when I hit Play (and only if I previously do some renaming and stuff, I can give the details if you like). But once in playmode, changing the snapshot does have no effect on the scene at all.

    I use BAKED LIGHTS ONLY, no Precomputed Real-Time GI. Using Unity 5.0.1 Pro as of 1. April.

    Thanks in advance!
     
  8. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    I keep hearing the snapshot file is an editor-only file. it is NOT and editor only file. The file is somehow referenced by Unity when generating a build. It is trivial to test:
    generate multiple lightmaps files for a scene.
    Generate a script to set the lightmap files accordingly during runtime(. http://wiki.unity3d.com/index.php/LightMapSwitcher)
    Create a build with the snapshot file where is was,
    Run the game. The lightmaps are applied to the scene accordingly.

    Now do the same exact thing but delete the snapshot file before you do the build. Now the lighmaps will not be applied when running the build.
    So it is not an editor-only file.
     
  9. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    The Unity 5.2 feature for baking multiple scenes and using additive loading should makes this process much more smooth for you. See this for details (from the 5.2 beta forum) https://docs.google.com/document/d/1kfCuoxNrfsUWyIR0l2sf3PTcx0Jb2ccFRoEGBlS4-qs/edit
     
  10. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    It is an editor only file. Building the player is done by the Editor and it is using the data in the lightmap snapshot. So removing the snapshot file will cause the lightmaps to disappear because the editor can't copy them to the player build.
     
  11. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    ok, thanks for the explanation. I got confused by the term "editor-only". Because you can assign an "Editor Only" tag to a game object, then it is ignored when creating a build, so I assumed editor only meant the same thing when referring to the snap shot file.
     
    Last edited: Jul 17, 2015
  12. WagDan

    WagDan

    Joined:
    Nov 7, 2014
    Posts:
    37
    Can we write our custom lightmaps into a snapshot? Can we use the snap shot to store the array and index info? From custom baked lightmaps from outside of unity3d?
     
  13. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    Lightmap index, scale and offset is set on the renderer, so the scene isn't dirtied every time you bake. If you want to use lightmaps from a 3rd party DCC tool, you should not set it on the snapshot, you should use this: http://docs.unity3d.com/ScriptReference/LightmapSettings-lightmaps.html
     
  14. harish-g9

    harish-g9

    Joined:
    Jan 29, 2013
    Posts:
    7
    Hi,

    I migrated my project from Unity 4.5.5 to Unity 5.1.2. I see there is problem with Lightmaps. I tested with generated lightmaps only for one of the model I used in the project. The problem is I use several models with different light maps and I load only those light maps what are selected. I mean if I select one model, lightmaps that are related to the model will be loaded through the LightmapSettings class. But Unity5 generates LightmapSnapshot file for each model we bake and we cant change the lightmapsnapshot file during the runtime. How could I solve this issue? Any help would be appreciated.
     
  15. WagDan

    WagDan

    Joined:
    Nov 7, 2014
    Posts:
    37
    Thank you. We got it working now. Using the renderer. :)
     
  16. xueye

    xueye

    Joined:
    May 20, 2015
    Posts:
    3
    Hi,
    I want to know can i use the generated snapshot in another scene? For example,i have two scenes in which the models and light settings are same.I baked one and use the generated snapshot in another scene,but it didn't look like expect.What should i do to make the two scenes look same ?Please help me
     
  17. marcojacovone

    marcojacovone

    Joined:
    Jul 7, 2014
    Posts:
    63
    Hi @KEngelstoft ,
    I'm working to a lightmaps manager editor extension that manage many light configurations, bake them and give the chance to switch from one configuration to another at runtime.

    It works fine for all light maps, light probes and reflection probes in the scene, by switching pre-baked objects into the LightmapsSettings object as well as reflection probes instances. For light probes I can only modify coefficients at runtime, because probes positions are read-only. The overall tool however works fine.

    In this scenario make sense to have different light probes due to different shadows that the scene may have, because of different lights setups for pre-baked light maps.
    My initial idea was to give to the user the possibility to specify different sets of light probes that the tool can enable/disable just before the automated light mapping bake process.

    But, because light probes resides in snapshot, and it is an editor-only file, I cannot switch it at runtime.
    You confirm that?

    In my switch process I:

    1) Switch lightmaps (lightmapData)
    2) Modify light probes coefficients
    3) Modify reflection probes baked textures
    4) All with the same snapshot file

    It is the correct way?

    Thanks in advance,
    Marco