For medium sized scenes, where you may have more render threads than objects in the scene, the trick to fast lightmap renders is to keep the lightmap resolutions even. But I’ve recently discovered the missing elements in my scenes that speed up my renders by 500%!
Let’s say for example you have a total of 24 cores to render your lightmap with and your scene is only 24 objects, as 23 of your objects are finished, the remaning cores are unfortunately not going to help out your remaining 1 objects, they will do absolutely nothing. Thus whether you have 4 cores or a million cores is not going to matter, if your entire build is stuck waiting around for this one remaining object.
One solution to the above problem is to break up your scenes into more objects, then as threads are completing their job they can pick up new objects to work on. However there are some cases where you just don’t want to break up your scene too much (for example for batching performance reasons). In that case one solution (or so I thought) was to cap lightmap resolutions.
If the entire scene is made up off 64 pixel lightmaps except for 1 object that has a huge 4096, then the entire lightmap render will have to wait around for that 1 map, since lightmap resolution is the main indication of how long an objects lightmap will take to render. With that said however, there was one problem.
Despite having capped all my lightmap resolutions to 1024, my lightmap built had to wait 20 minutes because of this one object: the floor of my scene. But why? The floor had a 1024 lightmap just as the other objects, what I didn’t take into consideration was unmapped texels!
Unmapped Texels: The Secret to Even Lightmap Build Times
As it turns out, as something like a floor is easy to UV map, the lightmap UV for the floor covered pretty much the entire 1024 lightmap (with it’s padding, only 3% was so called unmapped texels). The other objects however was significally more difficult to UV map due to the complexity of their shape (let’s say a sofa with cushions, for example), despite a carefully laid out UV, a whopping half of the pixels of that 1024 lightmap UV was actually empty space inbetween objects (to avoid mip map bleeding). Therefore all thought the resulting lightmap size was the same, there was significally more actual pixels rendered for the floor due to it’s lack of wasted gaps in the UV layout.
Therefore the floor took 3 times longer to build the lightmap for.
Since the “wasted” UV space of the complicated models are desired, the solution is simply to take the unmapped texels procentage into consideration when assigning lightmap budgets. So if you want the floors lightmap build to render as fast as that of the sofa, you could set the sofa to twice the resolution, or split the floor up into smaller peices.