Partial scene baking

From Bakery GPU Lightmapper: Wiki
Revision as of 08:09, 3 May 2021 by Mr F (talk | contribs) (Real world example)
Jump to navigation Jump to search

In the level design process, especially when working on very large maps, it is often desirable to only rebake a small chunk of the world and iterate on it. Originally Bakery's Lightmap Groups were meant to achieve it (apart from their other benefits). In practice, however, it didn't work well, as they are limited to a single lightmap atlas, and "Render Selected" functionality had too many constraints due to lightmapper's core architecture. "Render Selected" also didn't reduce the memory footprint of world geometry; all vertices and triangles of all loaded scenes had to be ready in VRAM.

Large scenes could be also split into multiple smaller scenes, but this approach required more setup and, most importantly, such scenes couldn't light/shadow each other.

The sector system

BakerySector component UI

The new sector system (upcoming in v1.9) attempts to solve this problem. BakerySector is a collection of objects that can be baked separately. Similar to Lightmap Groups, adding BakerySector component on a root object of a hierarchy, marks all objects in this hierarchy as belonging to this sector.

Main Bakery window (when viewed in Advanced/Experimental mode) now has a sector field:

Bsector field.jpg

If not set, all bakes will proceed normally; but if set to a specific sector, only this sector will be baked, or rendered in RTPreview.

Here is an example. Two white boxes belong to a sector. First, this is how it looks in RTPreview (and for the lightmapper) by default:

Bsector default.jpg

All scene objects are present and will be fully baked.

Now, with the sector selected:

Bsector only.jpg

Only white boxes are visible by the lightmapper now. They can be baked separately without breaking existing scene lightmaps. However, they lack shadows and bounces from the surrounding geometry.

To fix this problem, BakerySector has Capture Points. Each capture point is like a virtual omnidirectional camera (or a cubemap, if it's easier to grasp). These points capture the scene around them (depth and albedo information) and generate a simplified projected mesh. Multiple capture points can be combined to cover different viewpoints, acting similarly to a virtual version of 3D scanning. When the real scene is very large and complex, these projected meshes can work as its cheap approximation, providing desired shadows/bounces, while only requiring a fraction of memory/time to process. Projected geometry is temporary and only used in the bake/preview; it won't persist in the scene.

Here is the same scene in RTPreview, with 1 capture point added:

Bsector 1.jpg

Now shadows and bounces on the white boxes look just as if we had whole world geometry loaded; but instead of the real geometry, only this projected mesh is used.

Adding another capture point recovers more of the outside geometry:

Bsector 2.jpg


Real world example

In the toy example above there is no real benefit of using sectors. But here is a real example:

There is a large city map. A new chunk, containing roads, buildings and various props was added. Baking the whole map at once is not possible in this case; it just won't fit in memory. It can be done with an upgraded GPU, but then it would still take too long.

We really just want to bake this new chunk and make it look integrated into the world:

Bsector real1.jpg


A sector is added to the root object of the chunk. We can now bake the chunk separately, and it will bake pretty fast:

Bsector real2.jpg


And now with a bunch of capture points:

Bsector real3.jpg

The new chunk can be now baked quickly, while receiving shadows and GI from the surrounding world and without breaking older bakes.


Loading, saving and reusing captures

BakerySector has multiple modes of operation. The default Capture in place mode generates projected geometry each time the Render or "Open preview" buttons are pressed. This geometry is based on what is currently visible in the opened scenes.

Alternatively, projected geometry can be saved into an asset and then loaded anywhere, even in a different scene. This is especially useful when iterating on interiors.