Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Assigning lightmap snapshots

Discussion in 'Global Illumination' started by passerbycmc, Aug 23, 2015.

  1. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Wondering if part of the 5.2 releases or in the future, if Unity will ever expose some API for setting the current LightmapSnapshot. I know it cant be done for runtime for obvious reasons, but if it was something available as part of the UnityEditor name space that would be nice.

    I need this since i have a script that will divided 1 larger scene into a bunch of small scenes for streaming in with LoadLevelAdditiveAsync. Than i run the new Lightmapping.BakeMultipleScenes to create lightmaps that can stream in and out based on what chunks are loaded.

    The problem is when i only make gameplay related changes in in my megascene than chunk it back out. I either have to rebake, even know nothing has changed lighting wise. Or i have to manually reassign the lightmap snapshots for each scene.

    Would love to just be able to add some logic to my build process that finds and sets the existing lightmap snapshots.
     
    ArachnidAnimal likes this.
  2. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    I still managed to accomplish what i needed, but via a pretty roundabout way. i had to open a scene as a TextStream than search it for the empty Lightmapsnapshot and swap it for the one i wanted. Which btw was also a pain in the ass to do, since there is no easy way to access the fileID of objects in unity, forceing me to have to go around and use Reflection and the SerializedObject.
     
    ArachnidAnimal likes this.
  3. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,766
    If other people knew how to do what you did it would greatly speed up people's lightbakes. I was having an issue similar to that. I wanted to lightbake sections of the scene at a time, then load individual lightmaps based on bake tag. You can do that, however, it seems the lightmapSnapshot.asset file is required, and must contain all of the information for lightmapping. So that last bake you do must contain all the scene baked at one time. It looks like your solution could overcome that issue too.
     
  4. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Ya my current solution is pretty integrated into the build process for the project i'm working on, but i could make a little script in a day or 2 that applies a new lightmapsnapshot to a unity scene. Just need to clean things up a little since im not sure how stable my current way of reading and writing to the scene file is.

    Since in all my test cases the lightmapsnapshot has been part of the 2nd yaml doc index in the Scene file. But i am not sure if that is always the case yet. I also haven't been able to write out a valid scene file from the yaml serializer i have so for making the change i had to opt to find the lines that contain lightmap snapshot and replace.
     
  5. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,766
    From what i understand they are including alot of lightbaking bug fixes into 5.2 in september. SO ive been holding off until then. Im hoping they fix the issues that slow down lightbaking, cause right now I cannot bake certain scenes yet. hopefully the issues are addressed.
     
  6. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    They didn't fix what im fighting with now, still no native way to assign lightmap snapshots. But they did introduce a nice multibake tool. Also lightmaps properly unload from the lightmap array when you unload a level now.

    I been on the beta and rc of 5.2

    Though for bad bake times, you should make a lightmapsettings preset with lower settings for terrian, as well as setting terrian to use a low scale in lightmap. Aside from that you can get a good boost by setting your small objects to non lightmapped static to force them to use probes. This will greatly speed things up as well as a lot of small probes look better lit with probes.
     
    ArachnidAnimal likes this.
  7. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,766
    i was going to try to set small items to have a very small scale in the lightmap.

    the main issue i was having is the bake failing "radiosity" stage. I believe it has something to do with having small gaps or holes in meshes. Someone from unity said it was fixed in 5.2.
     
  8. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    I have added the 'Assigning lightmap snapshots' to our TODO list for API... No promises on a delivery date though, as we are focusing on bugfixing at the moment.
     
  9. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    That would be amazing, and really helpful to anyone with more complex build workflows
     
  10. rab

    rab

    Joined:
    Nov 13, 2009
    Posts:
    101
    Hello KEngelstoft,

    I already was asking here - can we expect the return of LightmapEditorSettings.LockAtlas and something like LoadLightProbes or LoadLightSnapshot in Unity 5.2?

    Best regards!
     
  11. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    At rab you can still swap the content of lightprobes but not there positions at run time in unity 5. Its just a little bit more complicated since you have to read the SphericalHarmonics that represent the data in the probes, into your own type that you can serialize and re apply later. you can also edit the lightmap array at run time as well. Just cant change the lightmapsnap shot its self.

    I really don't care if i can change the lightmapsnapshot at runtime, i just wish there was a good way to change it via code in the editor.
     
  12. rab

    rab

    Joined:
    Nov 13, 2009
    Posts:
    101
    Hi passerbycmc,

    yes I've read about this way - which is quite complicated compared to the easy LightprobeData assignment in Unity4 via the generated LightProbe.asset file. I hope this function will return with the new LightmapSnapshot.asset file. As far as I understood - the LightmapSnapshot will contain all data for the lightmap related stuff in the scene - so there is also the lightmap atlas contained? Because in Unity5 there is no way for locking atlas generation when baking, which is needed for lightmapping scaled static objects. This has been possible since Unity3 and is now gone in Unity5.

    Unfortunately I don't get a line on this topic from any developer at Unity.

    Best regards!
     
  13. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    Not exactly. 5.2 will introduce multiscene lightmap baking and additive loading of lighting data.
     
  14. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    Lock atlas is not possible in Unity 5, but you can force specific objects into the same lightmap by assigning a Lightmap Parameters with the same Baked Tag.
     
  15. Wiliz

    Wiliz

    Joined:
    Feb 18, 2014
    Posts:
    20
    Any updates on this? Since the end of the support for Unity 4.6 was announced, we have been forced to upgrade our project to Unity 5. It is mostly working fine, but assigning light probes at runtime is still a feature that is completely missing from Unity 5, and our project depends on it.

    To explain our use case: We load scenes additively, and switch the active scene by enabling and disabling game objects manually. Each of our scenes has its own set of light probes which we have baked separately. When we switch the scene, we want to be able to completely replace the active set of light probes with the light probes from that scene. In Unity 4 we could simply save a reference to the LightProbes asset and assign it to LightmapSettings.lightProbes at runtime as needed.

    BakeMultipleScenes was added to solve some additive loading scenarios, but it is not appropriate to our use case. We don’t need the light and shadows to cast to other scenes, and in fact it would not even work in our case because the scenes would overlap each other. We need to be able to bake them separately. Also since this method combines the light probes from all scenes into a single set, it would consume a lot of memory unnecessarily to keep it in memory, when in reality we only need the light probes from one scene at a time.

    Please consider adding this API back soon and keep us updated on its status. Thanks!
     
  16. testure

    testure

    Joined:
    Jul 3, 2011
    Posts:
    81
    This does absolutely jack for those of us who want to bake multiple lighting themes for the same static geometry.
     
    ChayChay likes this.
  17. kevincfy

    kevincfy

    Joined:
    Oct 12, 2012
    Posts:
    16