In chapter nine of our Unity game programming course, we'll explore a crucial aspect of game design: lighting and shadows. These elements are fundamental to creating an immersive and realistic atmosphere in your game. They can help set the mood, guide the player, highlight points of interest, and more.

Unity offers a variety of tools to help you manipulate light and shadows in your game. Let's start with an overview of the types of lights available in Unity.

Types of Lights

There are four main types of lights in Unity: Directional, Point, Spot and Area. Each has its own characteristics and uses.

Directional lights are like the sun: they illuminate everything from a specific direction, regardless of distance. They are ideal for daytime lighting and outdoor shade.

Spot lights are like light bulbs: they emit light in all directions from a single point. They are perfect for creating localized light effects, like a lamp or a torch.

Spot lights are like flashlights: they emit a cone of light from a point in a specific direction. They are ideal for spotlights or car headlights.

Finally, area lights emit light from a specific surface, such as a window or computer monitor. They are the most realistic, but also the most expensive in terms of performance.

Working with Shadows

Shadows add depth and realism to your game. Unity offers two options for shadows: Hard Shadows and Soft Shadows. Hard Shadows have sharp edges and are easier to compute, while Soft Shadows have soft edges and are more realistic, but also more expensive in terms of performance.

To enable shadows, you need to set the light to cast shadows and have objects in your scene that can cast shadows. You can also adjust the resolution, softness, and fade distance of shadows to optimize performance and appearance.

Global Illumination

In addition to individual lights, Unity also offers Global Illumination, which simulates how light is reflected and absorbed by the environment. This can add an extra level of realism to your game, but it is also more expensive in terms of performance.

To use Global Illumination, you need to create a light map, which is a texture that stores information about how light interacts with the environment. Unity can calculate this light map automatically, or you can create your own for more precise control.

Conclusion

Lighting and shadows are powerful tools for creating an immersive, realistic atmosphere in your game. With Unity, you have a variety of options at your disposal, from individual lights to Global Illumination. However, it's important to remember that lighting and shadows come at a performance cost, so it's important to optimize them for your game.

We hope this chapter has given you a good introduction to lighting and shadows in Unity. In the next chapter, we'll explore another crucial aspect of game design: sound.

Now answer the exercise about the content:

Which of the following light types in Unity is ideal for daytime lighting and outdoor shadows?

You are right! Congratulations, now go to the next page

You missed! Try again.

Article image Particle system

Next page of the Free Ebook:

10Particle system

3 minutes

Obtenez votre certificat pour ce cours gratuitement ! en téléchargeant lapplication Cursa et en lisant lebook qui sy trouve. Disponible sur Google Play ou App Store !

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text