DirectionalLightShadowCSM - Verge3D User Manual - Soft8Soft
Description: Learn how to use DirectionalLightShadowCSM in your interactive 3D apps made with Verge3D

LightShadow →

# DirectionalLightShadowCSM

This is used internally by DirectionalLights for calculating shadows.

Unlike the other shadow classes, this uses an OrthographicCamera to calculate the shadows, rather than a PerspectiveCamera. This is because light rays from a DirectionalLight are parallel. DirectionalLight usually illuminate a large scene with many objects, some close, some far away. To optimize shadow calculation in this situation, a technique called Cascaded Shadow Maps is used.

## Constructor

### DirectionalLightShadowCSM()

Creates a new DirectionalLightShadowCSM. This is not intended to be called directly — it is called internally by DirectionalLight.

## Properties

See the base LightShadow class for common properties.

### # .camera : Camera

Dummy camera.

### # .cascadesFitToScene : Boolean

Defines the method for creating subfrustums. If `true`, uses fit to scene, else fit to cascade method. The default is `false`. Use .setCascadesFitToScene to set this value.

### # .customSplitsCallback : Function

Defines custom method of partitioning the frustum into the subfrustums. The function should take this arguments: numCascades, near, far, breaks, exponent.

### # .exponent : Float

Defines the method of partitioning the frustum into the subfrustums, 0.0 linear split, 1.0 - logarifmic (i.e. puts more resolution towards the near clip plane). Only works in perspective view. Range is `0.0` to `1.0`. The default is `0.5`. Use .setExponent to set this value.

### # .fade : Float

When the fade is greater than 0.0, the size of each cascade (distance interval) is increased so that neighboring cascades overlap. Then a fade is applied in the overlapping region to provide a smooth transition between cascades. Try to use small values, else you may get rendering artifacts. Range is `0.0` to `1.0`. The default is `0.0`. Use .setFade to set this value.

### # .isDirectionalLightShadowCSM : Boolean

Read-only flag to check if a given object is of type DirectionalLightShadowCSM.

### # .mainFrustum : CSMFrustum

The main frustum.

### # .maxDistance : Float

Frustum far plane distance (i.e. shadows are not visible farther this distance from camera). May be smaller than camera.far value. Range is `0.0` to `Infinity`. The default is `100000`. Use .setMaxDistance to set this value.

### # .noLastCascadeCutOff : Boolean

If `true`, disables cutting off the last cascade for better shadow coverage. The default is `true`. Use .setNoLastCascadeCutOff to set this value.

### # .numCascades : Integer

The number of shadow cascades. Range is `1` to `4`. The default is `1`. Use .setNumCascades to set this value.

### # .lightMargin : Float

Defines how far shadow camera is moved along z axis in cascade frustum space. The larger is the value the more space the shadow will be able to cover. Should be set to high values for scenes with large or tall shadow casters. Range is `0.0` to `Infinity`. The default is `100.0`. Ignored if .autoLightMargin is `true`. Use .setLightMargin to set this value.

## Methods

See the base LightShadow class for common methods.

### # .createCascades() → this

Creates shadow map cascades.

### # .getBreaks(camera : Camera) → this

Recalculates split intervals for shadow cascades. Used internally.

### # .initCascades(camera : Camera) → this

Inits cascades, i.e. splits the main frustum. Used internally.

### # .setCascadesFitToScene(cascadesFitToScene : Boolean)

Defines the method for creating subfrustums. See .cascadesFitToScene.

### # .setExponent(exponent : Float)

Defines the method of partitioning the frustum into the subfrustums, 0.0 linear split, 1.0 - logarifmic (i.e. puts more resolution towards the near clip plane). See .exponent.

### # .setFade(fade : Float)

Sets the value of smooth transition between cascades. See .fade.

### # .setMaxDistance(maxDistance : Float)

Sets frustum far plane distance (i.e. shadows are not visible farther this distance from camera). See .maxDistance.

### # .setNoLastCascadeCutOff(noLastCascadeCutOff : Boolean)

If set `true`, disables cutting off the last cascade for better shadow coverage. See .noLastCascadeCutOff.

### # .setNumCascades(numCascades : Integer)

Defines the number of shadow cascades. See .numCascades.

### # .setLightMargin(lightMargin : Float)

Defines how far shadow camera is moved along z axis in cascade frustum space. See .lightMargin.

### # .update(camera : Camera, light : DirectionalLight) → this

Recalculates positions and frustums of shadow cascades.

### # .updateFrustums(camera : Camera) → this

Recalculates frustums for shadow cascades. Must be called after changing the view camera projection matrix, .exponent, .maxDistance or any bias settings.

### # .updateMaps() → this

Updates shadow maps. Used internally.

### # .updateMapSize(size : Vector2) → this

Changes shadow map resolution.

### # .updateCascadePositions(camera : Camera) → this

Recalculates positions of shadow cascades.

### # .updateShadowBounds(camera : Camera) → this

Recalculates frustums for shadow cascades. Used internally.

## Puzzles

The set shadow param puzzle allows to enable/disable casting or receiving shadows in a visual manner.

## Source

For more info on how to obtain the source code of this module see this page.