Shadows

Shadows bring significant information and realism to a scene.

Only directional lights, , and spot lights can cast shadows.

Xenko uses shadow mapping to render shadows. To understand shadow maps, imagine a camera in the center of the sun, so you're looking down from the sun's perspective.

From this perspective, Xenko creates a shadow map for each light that casts shadows. This tells us how far each visible pixel is from the light. When Xenko renders the scene, it checks the position of each pixel in the shadow map to learn if it can be "seen" by the light. If the light can see the pixel, the light is illuminated. If it can't, the pixel is in shadow.

For example, these are shadow maps from the first-person shooter sample included in Xenko, generated by a .

FPS scene

Note

Shadow maps for each light that casts a shadow are saved in a region of the shadow atlas texture. You can choose how much of the shadow atlas each light uses. The larger the shadow map, the better the shadow quality, but the less space you have for shadow maps from other light sources.

Higher-quality shadow (uses a large area of the shadow atlas)Lower-quality shadow (uses a smaller area of the shadow atlas)
High-resolution shadow
FPS scene shadow map

Generally, you should give more space to light sources that cast the most visible shadows.

The size of each area in the shadow map depends on several factors:

  • the based on the property (/8, /4, /2, x1, or x2)
  • the projected size of the light in screenspace ()
    • for directional lights, the lightSize is equal to the max (screenWidth, screenHeight)
  • the equals The final size of the shadow map is calculated like this:

If you've enabled shadows on a light in your scene, but it isn't casting shadows, make sure there's enough space in the shadow atlas to create a shadow map for the light. For more information, see Troubleshooting — Lights don't cast shadows.

See also