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

How Are Light-Baked Prefabs Supposed to Work?

Discussion in 'Global Illumination' started by John-B, Jan 23, 2019.

  1. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,253
    There is a very long thread on this topic with lots of slightly different code snippets and conflicting sets of step-by-step instructions. I believe I finally got it working, at least it looks like it, but I'm not sure if it's really helping performance.

    I have a test scene with a few static objects that use a baked light map. At runtime I instantiate about 25 different prefabs in the scene. Before I starting trying to bake the prefabs, the Stats window showed 79 batches, 57.3k tris, and 33 SetPass calls. It runs at about 240-250 fps in the Editor. That's my baseline. I took 6 of those prefabs that all share the same material, set them to static, and baked their light maps as discussed in the thread linked above. The scene uses 4 non-directional light maps, 64 MB. Aside from the baked prefabs being a bit dark, it appears to be working. However, now that test scene shows 1298 batches and 35 draw calls, and the frame rate is up slightly to around 250-260 fps.

    This is not a big sample, so I wasn't expecting big effects on performance, but I didn't expect batches to go up, let alone by 16x. And I didn't expect SetPass calls to go up either. I'm not sure the slight difference in frame rate is significant. I was expecting fewer batches and fewer SetPass calls. Isn't that what should happen? Does it sound like I'm doing something wrong with the prefab baking? I don't want to spend a lot of time tweaking the lighting and baking the rest of my prefabs (about 100 different objects) if it's hurting performance.
     
    Jay-Woody and Shorely like this.
  2. Jay-Woody

    Jay-Woody

    Joined:
    Aug 22, 2015
    Posts:
    11
    I would very much appreciate an in-depth tutorial on this matter. I started building my procedural assets and was surprised to find out that baking lightmaps to prefabs isn't built-in in the engine. Seems like a pretty important aspect for procedural generation.

    Haven't gotten the script to work yet and I know I'll be using some time to this, which is a bummer.
     
    sivrikaya and fguinier like this.
  3. fguinier

    fguinier

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    146
    We don't have an offical doc on this indeed, there are plan to have such a doc but no ETA at the moment.
     
  4. Rich_A

    Rich_A

    Joined:
    Nov 22, 2016
    Posts:
    338
    Any updates on this, 15 months later? :)
     
  5. Alexaroth

    Alexaroth

    Joined:
    Feb 4, 2019
    Posts:
    29
    Imagine focusing engine development efforts on features like ECS and other state-of-the-art features, while a simple thing like baked in lighting for prefabs is not supported years down the line...
     
  6. cineconcerts

    cineconcerts

    Joined:
    Dec 18, 2019
    Posts:
    10
    I can't get any method to work. Really sucks.
     
  7. swantonb

    swantonb

    Joined:
    Apr 10, 2018
    Posts:
    154
    Use bakery gpu lightmapper for easy prefab lightmapping