Overview
Lighting is one of the essential aspects of the game. A better lighting performance in a game can make your game interesting. Lighting can make the visuals of a game to stand out, let’s take an example of a game that has an environment concept of a dystopian era and cyberpunk age. The surrounding will utilize more neon lights for sure but the environment light needs to be redefined and needs skillful hands to reciprocate the exact environment a dystopian sci-fi age has, this increases the engagement quality for the players and allows them to connect with the story of the game on a deeper level.
Good lighting can make an average model look visually stunning in the game, on the other side poor light can make an extraordinary model feel blunt and without taste. In this blog, we will see what can be better lighting performance in a game.
Directional Lights
Direction Lights are useful for creating effects like sunlight. Directional lights can be thought of as distant light sources which exist far away. Directional lights are large distant sources that come from positions outside the range of the game. In a real scene, they can simulate the sun ( or moon).
In addition, pointing the light upwards causes the sky to turn black as if it were nighttime. The sky appears to be daylight whenever the light is directed downward. Default, every new Unity scene contains the Directional Light. You can also change its behaviour by deleting the default Light and creating a new light.
Directional Light Off
Directional Light On
Shadow
Shadows add a degree of depth and realism to a scene since they bring out the scale and position of objects that can look ‘flat’.
How Does Shadow Work
Light rays travel straight from that source and may hit objects in the scene. Once a ray has hit a thing, it can not travel further to illuminate anything else. The shadows cast by the object are simply the areas that are not illuminated because the light can not reach them.
Shadow Mapping and the Bias Property
The shadows for a given light are determined during the final scene rendering. When this scene is rendered to the main view camera, each pixel position in the view is transformed into the coordinate system of the light. The distance of a pixel from the light is compared to the corresponding pixel in the shadow map. If the pixel is more then it is presumably obscured from the light by another object and it will not get illumination.
No Shadow
Soft Shadow
Hard Shadow
Point light
A Point Light is located in space and sends light out in all directions equally. The direction of light hitting a surface is the line from the point of contact back to the center of the object. The intensity decreases with the distance from the light, reaching zero at a specified range. The intensity of light increases as the distance from a light source also is equivalent to a value multiplied by 1/d2. This is defined as the “inverse square law.”
Spotlight
A Spot Light has a specific location and range over which the light falls off. Whenever, the Spot Light is constrained to an angle, resulting in a cone-shaped region of illumination—the center of the cone points in the forward Z direction. Light also comes less (diminishes) at the edges of a Spot Light cone. Widening the spot angle increases the width of the cone & and increases the size of the fade, which is known as the ‘penumbra’.
Light Cookies
In theater, lighting effects have been long used to create an impression of objects that do not exist in the set. A prison scene often shows the light coming through the closed window, even though the window and indeed the wall are not part of the set. Though very atmospheric, the shadows are created simply by placing a mask shaped in between the light source and the action. This mask is known as a color or cookie for short. Unity lights allow you to add cookies in the form of textures to add atmosphere to a scene.
Creating a Cookie
The cookie is just an ordinary texture but only the transparency channel is relevant. When you import the cookie, Unity gives you the option to convert the brightness of the image to alpha so it’s often easier to design your cookie as a grayscale texture. You can use any image editor to create a cookie and save it to your project’s Assets folder.
When the cookie is imported in Unity, select it from the Project view and set the Texture Type to Cookie in the inspector. You need to also enable Alpha From Grayscale unless you already have designed the image’s alpha channel yourself.
The Light Type affects the way the cookie is projected by the light. A spotlight should use a cookie with the set type to Spotlight but a directional light can use the Spotlight or Directional options. A directional cookie with a directional light will repeat the cookie in a tiled pattern all over the scene. When a spotlight cookie is used, the cookie will appear just once in the ‘beam’ of its direct path of the light; this is the only case where the position of a directional light is important.
Applying a Cookie to a Light
When the texture is imported, drag it to Light’s Cookie property in the inspector.
The spotlight and point light simply scale the cookie according to the size of the cone or sphere. The directional light has an additional option of Cookie Size that lets you scale the cookie yourself; the scaling works with both Spotlight and Directional cookie types.
Uses of Cookies
Cookies are often used to change the shape of light so it matches a detail ‘painted’ in the scene. For example, a dark tunnel may have strip lights along with the ceiling. If you use standard spotlights for illumination then the beams will have an unexpected round shape but you could use cookies to restrict the lights to a thin rectangle. A green glow out of a monitor screen may shine on a character’s face, but it should just fill a tiny space.
Note: The cookie need not be completely black and white but can also incorporate any grayscale level. This can be useful for simulating dust in the path of light.
Realtime GI
Realtime GI is useful for Lights that change slowly & have a significant visual impact on your Scene, such as the sun moving across the sky, or slowly pulsating light in the closed corridor. Realtime Global Illumination is suitable for games that target mid-level to high-end PC systems and consoles. Some high-end small devices (like mobile) might also be powerful enough to make use of this feature, but you should keep small Scenes & the resolution for real-time lightmaps low to conserve system resources.
Using Realtime GI
To enable Realtime GI in your Scene
Open Window > Rendering > Lighting and Enable Realtime Global Illumination.
Light Probes and Realtime GI
When you enable Realtime Global Illumination in a Scene, Light Probes sample lighting iteratively at runtime. It means that they react to runtime changes in lighting scenes.
Baked GI
Global Illumination (GI) is a system that models how light is bounced off of surfaces onto indirect light rather than being limited to just the light that hits a surface directly from direct light.
Baked Light behaviour
- Unity bake both direct lighting and indirect lighting from Baked Lights into a lightmap
- For more information on using lightmaps, see lightmapping.
Limitations of Baked Lights
- You cannot change the properties of Baked Lights at runtime.
- Baked Lights do not contribute to specular lighting.
- Dynamic GameObject does not receive light or shadow from Baked Lights.
Conclusion
In this blog, we gave an overview of the considerations which need to be made before setting up a scene for lighting and how lighting is one of the most impactful stages when it comes to unity game development. We have also briefly looked at creating various lighting effects. Combining this with the ability to quickly iterate on lighting with real-time updates to Global Illumination, plus the ability to change bounced lighting at run time, it quickly becomes easy to see how Unity’s Precomputed Realtime Global Illumination can be an attractive option for many real-time applications.
Baked is pre-computed and saves the engine a ton of processing power when dealing with shadows in a scene. Whenever you have a static light source and static objects (i.e. they don’t move), then they use baking.