Lighting in Unity is more fully featured than ever.
The lighting pipeline includes realtime global illumination,
in addition to traditional baked light mapping techniques.
These combined with physically-based rendering
and the standard shader
give more power and versatility to light more complex scenes.
Unity uses physically-based rendering, or PBR
to create a friendly way of achieving a consistent
plausible look for materials under all lighting conditions.
In order to do so, Unity models how light actually behaves
and follows the laws of physics on how
light interacts with materials.
These materials are usually created using the standard shader.
The standard shader makes physically
based rendering easy and accessible to use.
One of the most powerful tools in the Unity
pipeline is Unity's realtime global illumination,
or GI.
Using GI, all lights in the scene can effect
the object's within range with both
direct and indirect illumination.
Direct illumination comes from lights
shining directly on the objects in the scene.
Indirect illumination however
is the light reflected, or bounced off of
the light surfaces in the scene.
This bounced indirect light
can illuminate nearby objects
mimicking how light behaves in the real world
This indirect light is effected
by the colour of the surfaces it bounces off of,
taking a contribution of that surface's colour with it.
Direct and indirect light will
blend together to create a much more realistic look.
In addition to the default main camera
a new scene in Unity comes with
a default sky box
and a default directional light aligned
with that sky box.
Each scene also contains default
values for ambient light.
Ambient light illuminates all surfaces in the scene.
Ambient light is controlled by the settings in the
lighting panels Environment Lighting tab.
Ambient light can be created by either
using a sky box,
a user generated gradient of 3 colours,
or a single colour.
All objects added to the scene
will receive ambient light
unless the ambient intensity value is set to 0
or the ambient light's colour values are set to black.
It is rare, if not impossible
for any real-world material
to have absolutely no reflectivity.
By default all objects in the scene
will also receive reflection information.
Even though the cube, sphere and plane in the scene
are unlit and ambient light is none
they still receive lighting information
in the form of reflections.
The default reflection source is the sky box.
This can be changed to a custom cube map.
To receive no default reflections
either set the custom cube map to none,
or remove the sky box.
It is worth noting that the default sky box
is procedurally generated
and new procedural sky boxes
can be created and saved as assets.
When lighting scenes in Unity
we can work with realtime lighting,
baked lighting,
or a mixture of both.
Realtime lighting is more easily modified at run time.
but it comes at a cost to performance.
Baked lighting on the other hand pre-calculates
much more detailed lighting information
and saves it to a light mapped texture on disc.
This light map information is then
read from the texture at run time,
avoiding the need to do any lighting
calculations when the project is running.
This saves performance,
but at the cost of dynamic changes in the scene.
Baked light maps are not updated at run time.
Lights can be switched between realtime, baked,
and mixed lighting on a per-light basis.
Using baked lighting exclusively
would be more appropriate for target platforms
such as mobile devices with lower performance capabilities.
The light mapping system can either work
continuously or on demand.
When continuous baking is selected
lighting changes will be baked in the background while editing.
These changes can either be properties
adjusted in the inspector,
or objects changed in the scene.
When continuous baking is not selected
changes will only preview on demand.
When the Build button in the lighting panel has been selected.
In this scene there is a directional light
coming in through the skylight in the ceiling.
This light contributes to the illumination of the entire scene
as the light bounces off of the surfaces
it lights directly,
on to other nearby surfaces in an indirect manner.
This light continues to indirectly
illuminate nearby surfaces
until the strength of the light fades
and it can bounce no more.
Decrease the intensity of the light
and the illumination of the scene decreases accordingly.
Likewise, if the directional light
is rotated to directly light a
different part of the scene,
it will now illuminate the scene in a different way,
with both it's direct and indirect lighting.
As materials created with a standard shader
can mimic a wide variety of physical surfaces
and different materials can have different
amounts of reflectivity
this can effect the scene's lighting.
To help balance this the Bounce Intensity can be adjusted
on either a per-light basis
or globally by adjusting the settings
in the lighting panel.
Adjustments can be made here to artificially
change the potential bounce of light from a lit surface.
Adjust the mount of indirect light
in the scene, and more.
In addition to lights we can use
emissive surfaces to contribute to the scene's lighting.
This scene is lit with a variety of lights
and light types, including emissive surfaces.
Emissive surfaces are a light source,
but they behave very much like indirect bounced light.
The primary emissive surfaces in the scene
are in the main corridor junction.
But additional panels are located throughout the scene.
All of these emissive surfaces use
the standard shader's Emission property
by adjusting the Emissive scale.
The float value next to the Emission property
and by adding a touch of colour,
the mood of our scene changes.
As these lights can participate in realtime light mapping
they can be controlled at runtime using
code or animation to create
complex changes in mood
while our projects are running.
The final contributing factor in lighting
a Unity scene are probes.
There are 2 types of probes in Unity.
Light probes
and reflection probes.
Light probes sample the lighting in the scene
at different positions in the world.
The information in these probes can be used
to light dynamic elements in the scene
such as characters or other moving objects
at a low cost to performance.
Reflection probes on the other hand
act as a single point of reference to
calculate reflections from
Surrounding each reflection probes
is a cuboid that specifies
what should be included in that reflection.
These probes sample the elements surrounding them
using box projection,
and store that information in a cube map.
Materials with reflective surfaces
that are on objects within the reflection probe's volume
can then reference this cube map to
create reflective surfaces.
By default there is one built-in
reflection probe in every scene.
This default reflection probe
reflects the sky box to create basic reflections.
For more detail in the reflections
additional reflection probes
should be added and positioned appropriately
for the reflective objects.
It is worth noting that phyically-based rendering
works best in linear colour space.
Linear colour space will give
a more realistic and mathematically correct result.
For best results make sure that
the colour space is set to linear
in the project's
Player Settings window.
Linear colour space is the default setting.
Be aware that not all platforms
support linear colour space however,
and that gamma is currently the
required colour space for most mobile platforms,.
When looking at all these aspects
to lighting a scene in Unity
they can be summed up effectively
with the main contributory factors.
Ambient light.
Reflections.
And light sources.
Working with materials created
with the standard shader being
drawn using phyically-based rendering
with global illumination to calculate
the indirect light and create
more complex, more realistic scenes.