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

Lightmap baking for modular scene with 50 000 objects

Discussion in 'Global Illumination' started by Jan-Pieter, Jul 21, 2020.

  1. Jan-Pieter

    Jan-Pieter

    Joined:
    May 20, 2018
    Posts:
    24
    Hello everyone!

    I'm currently creating a big city, with around 8000 instances of 60 different buildings.
    These building prefabs are each made of 3 - 10 models. I only have 32 of those models in total, so the workflow has been very modular so far. Now I want to bake a lightmap for these buildings, but since the light is baked on each and every one of the building parts, this seems, well.. impossible. I'd have a lightmap for every model out of 50k models.

    Now here's my question:
    Is there a way in unity to bake lightmaps for prefabs instead of for every object this prefab is made of?
    If not, what are my options here?

    Thanks in advance!
     
  2. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    168
    There's no way to selectively just bake a prefab and instantiate it.
    What you may be able to do is bake one instance in a separate scene, additively load it and then fix up all other instances with the lightmap parameters of the added in object with a custom script.
     
  3. ADufay

    ADufay

    Unity Technologies

    Joined:
    Jan 2, 2020
    Posts:
    18
    Hello Jan-Pieter.

    There is a trick using a script that can help, however it comes with some drawbacks, please read them carefully before considering using the script :).

    The main drawback is that if you bake a prefab and reuse its baked lighting, it's gonna be a straight copy paste of its lighting. For instance, if the prefab is not shadowed by anything in the prefab mode, you are not gonna get any shadow when you use that prefab in your scene. This can be ok in some scenarios, but it's a pretty limited use case.
    Other drawback is that the lighting setup in the prefab as to match the lighting of your scene to make the baked lighting consistent when you reuse that said prefab in the scene. You will have to manually synchronize lighting between you prefab baking mode and your scene. If it's just a sunlight (directionnal) that could be ok.

    If you think this trick is good for your use case you can have a look at this post:
    https://forum.unity.com/threads/problems-with-instantiating-baked-prefabs.324514/#post-2177524

    Hope that helps,

    Cheers !
     
unityunity