Manual

From Bakery GPU Lightmapper: Wiki
Revision as of 09:35, 29 May 2019 by Mr F (talk | contribs) (Network baking)
Jump to navigation Jump to search

System requirements

To use Bakery you'll need:

  • Windows (7 or higher) PC.
  • Nvidia GPU. Minimum supported model is Kepler (GeForce 6xx or newer. For Quadro cards check the specs).
  • 64-bit Unity editor. Bakery was tested on all versions from 5.6 to 2019.1.

Prerequisites

  • Make sure your project does not have any script compilation errors, as it will prevent Bakery scripts from compiling as well.
  • Make sure you have the latest GPU driver. Update it if needed.

Installation

1. Import Bakery to your project via Asset Store.

2. Unity will show a list of files to import. If it's your first time using Bakery, it is recommended you just click Import. Experienced users may want to untick the examples folder for a more lightweight installation.

Files will be imported to Assets/Bakery and Assets/Editor/x64/Bakery. These folders can be moved later.

3. Unity will then import Bakery and compile the scripts. It may show a window like this:

Goahead.png

In which case you should click "Go Ahead".

You should now see Bakery menu added to the editor:

Bmenu.jpg


Quickstart

1. Add some model or primitive and mark it as Static.

Staticmarked.jpg


2. Select Directional Light (the one Unity created for you) and add Bakery Direct Light component to it.

Bulbgraph.png Bakery and Unity use separate light source components.


3. Bakery Direct Light has many options to tweak, but you can easily match it to Unity light. Click Match lightmapped to real-time. Now Bakery light should have the same yellowish color as Unity’s default Directional.

Matching.jpg

Bulbgraph.png Direct Light component may complain about project not using linear light intensity. The problem is that by default Unity applies gamma correction to light source colors incorrectly. Correct mode can be enabled by scripting, and that’s what the “Fix” button does. If you already have many light sources set up in non-linear intensity mode, and you don’t want to change them again, you may skip fixing. Even if you press “Fix”, you can always revert the change anytime.


4. To get shadowed ambient lighting, create Skylight (Bakery->Create->Skylight).

Menusky.jpg


5. Select Skylight, give it some bluish color and click Match scene skybox to this light. This will make scene skybox match lighting exactly.

Bulbgraph.png Matching Unity skybox to Bakery skylight is optional but useful for correctness, as to ensure that visible environment and in-engine reflection probes match baked lighting.


Skycomp.jpg


6. Click Bakery->Render Lightmap. By default, Full Lighting mode is active. It will bake both direct and indirect contribution from all lights. If you want to combine real-time shadows with baked GI, change it to Indirect.

Bakerywindow.jpg

Bulbgraph.png Bakery may complain that you are using old gamma mode and suggest to change it. If you care about quality of lighting, using Linear mode is highly recommended. You may ignore it if you already have a big project set up with incorrect gamma and don’t want to change it or when shipping to mobile devices that don't support it.

7. Click Render.

8. Done! You should now have baked GI:

Bakedgi.jpg

Render settings

All render settings can be accessed via Bakery->Render Lightmap. Settings are saved for every scene. The topmost option in Bakery window allows you to switch between Simple, Advanced and Experimental settings, each succeeding mode revealing more tweakable options. Simple mode is enough for most scenes and it's a good way to get started.


Render mode

Defines the type of lightmaps to bake.

Full Lighting

Complete direct and indirect lighting for all Bakery lights.

Bulbgraph.png On pre-2017.3 Unity versions if you have both Unity and Bakery components on the same object, you will need to disable Unity ones manually to avoid double brightness. On newer versions real-time effects are automatically disabled for baked lights, as with built-in lightmappers.
Indirect
Comparison of different render modes supported by Unity

Basic mixed mode. It will look at the Baked Contribution selector on every light: if it’s set to Direct And Indirect, the light is baked as in Full Lighting mode. If it’s set to Indirect Only, only indirect contribution (GI) from this light is baked. In latter case you should keep both Unity and Bakery lights on the object, one giving real-time direct contribution, and another for precomputed GI.

Indirectonly.jpg

Shadowmask
Left: completely baked light. Center: dynamic light with baked GI. Right: capsule shadow, bump and specular are dynamic, but cube shadow and GI are baked.
When camera gets far away enough or if dynamic shadows are disabled, the same scene will look like this

A more advanced mixed mode. It works by generating two types of lightmaps - one with baked color (as in Indirect mode), and another with shadows from static objects. It has several benefits:

  • Real-time shadows can render only a handful of dynamic objects, instead of the whole scene.
  • Real-time and baked shadows blend together properly.
  • Real-time lights can render bump, specular and other surface effects, while still being occluded by high-quality baked shadows.

