Lighting and shadows

Capítulo 9

Estimated reading time: 3 minutes

+ Exercise
Audio Icon

Listen in audio

0:00 / 0:00

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.

Continue in our app.
  • Listen to the audio with the screen off.
  • Earn a certificate upon completion.
  • Over 5000 courses for you to explore!
Or continue reading below...
Download App

Download the app

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.

The ideal light type for daytime lighting and outdoor shadows in Unity is the Directional Light. Directional Lights simulate sunlight, casting parallel rays that illuminate an entire scene consistently, which is perfect for outdoor environments.

Next chapter

Particle system

Arrow Right Icon
Free Ebook cover Complete game programming course with Unity
19%

Complete game programming course with Unity

4

(4)

48 pages

Download the app to earn free Certification and listen to the courses in the background, even with the screen off.