Lightmapping In-Depth
Manual     Reference     Scripting   
Unity Manual > Lightmapping Quickstart > Lightmapping In-Depth

Lightmapping In-Depth

If you are about to lightmap your first scene in Unity, this Quickstart Guide might help you out.

Lightmapping is fully integrated in Unity, so that you can build entire levels from within the Editor, lightmap them and have your materials automatically pick up the lightmaps without you having to worry about it. Lightmapping in Unity means that all your lights' properties will be mapped directly to the Beast lightmapper and baked into textures for great performance. Unity Pro extends this functionality by Global Illumination, allowing for baking realistic and beautiful lighting, that would otherwise be impossible in realtime. Additionally Unity Pro brings you sky lights and emissive materials for even more interesting scene lighting.

In this page you will find a more in-depth description of all the attributes that you can find in the Lightmapping window. To open the Lightmapping window select WindowLightmapping.

Object

Per-object bake settings for lights, mesh renderers and terrains - depending on the current selection.

Mesh Renderers and Terrains:

StaticMesh Renderers and Terrains have to marked as static to be lightmapped.
Scale In Lightmap(Mesh Renderers only) Bigger value will result in more resolution to be dedicated to the give mesh renderer. The final resolution will be proportional (Scale in lightmap)*(Object's word-space surface area)*(Global bake settings Resolution value). A value of 0 will result in the object not being lightmapped (it will still affect other lightmapped objects).
Lightmap Size(Terrains only) Lightmap size for this terrain instance. Terrains are not atlased as other objects - they get their individual lightmaps instead.
AtlasAtlasing information – will be updated automatically, if Lock Atlas is disabled. If Lock Atlas is enabled, those parameters won't be modified automatically and can be edited manually.
Lightmap IndexAn index into the lightmap array.
Tiling(Mesh Renderers only) Tiling of object's lightmap UVs.
Offset(Mesh Renderers only) Offset of object's lightmap UVs.

Lights:

LightmappingThe Lightmapping mode: Realtime Only, Auto or Baked Only. See Dual Lightmaps description below.
ColorThe color of the light. Same property is used for realtime rendering.
IntensityThe intensity of the light. Same property is used for realtime rendering.
Bounce IntensityA multiplier to the intensity of indirect light emitted from this particular light source.
Baked ShadowsControls whether shadows are casted from objects lit by this light (controls realtime shadows at the same time in case of Auto lights).
Shadow Radius(Point and Spot lights only) Increase this value for soft direct shadows - it increases the size of the light for the shadowing (but not lighting) calculations.
Shadow Angle(Directional lights only) Increase this value for soft direct shadows - it increases the angular coverage of the light for the shadowing (but not lighting) calculations.
Shadow SamplesIf you've set Shadow Radius or Angle above zero, increase the number of Shadow Samples as well. Higher sample numbers remove noise from the shadow penumbra, but might increase rendering times.

Bake

Global bake settings.

ModeControls both offline lightmap baking and runtime lightmap rendering modes. In Dual Lightmaps mode both near and far lightmaps will be baked; only deferred rendering path supports rendering dual lightmaps. Single Lightmaps mode results in only the far lightmap being baked; can also be used to force single lightmaps mode for the deferred rendering path.
Use in forward rendering(Dual lightmaps only) Enables dual lightmaps in forward rendering. Note that this will require you to create your own shaders for the purpose.
QualityPresets for high (good-looking) and low (but fast) quality bakes. They affect the number of final gather rays, contrast threshold and some other final gather and anti-aliasing settings.
BouncesThe number of light bounces in the Global Illumination simulation. At least one bounce is needed to give a soft, realistic indirect lighting. 0 means only direct light will be computed.
Sky Light ColorSky light simulates light emitted from the sky from all the directions - great for outdoor scenes.
Sky Light IntensityThe intensity of the sky light - a value of 0 disables the sky light.
Bounce BoostBoosts indirect light, can be used to increase the amount of bounced light within the scene without burning out the render too quickly.
Bounce IntensityA multiplier to the intensity of the indirect light.
Final Gather RaysThe number of rays shot from every final gather point - higher values give better quality.
Contrast ThresholdColor contrast threshold, above which new final gather points will be created by the adaptive sampling algorithm. Higher values make Beast be more tolerant about illumination changes on the surface, thus producing smoother but less-detailed lightmaps. Lower numbers of final gather rays might need higher contrast threshold values not to force additional final gather points to be created.
InterpolationControls the way the color from final gather points will be interpolated. 0 for linear interpolation, 1 for advanced, gradient-based interpolation. In some cases the latter might introduce artifacts.
Interpolation PointsThe number of final gather points to interpolate between. Higher values give more smooth results, but can also smooth out details in the lighting.
Ambient OcclusionThe amount of ambient occlusion to be baked into the lightmaps. Ambient occlusion is the visibility function integrated over the local hemisphere of size Max Distance, so doesn't take into account any lighting information.
Max DistanceBeyond this distance a ray is considered to be unoccluded. 0 stands for infinitely long rays.
ContrastControls the transition between fully occluded to not occluded.
Lock AtlasWhen Lock Atlas is enabled, automatic atlasing won't be run and lightmap index, tiling and offset on the objects won't be modified.
ResolutionThe resolution of the lightmaps in texels per world unit, so a value of 50 and a 10unit by 10unit plane will result in the plane occupying 500x500 pixels in the lightmap.

Maps

The editable array of all the lightmaps.

CompressedToggles compression on all lightmap assets for this scene.
Array SizeSize of the lightmaps array (0 to 254).
Lightmaps ArrayThe editable array of all the lightmaps in the current scene. Unassigned slots are treated as black lightmaps. Indices correspond to the Lightmap Index value on Mesh Renderers and Terrains. Unless Lock Atlas is enabled, this array will get auto-resized and populated whenever you bake lightmaps.

Lightmap Display

Utilities for controlling how lightmaps are displayed in the editor. Lightmap Display is a sub window of the Scene View, visible whenever the Lightmapping window is visible.

Use LightmapsWhether to use the lightmaps during the rendering or not.
Shadow DistanceThe distance at which Auto lights and Close By lightmaps fade out to just Far Away lightmaps. This setting overrides but not overwrites the QualitySettings.shadowDistance setting.
Show ResolutionToggles the scene view Lightmap Resolution mode, which allows you to preview how you spend your lightmap texels on objects marked as static.

Details

Dual Lightmaps

Dual lightmaps is Unity's approach to make lightmapping work with specular, normal mapping and proper blending of baked and realtime shadows. It's also a way to make your lightmaps look good even if the lightmap resolution is low.

Dual lightmaps by default can only be used in the Deferred Lighting rendering path. In Forward rendering path, it's possible to enable Dual Lightmaps by writing custom shaders (use dualforward surface shader directive).

Dual lightmaps use two sets of lightmaps:

Realtime Only lights are never baked. The Near lightmap set is used within the distance from the camera smaller than the Shadow Distance quality setting.
Within this distance Auto lights are rendered as realtime lights with specular bump and realtime shadows (this makes their shadows blend correctly with shadows from Realtime Only lights) and their indirect light is taken from the lightmap. Outside Shadow Distance Auto lights no longer render in realtime and full illumination is taken from the Far lightmap (Realtime Only lights are still there, but with disabled shadows).

The scene below contains one directional light with lightmapping mode set to the default Auto, a number of static lightmapped objects (buildings, obstacles, immovable details) and some dynamic moving or movable objects (dummies with guns, barrels). The scene is baked and rendered in dual lightmaps mode: behind the shadow distance buildings are fully lit only by lightmaps, while the two dummies are dynamically lit but don't cast shadows anymore; in front of the shadow distance both the dummy and static lightmapped buildings and ground are lit in realtime and cast realtime shadows, but the soft indirect light comes from the near lightmap.

Single Lightmaps

Single Lightmaps is a much simpler technique, but it can be used in any rendering path. All static illumination (i.e. from baked only and auto lights, sky lights and emissive materials) gets baked into one set of lightmaps. These lightmaps are used on all lightmapped objects regardless of shadow distance.

To match the strength of dynamic shadows to baked shadows, you need to manually adjust the Shadow Strength property of your light:


Adjusting Shadow Strength of a light from the original value of 1.0 to 0.7.

Lightmapped Materials

Unity doesn't require you to select special materials to use lightmaps. Any shader from the built-in shaders (and any Surface Shader you write, for that matter) already supports lightmaps out of box, without you having to worry about it - it just works.

Lightmap Resolution

With the Resolution bake setting you control how many texels per unit are needed for your scene to look good. If there's a 1x1 unit plane in your scene and the resolution is set to 10 texels per unit, your plane will take up 10x10 texels in the lightmap. Resolution bake setting is a global setting. If you want to modify it for a special object (make it very small or very big in the lightmap) you can use Scale in Lightmap property of Mesh Renderers. Setting Scale in Lightmap to 0 will result in the object not being lightmapped at all (it will still influence lightmaps on other objects). Use the Lightmap Resolution scene view render mode to preview how you spend your lightmap texels.


Lightmap Resolution scene view mode visualising how the lightmap texels are spent (each square is one texel).

UVs

A mesh that you're about to lightmap needs to have UVs suitable for lightmapping. The easiest way to ensure that is to enable the Generate Lightmap UVs option in Mesh Import Settings for a given mesh.

For more information see the Lightmap UVs page.

Material Properties

The following material properties are mapped to Beast's internal scene representation:

Note: When mapping materials to Beast, Unity detects the 'kind' of the shader by the shader's properties and path/name keywords such as: 'Specular', 'Transparent', 'Self-Illumin', etc.

Advanced

Automatic Atlasing

Atlasing (UV-packing) is performed automatically every time you perform a bake and normally you don't have to worry about it - it just works.

Object's world-space surface area is multiplied by the per-object Scale In Lightmap value and by the global Resolution and the result determines the size of the object's UV set (more precisely: the size of the [0,1]x[0,1] UV square) in the lightmap. Next, all objects are packed into as few lightmaps as possible, while making sure each of them occupies the amount of space calculated in the previous step. If a UV set for a given object occupies only part of the [0,1]x[0,1] square, in many cases atlasing will move neighboring UV sets closer, to make use of the empty space.

As a result of atlasing, every object to be lightmapped has it's place in one of the lightmaps and that space doesn't overlap with any other object's space. The atlasing information is stored as three values: Lightmap Index, Tiling (scale) and Offset in Mesh Renderers and as one value: Lightmap Index in Terrains and can be viewed and modified via the Object pane of the lightmapping window.


Right-clicking a lightmap allows to select all game objects, that are using the chosen lightmap. Lightmaps of the active object from the current selection will be highlighted in yellow.

Atlasing can only modify per-object data which is Lightmap Index, Tiling and Offset and can not modify the UV set of an object, as the UV set is stored as part of the shared mesh. Lightmap UVs for a mesh can only be created at import time using Unity's built-in auto-unwrapper or in an external 3D package before importing to Unity.

Lock Atlas

When Lock Atlas is enabled, automatic atlasing won't be run and Lightmap Index, Tiling and Offset on the objects won't be modified. Beast will rely on whatever is the current atlasing, so it's the user's responsibility to maintain correct atlasing (e.g. no overlapping objects in the lightmaps, no objects referencing a lightmap slot past the lightmap array end, etc.).

Lock Atlas opens up the possibility for alternative workflows when sending your object's for lightmapping. You can then perform atlasing manually or via scripting to fit you specific needs; you can also lock the automatically generated atlasing if you are happy with the current atlasing, have baked more sets of lightmaps for your scene and want to make sure, that after adding one more object to the scene the atlasing won't change making the scene incompatible with other lightmap sets.

Remember that Lock Atlas locks only atlasing, not the mesh UVs. If you change your source mesh and the mesh importer is set to generate lightmap UVs, the UVs might be generated differently and your current lightmap will look incorrectly on the object - to fix this you will need to re-bake the lightmap.

Custom Beast bake settings

If you need even more control over the bake process, see the custom Beast settings page.

Page last updated: 2011-10-25