Search Unity

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,094
    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:
    7
    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:
    114
    We don't have an offical doc on this indeed, there are plan to have such a doc but no ETA at the moment.