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. Dismiss Notice

Re Use Baked Lightmap for Mobile

Discussion in 'Global Illumination' started by Gokcan, Jul 2, 2021.

  1. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    Hi All,

    We are developing a mobile game. We have 2 different scene but they both have same light same static meshes. So we wanted to use same light bake on two of them. However, surprisingly I couldnt do it. Do I have to bake two different lightmap for mobile which will increase my app size for nothing... We are using progressive lightmapper with builtin render pipeline.

    I will be happy to hear some methods to achieve this... Thanks...
     
  2. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
  3. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    611
    I think the best path would be to separate your static meshes and lights into a separate scene, and only leave the dynamic stuff in your original scenes. Then additively load the dynamic scenes on top of the static one.
     
  4. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    @JoNax97 Thanks for your help. Yes I think about same but we are late in development. I wonder if it requires more work at this phase...
     
  5. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    I was shocked when I couldnt do it because it seems like really easy thing. Just I want to use same ligtmap at scene. Because when I bake lightmaps, they look identical. However, it will take twice memory in my mobile game which I dont want...
     
  6. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    @kristijonas_unity @KEngelstoft
    Guys, I am still waiting your answers from Unity team. If there is a hacky way, please inform us. There should be. We are at late development and we want to continue....
     
  7. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    416
    Hey @Gokcan,

    Yes, it's totally possible.

    To properly restore lightmapped renderers to the same look in another scene one will need to set the following pieces of data.

    Global:

    Per renderer:

    Per light:
    Please keep in mind that all the properties above are not serialized in the Editor.

    Your script needs to either:
    a. patch the data every time the scene is loaded, both in the Editor and in the player
    b. patch the data in PostProcessScene

    a. allows you to assemble the scene at runtime (in the Editor or in the player), but it can't work with static batching.

    b. requires the scene to exist in the Editor and it can work with static batching.
    Code (CSharp):
    1. [PostProcessScene(-1)]
    2. void PatchLightmapDataOnRenderers()
    3. {
    4.     // [...] patch the data
    5. }
    as static batching happens at
    Code (CSharp):
    1. PostProcessScene(0)
    This way static batching will pick up the data on your renderers and bake it into the static batch.
    Additionally, this is only needed in the Editor, as this callback will be issued when the scene is built for the player and all the data I mentioned above is serialized when building the player.

    Hope this helps!
     
  8. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    Thank you @Kuba really.
    I will start to investigate what you wrote. I am using unity almost 7 years and interestingly never touched these parts:) It could be valuable if I had a basic script or project what U described above...