Hello everyone, prepare to get technical! This is Spencer writing today to share some insight on what it takes to light our levels in Umbrella Mondays! (We wrote a blog post about the art side of lighting last week!)
To utilize the Lighting in Unity, we use the different types of light primitives (point, cone, area, and directional) to send out light data to shaders, which calculate what the player sees at each spot in the game. The shaders control everything from shadows to color highlights. Computationally, lighting takes a lot of processing power, which is why computers have dedicated graphics cards to run calculations for every frame!
Unity has a standard shader library, which gives us a starting place for creating specular highlights, detailed shadows, and more. These effects are controlled by an object’s texture, but in order for that texture to be visible, we must use lights!
We mentioned that computing light information takes a lot of processing power. If a Unity game has too many lights, it can cause the game to run slowly since the graphics card has to calculate light information for every object in the game. One way that Unity makes lighting less intensive is through “baking,” which allows us to preprocess the lighting on any static (or non-moving) object.
Lights on non-moving objects can be super accurate in Unity, since Unity can calculate indirect lighting and bounce between objects, creating higher definition shadows. How this works is Unity processes the indirect lighting on all of our static objects, then translates that data into lighting maps that, when the game runs, overlay the objects to show the precomputed (baked) lighting. This way, the game’s frame rate stays higher with good graphical fidelity, as the lighting calculations are already done by play time for a large portion of objects.
Some of our objects move, however, and dynamic lighting must still be computed. As an object moves, the light on the surface changes, so we can’t have pre-calculated lighting data!
Objects that are dynamic, such as Fella, won’t have baked lighting applied to them, but instead only respond to lights we allow to process in real time. However, they can receive our bake data from static points called light probes.
Light probes are a web of data points in the Unity scene that saves the light data that was baked on to them during preprocessing, and then average their results with other nearby light probes to apply an ambient light to dynamic objects to match the scene around them! This way, dynamic moving objects can still have baked lights applied.
Another way to have lights enhance our game in Unity is to apply volumetric lighting. Volumetric lighting is a special lighting effect where the area (volume) that the light passes through also has some sort of lighting effect applied, rather than the light just affecting the surfaces that it hits. A common example of volumetric lighting would be fog and dust effects. The results can be dramatic!
As always, thanks for reading! See you next week!