More details

Currently only Direct, Point and Spot lights can interact with shadowmasking (because they are the only types Unity supports in real-time). To enable this behaviour, you must have both Unity and Bakery lights on the same object, with Baked Contribution set to Indirect and Shadowmask. Unmarked lights will be baked as in Indirect mode.

Smask22.jpg

Distance Shadowmask

This checkbox is only visible if you chose shadowmask and simply toggles equally named setting in project’s Quality Settings. More details.

Bulbgraph.png Checkbox is not visible on Unity 5.6.x due to the lack of corresponding scripting API. Instead you can toggle it in Window->Lighting->Mixed Lighting->Lighting Mode.
Bulbgraph.png On Unity versions < 2017.3 rendering Shadowmask lightmaps will clear the light probes due to API limitations. They will need to be re-rendered again after bake. It shouldn’t happen on newer versions.



Directional mode

Comparison of different directional modes

Defines how directional information is baked. Standard lightmaps only store a single color per texel, while directional lightmaps give shaders a hint of how lighting changes over a hemisphere around the texel. This data is required to combine fully lightmapped areas with normal maps. Plugging it into the built-in Bakery shader can also produce approximate specular response.

None

No directional data, single color per texel.

Baked Normal Maps

Still no directional data, but normal maps are taken into account when rendering the lightmap. There is no additional runtime overhead. Since lightmaps usually have lower resolution than normal maps, the result may look blurry. Other problems include aliasing at distance due to lack of mipmapping and denoising step potentially smudging the detail. To learn how to use custom shaders with procedural normals in this mode, read Shader Compatibility section.

Dominant Direction

This mode is similar to what Enlighten and Progressive bake in Unity. It is compatible will most shaders, only generates one additional map and the runtime overhead is minimal. The downside is that bump-mapping looks rather faint and gray-ish and can be quite different comparing to the same object under real-time lighting.

RNM

Based on Radiosity Normal Mapping technique originally invented for HL2 (slides) and later used in many games (e.g. Mirror’s Edge). It generates 3 HDR maps in total, being the most memory-demanding mode of all. Runtime overhead is still relatively low. This mode is more precise than Dominant Direction. It is better at reproducing surface contrast and handling colored lights affecting normal maps from different angles.

SH

Based on “Precomputed Global Illumination in Frostbite” paper. This is the highest quality mode, giving much better surface contrast and representing differently colored lighting coming from different directions. Generates 4 maps in total, only one of them being HDR, therefore takes less memory than RNM. Runtime overhead is slightly higher than that of RNM.

Limitations
  • RNM and SH can be only used with Bakery shader or require adjustments to your shaders.
  • In RNM and SH modes, standard color lightmaps are not created. You need to either have Bakery shader on all materials in the scene, or use Lightmap Groups to separate RNM/SH objects from the rest.
  • RNM and SH maps are applied to objects using MaterialPropertyBlock and so may be not shown completely in Unity’s Lighting window.
  • Dominant Direction, RNM and SH modes may require slightly more samples for GI and Light Meshes to get comparable quality.



Texels per unit

1 vs 10 texels per unit

Approximate amount of lightmap texels per world unit. Affects the amount and resolution of generated lightmaps.

Example values to get you started:

  • Large outdoor area (a city): 1 - 5
  • Medium outdoor area (a few alleys): 10-20
  • High quality interior: 100

Keep in mind that Texels Per Unit is base resolution, but every object can be additionally tweaked using Scale in Lightmap option on Mesh Renderers as well as “Scale per map type” in Bakery window.


Max resolution

Maximum lightmap size limit. If objects can't fit in a single lightmap (given current Texels Per Unit value), additional lightmaps will be allocated. Same 4 square objects can take four 512x512 maps or one 1024x1024.


Bounces

Note how more bounces bring more light to closed spaces.

Defines how many times light rays should bounce off surfaces. Usually lower values are sufficient for outdoor scenes (e.g. a city), while higher values are required for more closed scenes (interiors, caves).


Samples

Left: samples = 4, right: sample = 16. Denoising is off for illustrative purposes.

Affects quality of GI. Typical values are from 16 to 32.


GPU Priority

While GPU is working on lightmaps, OS and other software may become less responsive. This option allows you to balance between baking speed and system responsiveness.


Render

Bakes lightmaps for all opened scenes.


Render Light Probes

Bakes light probes for all opened scenes.


Render Reflection Probes

Bakes reflection probes for all opened scenes. This button is just for convenience and will call built-in engine reflection probe update.


Update Skybox Probe

Bakes global diffuse and reflection probe for the current skybox. As with "Render Reflection Probes", it just calls built-in engine functions.


