Partial scene baking

From Bakery GPU Lightmapper: Wiki
Revision as of 15:42, 16 November 2022 by Mr F (talk | contribs) (The sector system)
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 sector system (added 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 to 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.

Suppose there is a large city scene and a detailed interior inside it. The interior is in a separate scene, so it's easier to work on it, but we still want city shadows/bounces to affect the interior through windows.

A sector can be added to the root of the room, and capture points can be placed just outside the windows:

Bsector room1.jpg


You can then copy the sector object (without any geometry itself) to the city scene, set mode to Capture To Asset and click Capture:


Bsector room2.jpg


Loading back the room scene, set mode to Load Captured and select the generated asset:


Bsector room3.jpg


Bakery will now "see" the projected approximation of the city, as seen from capture points, even though the city is not even loaded in the scene:


Bsector room4.jpg


Loaded sectors can be cloned, moved and rotated. Each copy of the room will still see the same captured city through its windows:

Bsector room5.jpg


Light probes and volumes

  • Light probes are not baked if any sector is chosen. They only update in regular full bakes or with "Render Light Probes".
  • Volumes from the hierarchy of the chosen sector are baked; other volumes are left unchanged.

Material compatibility

Internally, capture points render the scene in 6 directions using special shaders that output albedo, normal and depth. As these shaders don't have original shaders' logic, procedural albedos may be lost. Currently every rendered object will draw _MainTex/_BaseMap/_BaseColorMap of the material (whichever is present). As capture points draw objects directly as seen (with perspective projection), they can't, unlike the lightmapper or the RTPreview, use Meta Pass.