Click or drag to resize
DigitalRuneShadow Types
Defining shadows

All lights (except ambient lights) can cast shadows. Shadow computations are expensive, therefore shadows are disabled by default. Shadows can be enabled per light node by assigning a Shadow type to the LightNodeShadow property.

DigitalRune.Graphics (Shadows)
Class Diagram: Shadows

DigitalRune Graphics supports the following shadow types.

StandardShadow

The StandardShadow uses a regular shadow map. This type of shadow can be assigned to Spotlight nodes and ProjectorLight nodes.

CubeMapShadow

CubeMapShadow uses a cube map to create an omnidirectional shadow. This type of shadow can be assigned to PointLight nodes.

CascadedShadow

CascadedShadow describes a Cascaded Shadow Map (CSM), also known as Parallel Split Shadow Map (PSSM). Up to 4 shadow maps are used to create a shadow that can cover large distances. This type of shadow can be assigned to DirectionalLight nodes – usually the light node representing the sun.

Note Note

Terminology: The word "cascade" actually means "a series of stages". However, it is common to use the term "cascade" to describe an individual "slice" of the CSM instead of the whole series of slices. A "slice" is also called "cascade interval" or "sub-frustum".

The term "split" can refer to the border between two slices (4 slices = 3 splits) or to the slices. Therefore, the term "split" has to be used with care.

The property Distances defines the split distances in world units. This enables full control over the split distribution. Split distances can also be computed automatically as a mix of linear and logarithmic splitting using ComputeSplitDistances.

Shadow maps usually don't cover the whole visible area, which means the max shadow distance is less than the camera far distance. Shadows fade out near the max shadow range. This can be controlled using FadeOutRange.

ShadowFog defines the amount of shadow for all parts of the scene which are outside the max shadow range. In most games, the scene beyond the max shadow range receives full directional light (= no shadows). However, in some scenes, e.g. if the player is inside a dark wood, you might want to treat all parts outside the shadow range as partially shadowed to create a darker scene.

To compute each shadow map an orthographic projection is fitted to the partial camera frustum of the cascade. The near plane of this orthographic projection should be moved as close as possible to the cascade – but not too close in order to catch any shadow casters in front of the cascade. MinLightDistance defines the minimum allowed distance of the shadow projection near plane from the cascade. For example, if MinLightDistance is 100, then all birds and mountains will throw shadows if they are either inside the camera frustum or outside the camera frustum but within 100 units. Birds and mountains farther than 100 units might not throw shadows.

CascadeSelection defines which shadow maps are selected when the shader reads the shadow maps. Fast selects the cascades based on the z distance. This is fast but does not make the best use of the computed shadow maps.

Shadow-Cascade-Selection-Fast

The cascade transitions appear on horizontal lines in front of the camera. The transition is close to the camera.

Best is slower but makes optimal use of the rendered shadow maps. It checks the shadow map coordinates of each pixel to pick the best shadow map.

Shadow-Cascade-Selection-Best

The resolution near the camera has increased. Cascade transition are still visible along straight lines but the lines are not horizontal in front of the camera.

BestDithered uses a dither pattern to hide cascade transitions: In a small interval near the cascade transition, shadowed pixels randomly sample the best or the next-best cascade.

Shadow-Cascade-Selection-Best-Dithered

To hide the cascade transition even more, you could interpolate both shadow maps. This requires to sample both shadow maps for each pixel – whereas the dither method has to sample only one shadow map.

CompositeShadow

The CompositeShadow can be used to combine multiple shadows maps for one light source. For example, you can combine several shadow for the sun light to improve visual quality or performance:

  • A CascadedShadow creates detailed shadows of dynamic objects over a small distance.
  • Another CascadedShadow creates shadows of static objects over a large distance.
  • A variance shadow map creates soft shadows of distant hills and skyscrapers.
Custom shadow map types

Developers can add new types of shadow maps, if necessary. The Samples demonstrates how to create custom shadow map types, such as Variance Shadow Maps (VSM).