Greetings warriors of Calradia!
Lighting
is an extremely important aspect of any modern game. Bad
lighting can make the most detailed models and textures seem
drab and lifeless, while good lighting helps to bring together
the different visual elements on-screen to provide a more
realistic and aesthetically pleasing polish. This is something
that we are acutely aware of, and is what led to the
introduction of Global Illumination (GI) to our game engine
some time back, (which we briefly mentioned at the time in our
Engine 1.4 Update
blog).
Recently, we have been working on enhancing and
heavily optimising this engine feature, so we wanted to take
the time to expand on this and discuss GI in a little more
detail, covering our requirements, how the system works, and
touching on some of the difficulties we faced while
implementing it.
So, what is GI? To put it
simply, GI is a system that models how light is bounced off of
surfaces onto other surfaces, or in other words, indirect
lighting. This allows light that has been emitted from a
source, for example, a torch, to interact with surrounding
objects in a more natural manner with some of the light being
absorbed by the object and the rest being reflected onto other
objects. The end result is a much more realistic
representation of how light acts in the real world.
In
Bannerlord, we decided to go for a GI solution that can handle
different lighting environments, can run on a wide spectrum of
hardware, has low memory and hard drive usage and requires
less manual work to be done per scene. With these
requirements, we decided to use a static solution that bakes
the lighting transfer on pre-defined probe points.
For our implementation, we drew inspiration from
multiple techniques. The core lighting algorithm uses the
technique from
Precomputed Radiance Transfer for Real-Time Rendering in
Dynamic, Low-Frequency Lighting Environments
(Sloan, et al, 2002). In addition to this, we implemented an
in-game offline ray tracer to ensure that the lighting is
correct with the ground truth. After that, we modified some
equations so that gameplay would not be negatively affected
(e.g. increasing the ambient light of torches).
With
probe-based methods, such as the one that our engine uses, a
major issue is light leaking, which can drastically reduce the
visual quality. To solve these leaking issues, we use the
shadow map algorithm described in the
Irradiance & Light field Probes with Visibility
slide (Morgan McGuire, 2017). However, the most challenging
and time-consuming part was to implement a process that can
automate the probe placement, light leak shadow map placement,
and baking process.
Firstly, we didn’t
want to place probes everywhere as this would save huge
amounts of memory and hard drive usage, which was one of our
initial design requirements. So, to achieve the desired visual
result while remaining conscious of hardware usage, our
automated baking process uses the navigation mesh to find the
positions that agents can go. Then, from these positions, rays
are cast to find the visible points on the scene. For all of
these points, the automatic process then places probes in a
grid fashion. Following this, the automatic process assigns
shadow-map functionality to the ones that might introduce
leaks. For example, an outside probe which affects both the
inside of a house and the outside will render a shadow-map to
prevent leaking. Finally, the lighting transfer function is
calculated for every probe placed. This process is done for
every level combination for towns and once for multiplayer and
interior maps.
This automatic baking process
can be run via the editor or our internal integration system,
saving a huge amount of time for our scene designers! And the
good news is that this will also be available to modders and
is as simple as the click of a button in the scene editor.
Also, additional editing time is optimised with many advanced
editing operations like lasso and geometric selection
operations and shortcuts in the editor.
We are quite pleased with the final results. Our
implementation of GI certainly enhances the visuals of the
game by adding some visual depth to scenes and making the
environments more realistic, and all with a minimal impact on
performance!
Join the conversation and comment on the forums! (90 comments)