Command line, Unity, Beast

I have been running into problems with using Beast for lightmap baking. The bake works well if only a few objects are selected, or even up to a third of the scene. However, when I try to bake all the static objects in the scene (large city, roughly 10,000 units x 500 units in the x and y directions), Unity simply throws a “Beast error: 11: Job Execution Failure”.

I’ve been searching the web and these forums on how I might be able to work around this problem and it comes down to a few options. Can someone please let me know if either one of them work, and how exactly can I execute it? Ultimately I would like to be able to utilize dual lightmapping with static and dynamic objects.

Option #1: Bake the scene in parts, either stitch the lightmaps back to one in photoshop or with ‘Lock Atlas’ turned on, re-index the scene’s geometry to the corresponding lightmaps (I have a feeling this is not possible at all since Beast indexes the scene’s geometry automatically behind the scenes without giving user access to change/edit it).

Option #2: Run Unity and Beast in Windows’ command line to execute the baking process while prevent the scene/assets/unity to be loaded at all in order to save memory. I have heard that this might be an option, much like Maya’s command line render queues that allows a user to use command line to fire up renders (although, in Maya’s case, Maya does actually start and the scene gets loaded). Since Beast is fairly new, I just do not know what, if any, the command(s) for this specific job.

Option #3: Run Unity and Beast on OS X instead so that Beast can utilize more than a single thread (since waiting for a 64-bit Unity and Beast is going to take much longer, even if that happens) and hopefully Beast will not run out of memory on bake?

And if none of the above are valid options, how can I bake lightmaps for a large scene?

Many Thanks!
Joe

After some trial and error, I was able to get Unity to start the baking process. However, near the end (after the baking process is done, during the import assets process) Unity seems to hang and is just stuck in the middle of the process.

I believe Beast assigns lightmap indicies after the asset import, which means if I were to cancel asset import and pull in the lightmaps by hand, I would have to manually connect hundreds of GameObjects to their respective [atlased] lightmaps. Any idea why this might be happening also?

Hmm, I haven’t encountered Beast failing jobs on large scenes since the most early days of 3.0 alpha - and those bugs were fixed back then.

Any chance you could submit your project in a bug report? Even if we find a workaround, it’s still better to make it just work.

Re: 1. You can divide the scene into multiple smaller scenes and bake those individually.

If it’s possible in your case, at runtime you could use LoadLevelAdditive to load all the scenes into the currently running one and the lightmaps will just work. The downside is that occlusion culling can’t work with additively loaded levels, so if you need it as well, it’s a no go.

Alternatively you can combine the scenes after baking yourself. Say you have two scenes (scene1 and scene2) and you want to merge scene2 into scene1.

  1. Copy all the objects from scene2 to scene1, including lights. You will see that those objects have incorrect lightmaps on them now, let’s fix it next.
  2. In scene1, in the Lightmapping window open the Maps pane. Increase the size of the array so that it can accomodate all the lightmaps from scene2 as well. Say scene1 used 8 lightmaps, scene2 used 4 - set the size to 12. Assign the lightmaps from scene2 to those four new empty slots (just drag from project view onto the slots).
  3. Next you need to update lightmap indices on the objects copied from the scene2. If you look at the Object pane in the Lightmapping window and unfold the ‘Atlas’ bit, you will see all objects copied from scene2 still have indices from 0 to 3, because those were the indices of the slots of the proper lightmaps in scene2. Now the lightmaps from scene2 moved 8 slots up, so you just need to add 8 to all lightmap index values of the objects copied from scene2.

As soon as you do that you should see all the correct lightmaps on all objects. There’s is no need to touch lightmap tiling in offset in the Atlas part of the Object pane, because those values stay the same, you just need to update the lightmap indices as described.

Of course if there is a lot of objects in your scene, there’s no point in doing this manually, but writing an editor script that will do it for you should be very easy.

Re: 2. That’s not possible at the moment and most likely wouldn’t be a solution, because Beast would still choke on your scene.

Re: 3. Multi-threading, 32 vs 64 bit and memory consumption are three separate things and in your case they’re most likely not relevant. Exporting from Unity to Beast runs on a single thread, but baking (which is what is failing in your case) in Beast is always multithreaded (both on win and mac). It might be so that the issue your experiencing won’t occur on mac, but that would be more of a coincidence.

Re: your last question: yes, Unity updates the atlasing info (lightmap index, tiling and offset) on baked objects after importing the lightmaps, so if you cancel before everything’s done, you just won’t get that information.

So yea, it would be very nice if we could get your project attached to a bug report, so that we can just fix the issue. :slight_smile:

Hi Robert, thanks for your great reply! I finally got the chance to return to the project and I had opted to try merging separate baked scenes. However, I do have a couple of questions.

  1. What if the total number of lightmaps baked exceeds the 255 lightmap array size? Auto-atlasing is already on. I did notice the advance tab under “FBXImporter”'s ‘generate lightmap UVs’. Might toying with those settings help compact/atlas more UVs onto one lightmap?

  2. Since we are working with ‘bake sets’ (separate baked scenes), what happens at the ‘bake set’ seams? Currently, after I have the scene baked the geometry outlining my ‘bake set’ does not bleed its shadow onto the target ‘bake set’ or vice-versa

(see attached images:

  • The first image shows the real-time shadows within the shadow distance, where the building’s shadow is casted onto the ground/curb tile.
  • The second image is taken from afar, outside of the shadow distance, with the ‘bake set’ seam highlighted in red. The buildings were selected for ‘bake selected’ whereas the road was not).

Thanks a lot!


You are trying to generate more than 250 1024x1024 lightmaps? You are definitely doing something wrong. But you could up the texture resolution to 2048, there was a script floating around that would let you do that.

But try setting the texel resolution to something really, really low. Like 0.1 or even 0.001 and see if it bakes succesfully. It will probably look bad, but it would be interesting to see if it works.

Yeah. It is quite a large scene (1/2 kilometer square), but we are going to use occlusion culling on it to boost performance. I am only trying to get some performance numbers right now, as well as figure out overall pipeline. I will definitely try those two methods you mentioned, though. Thanks!