Occlusion probes

When "Render Light Probes" is pressed, lets Unity bake occlusion probes using currently selected built-in lightmapper. Occlusion probes is additional data stored inside regular light probes, and it prevents dynamic objects from getting lit in shadowed areas. Currently there is no way to use custom occlusion probes in Unity, and it has to call its own lightmappers instead to do the job.


Warnings

These options will validate the scene after one of the Render buttons is pressed and show warning dialog boxes asking to continue or stop the baking process.

  • UV validation: will check if all models have fully correct lightmapping UVs - specifically if they lie within 0-1 range and don’t overlap.
  • Overwrite check: will tell which lightmap files are going to be overwritten.
  • Memory check: will tell a very approximate amount of video memory required.
  • Sample count check: will check if any lights, GI or AO have unreasonable sample counts that can make GPU go out of available resources.
  • Lightmapped prefab validation: validates Lightmapped Prefabs and notifies if some prefabs are going to be overwritten.

Advanced render settings

Adjust UV padding

If enabled, will look for models with auto-generated UVs (“Generate Lightmap UVs” on the asset) and adjust them further to have proper padding between UV islands per-mesh. Model-wide Pack Margin in importer settings is ignored. Optimal values are calculated instead, given area of each mesh and lightmap resolution.


Unload scenes before render

Unloads Unity scenes before baking to free up video memory. Complex scenes can take a few gigabytes of VRAM by simply being shown in editor.


Denoise

Left: denoising off, right: denoising on.

If enabled, will apply denoising algorithm. Bakery uses Nvidia’s AI denoiser.


Fix Seams

Left: seams, right: seams are fixed.

If enabled, will attempt to blend seams created by UV discontinuities. Useful for smooth geometry, including Unity’s default sphere.


Split by scene

If multiple scenes are loaded at once, and this option is enabled, each scene will have its own set of lightmaps, not shared with others. It can be useful for limiting the amount of textures loaded when scenes are streamed at runtime.


Min resolution

Minimum lightmap size limit. Can be used to balance between many small but fully occupied lightmaps vs few incompletely filled.


Scale per map type

Allows you to scale the resolution of color/shadowmask/direction maps differently. For example, a common case would be to have low resolution indirect color but highly detailed shadowmask. Note that scaling is applied after the lightmaps are rendered, so it won’t save baking time. If “Adjust UV padding” is on, padding will be based on the lowest resolution map to prevent texel leaking.


Checker preview

Checker preview in action

If Show checker checkbox is on, Scene View will render a checkerboard pattern on top of visible objects to demonstrate lightmap texel size. This is useful to make sure you are using adequate values for Texels Per Unit and other resolution-affecting settings before you bake.

Enabling checker preview will force Bakery to perform atlas packing. It can take some time, but shouldn’t be longer than a few seconds. Press Refresh checker to re-atlas the scene after you changed something to see changes.

Checker preview also uses random colors to show how the scene will be split into different lightmaps.

Bulbgraph.png Checker preview currently does not show correct texel sizes for Terrains.

Emissive boost

Multiplies any surface emission by this number.


Indirect boost

Multiplies all bounced lighting by this number. Same as Indirect Intensity on light components, but global.


Backface GI

Backface GI
Left: backface GI = 0, right: backface GI = 1. Note how shadowed areas receive more green lighting.

Determines how much light is passed through front faces to back faces and then bounced off by GI. This is especially useful for thin translucent surfaces like leaves. Values are in 0-1 range.


Ambient occlusion

Left: AO intensity = 0. Right: AO intensity = 1.

Simple non-physical ambient occlusion you can apply over final scene lighting for aesthetic purposes.

  • Intensity: controls visibility of the AO effect. Value of 0 disables the effect.
  • Radius: determines the ray distance used in the AO effect. Smaller values give localized occlusion (corners, wrinkles), while larger values make it more similar to Skylight, giving shadows from distant objects.
  • Samples: affects the quality of ambient occlusion. Typical values are from 4 to 32.

RTX Mode

Enables RTX hardware acceleration. Only RTX GPUs will benefit from this option. Minimum supported driver version is 418.


Export terrain trees

If enabled, painted terrain trees will affect lighting. Trees themselves will not be baked. Note that highest possible LOD level is used for every tree during baking. It is not recommended to use this option for rendering multi-kilometer forests with highly detailed models.


Terrain optimization

If enabled (default), Terrains use separate ray tracing technique to take advantage of their heightfield geometry. Otherwise they are treated like any other mesh. Terrain optimization significantly reduces memory footprint required for high-resolution landscapes. In some cases it can also make terrain baking faster, in other cases (especially with simple low-resolution landscapes) it might make sense to disable it.


