Quick notes on how to deal with Unity 5 lighting.
The source project for the screenshots in this article is hosted at GitHub.
Standard realtime lighting
Standard realtime lighting includes ambient light, environment reflection and realtime lights and shadows. It doesn’t require any GI or precomputed stuff whatsoever. Both options Precomputed Realtime GI and Baked GI are disabled in Lighting > Scene.
1) Ambient Light
Equally affects all objects.
Ambient Source (Skybox, Gradient, Color) and Intensity
2) Environment Reflection
Reflected path that changes with the angle of the camera. Applied independently of Ambient. Affects the Fresnel effect as well.
If Reflection Probes are used they become the Reflection Source and Intensity for the objects under their influence, so the global reflection settings don’t have effect on these objects. Reflection Bounces define how much times the reflection can bounce among several probes (i.e. a probe capturing the objects under the influence of another probe).
Left: Reflection Source (Skybox, Cubemap), Resolution and Reflection Intensity.
Right: A Reflection Probe affects this object, so the global Environment Reflection Source doesn’t affect this mesh.
3) Standard Lights
All standard realtime lights in the scene apply direct lighting and shadows on the objects.
The first Directional Light in the scene is considered as Sun by default. The default Skybox gets its intensity and color adjusted depending on the Sun’s horizontal inclination. Alternatively, a specific directional light can be selected as Sun for affecting the default Skybox:
Precomputed realtime lighting
Precomputed realtime lighting throws in light bounces, color bleeding, and emissive materials in real time. Everything can change dynamically (light color and intensity, material color, material emission, etc) an the lighting gets updated in the scene accordingly in real time.
Lighting > Scene > Precomputed Realtime GI enabled, Baked GI disabled.
4) Light Bounces
Each light is configured to bounce off of objects and affect others.
5) Emissive Materials
Objects flagged as Static containing an emissive material emit light according to their geometry.
Precomputed realtime lighting is calculated on the scene objects flagged as Static. A precompute phase is triggered whenever the Transform of any object marked as Static is modified, or when the Static flag itself changes.
The parameter Lighting > Scene > Precomputed Realtime GI > Realtime Resolution directly affects the time it will take to precompute the data. It’s ok to use values as low as 0.01 – 0.5 for allow quickly prototyping while working in the Editor.
CPU Usage affects the reactions of the dynamic light changes in runtime. It doesn’t affect the CPU used for baking the precomputed data in the editor.
Light bouncing and material emission affect static objects only. Light probes must be used for the precomputed effects to be applied on dynamic objects as well.
Ambient Light in precomputed realtime lighting
Ambient Light affects the parts of the static geometry that can be reached “from the exterior” by the light. Backfaces also count here. For instance, at interior scenes where the static geometry defines a closed hull, the ambient light won’t have effect at all in the static meshes. Any “gaps” or parts that are reachable from the exterior of the static geometry will be affected by the Ambient Light accordingly.
Ambient Light, Standard Lights (baked or mixed), Light Bounces and Emissive Materias are baked into lightmap textures. Only Environment Reflection can change in runtime.
Lighting > Scene > Baked GI enabled, Precomputed Realtime GI disabled.
Standard Lights should be configured as Baked or Mixed for allowing to seamlessly switching among Bake only and Realtime only GI modes.
The parameter Lighting > Scene > Baked GI > Baked Resolution directly affects the time it will take the lightmap to be generated. It’s ok to use values as low as 1-4 for quickly prototyping while working in the Editor.
Modifying any parameter involved in lighting (Ambient Light, Standard Lights, Light Bounces, Emissive Materias) or modifying any Static object will trigger a new lightmap calculation phase.
General GI settings
The Indirect Light is the lighting effect of Ambient Light, Light Bounces and Emissive Materials (effect on nearby objects, not the emissive objects themselves), but not Environment Reflection. Scene Window > Irradiance shows the Indirect Light in the scene:
These settings affect the Indirect Light in both realtime and baked modes:
- Indirect intensity: Scales the indirect lighting (ambient + bounces + emissive)
- Bounce Boost: How strong the light bounces from one surface to the next. The bounced light is multiplied by the albedo of the surface intensified by this setting.
These settings affect the Baked GI mode only:
- Directional mode: whether to store directional and specular information in the lightmaps in Baked GI mode.
- Atlas size: size of the lightmaps in Baked GI mode.
Combining different lighting methods
The tutorial Unity 5 – Lighting and Rendering is a must-read for understanding the insights of the Global Illumination (GI) in Unity 5. The quotes here are extracted from this tutorial.
Precomputed realtime lighting + Baked lightmaps
It’s not a good idea, even given that both are enabled by default:
Although it is possible to simultaneously use Baked GI lighting and Precomputed Realtime GI, be wary that the performance cost associated with rendering both systems simultaneously is the sum of the cost of each of them. Not only do we have to store both sets of lightmaps in video memory, but we also pay the processing cost of decoding both in shaders.
[…] The decision on which approach to take will have to be evaluated based on the nature of your particular project and desired target platform. Remember that when targeting a range of different hardware, that often it is the least performant which will determine which approach is needed.
Standard realtime lighthting + Baked lightmaps
This is a convenient method for static and dynamic objects under the same constant lighting conditions:
Selecting the ‘Mixed’ baking mode [in the Light component], GameObjects marked as static will still include this light in their Baked GI lightmaps. However, unlike lights marked as ‘Baked’, Mixed lights will still contribute realtime, direct light to non-static GameObjects within your scene. This can be useful in cases where you are using lightmaps in your static environment, but you still want a character to use these same lights to cast realtime shadows onto lightmapped geometry.
Generating lightmap files
By default lightmap files are generated and stored internally each time a lightmap calculation phase is triggered (i.e. by moving static elements).
Lightmaps can be calculated manually by disabling the Auto checkbox in the Lighting window, then clicking the Build button. The generated files are stored in a folder with the same name as the scene they belong to. Baked data includes lightmaps and reflection probes.
The parameters Directional Mode and Atlas Size at the General GI section affect the type and number of the lightmap files.