Click or drag to resize
AB4D logo

VarianceShadowRenderingProvider Class

VarianceShadowRenderingProvider provides support for rendering shadows with using Variance shadow rendering technique. Currently only one SpotLight or one DirectionalLight shadow casting light are supported.
Inheritance Hierarchy
SystemObject
  Ab3d.DirectXDXResourceBase
    Ab3d.DirectXDisposableDXResource
      Ab3d.DirectXDXSceneResource
        Ab3d.DirectXShadowRenderingProviderBase
          Ab3d.DirectXVarianceShadowRenderingProvider

Namespace: Ab3d.DirectX
Assembly: Ab3d.DXEngine (in Ab3d.DXEngine.dll) Version: 7.1.9105.2048 (1.0.0.0)
Syntax
C#
public class VarianceShadowRenderingProvider : ShadowRenderingProviderBase

The VarianceShadowRenderingProvider type exposes the following members.

Constructors
 NameDescription
Public methodVarianceShadowRenderingProvider Constructor
Top
Properties
 NameDescription
Public propertyChangeBackBufferRenderingStep Gets a ChangeBackBufferRenderingStep that changes render targets from shadow depth rendering to rendering 3D scene.
Public propertyDepthBlurPostProcessingRenderingStep Gets a RenderPostProcessingRenderingStep that runs a post process that blurs the shadow depth map.
Public propertyPrepareShadowDepthRenderingStep Gets a PrepareVarianceShadowMappingRenderingStep that prepares render targets for variance shadow depth rendering.
Public propertyRenderNonShadowObjectsRenderingStep Gets a RenderObjectsRenderingStep that renders all objects that do not cast shadow.
Public propertyRenderShadowDepthRenderingStep Gets a RenderObjectsRenderingStep that renders shadow depth map - render objects from the light perspective and writes a distance from the light to a shadow depth map. This rendering step uses VarianceShadowDepthEffect to render objects (it is set to OverrideEffect property), filters object setting FilterObjectsFunction to FilterShadowCastingObjectsFunction(RenderablePrimitiveBase) and filters lights to use only the first shadow light (using FilterLightsFunction property).
Public propertyShadowDepthBias Gets or sets a float value that offsets the depth of the lights (distance from the lights to the object) and can help reduce the show artifacts in the corners. The value does not work for all 3D scenes because it depends on the size of the scene. Default value is 0 that does not apply any bias.
Public propertyShadowDepthBluringSize Gets or sets an integer that specifies the blur amount that is applied on the shadow depth map and can produce shadows with nice soft edges. Default value is 4.
Public propertyShadowMapSize Gets or sets and integer value that represents the size of a shadow depth map texture. Default value is 512 and means that by default a 512 x 512 texture will be used.
Public propertyShadowRenderingStepsGroup Gets a RenderingStepsGroup that groups rendering step that render shadow map.
Public propertyShadowThreshold Gets or sets a float value that helps prevent light bleeding (having areas that should be in shadow fully illuminated) for variance shadow mapping. Default value is 0.2f.
Public propertyShadowTresholdObsolete.
Gets or sets a float value that helps prevent light bleeding (having areas that should be in shadow fully illuminated) for variance shadow mapping. Default value is 0.2f.
Top
Fields
 NameDescription
Public fieldStatic memberChangeRenderTargetRenderingStepName Name for ChangeRenderTargetRenderingStep
Public fieldStatic memberDepthBlurPostProcessingRenderingStepName Name for DepthBlurPostProcessingRenderingStep
Public fieldStatic memberPrepareVarianceShadowMappingRenderingStepsName Name of the PrepareVarianceShadowMappingRenderingStep that prepares parameters for other rendering steps in shadow depth rendering.
Public fieldStatic memberRenderNonShadowObjectsRenderingStepName Name for RenderNonShadowObjectsRenderingStep
Public fieldStatic memberRenderShadowDepthRenderingStepName Name for RenderShadowDepthRenderingStep
Public fieldStatic memberShadowDepthMapRenderingStepsGroupName Name of the RenderingStepsGroup that contains rendering steps that render shadow depth map.
Top
Remarks

VarianceShadowRenderingProvider provides support for rendering shadows with using Variance shadow rendering technique.

The used algorithm is based on the GPU Gems3 "Chapter 8. Summed-Area Variance Shadow Maps" (https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch08.html)

Currently only one SpotLight or one DirectionalLight shadow casting light are supported.

Example

To enable shadow rendering the InitializeShadowRendering(ShadowRenderingProviderBase) method must be called with an instance of VarianceShadowRenderingProvider. Then the light that casts the shadow needs to be specified with setting the DXAttributeType.IsCastingShadow attribute on the light. The following code shows that:

C#
// Create new VarianceShadowRenderingProvider
var varianceShadowRenderingProvider = new VarianceShadowRenderingProvider()
{
    ShadowMapSize = 512,
    ShadowDepthBluringSize = 4,
    ShadowThreshold = 0.2f
};

// Initialize shadow rendering with DXEngine
MainDXViewportView.DXScene.InitializeShadowRendering(varianceShadowRenderingProvider);


// Create a SpotLight
var shadowSpotLight = new SpotLight()
{
    Position = new Point3D(0, 100, -500),
    Direction = new Vector3D(0, -1, 5)
};

// Mark it for casting shadow (set IsCastingShadow DXEngine attribute to true)
shadowSpotLight.SetDXAttribute(DXAttributeType.IsCastingShadow, true);
See Also