GI VRAM optimization

Toggles memory optimization used for very large scenes, especially when baking too many lightmaps at once. If enabled, may slow down rendering a little bit. If disabled, and the scene is too big, Bakery may go out of memory.

  • Auto: guess if optimization is needed based on open scenes. The guess is only approximate, so if you know the scene is huge, set it to Force On.
  • Force On: always enabled.
  • Force Off: always disabled.

Tile size

Same as GPU Priority, but instead of abstract priority you set tile size. Bakery splits lightmaps into smaller tiles and updates one at a time. Smaller size means more GPU work interruptions, and can make system more responsive.


Temp path

Temporary files folder. Bakery may require a few gigabytes of free space during rendering. Having this folder on SSD can make rendering slightly faster comparing to HDD. At the moment, this folder is not cleaned automatically. You can delete its contents anytime (except during rendering).


Output path

Lightmap folder. This is where all lightmap, and also lightprobe and vertex color assets will be saved. This path is relative to your Assets folder.


Use scene named output path

If this option is enabled, output path will be automatically set to a folder with the same name as the currently active scene (Assets/CurrentSceneName/). This is similar to how built-in Unity lightmappers behave.


Render Selected Groups

Only bakes Lightmap Groups containing selected objects. Not only selected objects will be redrawn, but all Lightmap Groups they belong to. Other lightmaps will not be updated. If objects are not a part of some manually assigned group, then a part of the scene using the same lightmap will be rebaked.


Beep on finish

If enabled, Bakery will play a sound when the bake is finished.

Experimental render settings

Unwrapper

If Adjust UV Padding is enabled, defines the unwrapper that will be used.


Export geometry and maps

If enabled, Bakery will export the scene to its format before rendering. If you are sure that geometry and textures of the scene and lightmap resolution settings were not changed (e.g. you are only tweaking GI or light settings), you can disable this checkbox to make next rendering faster.


Update unmodified lights

If enabled, Bakery will recalculate light sources that didn’t change since last rendering. If you are only tweaking one light and don’t want to wait for other lights to re-render, you can disable this checkbox.


Update modified lights and GI

If enabled, Bakery will recalculate GI and lights that were changed since last rendering.


UV padding: increase only

Only visible if Adjust UV padding is on. By default, optimal UV padding for a model asset is calculated only based on currently loaded scenes. If there are multiple instances of the same model using different lightmap resolution, the smallest one will define padding, so spacing between UV charts is large enough to prevent them from leaking over each other. However, baking the same model in 2 different isolated scenes will possibly break UVs in previous scenes while optimizing for the new one. This checkbox allows to prevent such behaviour by never decreasing the padding value, so it will be always optimized for the lowest resolution instance ever baked.


Denoise: fix bright edges

Left: a bright edge is visible after denoising; Right: fixed.

Only visible if Denoise is on. Sometimes the neural net used for denoising may produce bright edges around shadows, like if a sharpening effect was applied. If this option is enabled, Bakery will try to filter them away. Denoising stage may get slightly slower, when enabled.


Combine with Enlighten real-time GI

If enabled, then when the Render button is pressed, it will first try to bake with Enlighten to calculate real-time GI. After that, regular Bakery lightmapping process will happen. Both baked and real-time GI will work together.


Bake on remote server

Enables network baking.

Network baking

This feature is currently in beta.

  • Doesn't perform distributed rendering yet, but you can offload baking to another PC;
  • The idea is to use it over LAN, not over Internet (large data transfers);
  • Server PC doesn't need Unity installed;
  • Client PC doesn't require Nvidia GPU.

To use network baking:

1. Install Bakery on both client and server PC. If you don't have Unity on the server, just copy Assets/x64/Editor/Bakery folder.

2. Run ftServer.exe on server PC. Simply double-clicking it will work, but its temp folder will default to Users/Your username/AppData/Local/Temp/ftServer. If you want it to be in another folder, you'll need to specify it as an argument to ftServer either via command line, a bat file or with a simple shortcut: ftServer pathToTemp.

3. On client PC, set settings to Experimental, scroll the window down and check "Bake on remote server". Type the server IP in (make sure you can ping this IP).

4. Click "Connect to server". Now Bakery window will monitor current server status. If it says "Idle", you're ready to go.

5. Click the regular Render button. Status should now display baking progress.

6. After the bake is done, it will say "Idle" again. Click "Get data" to import and apply the lightmaps.

Bulbgraph.png Even though ftServer is designed with extensive validation and crash resistance in mind, it is not recommended to expose it to Internet for security purposes. Make sure Windows only allows your trusted LAN to interact with ftServer.