Saturday, June 28, 2025
spot_img

directx11 – Difficulties with matrices settings for cascaded shadows


I’ve added cascaded shadows to my pipeline. The entire course of appears to works superb as proven within the image. However I ought to get hold of a progressive “zoom” from the primary cascade (purple) to the final (blue) and right here the zoom is sort of the identical. Beneath the code I take advantage of coming from https://github.com/SaschaWillems/Vulkan/blob/grasp/examples/shadowmappingcascade/shadowmappingcascade.cpp. I’ve modified the unique one to make use of DX11 XMVECTOR capabilities.

code for CSM

The lightview setting

gLightView = XMMatrixLookAtLH(XMVectorSet(-800, 800, 800, 1), XMVectorSet(0, 0, 0, 1), XMVectorSet(0, 1, 0, 0));
CalculateShadowFrustrums();

The CalculateShadowFrustrums is as follows:

void CalculateShadowFrustrums()
{
  float cascadeSplits[3];
  float nearClip = NearPlane;
  float farClip = FarPlane;
  float clipRange = farClip - nearClip;

  // Calculate cut up depths based mostly on view digicam frustum
  // Based mostly on technique offered in https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch10.html
  BOOL bUseNVidia = false;
  if (bUseNVidia)
  {
    float minZ = nearClip;
    float maxZ = nearClip + clipRange;
    float ratio = maxZ / minZ;
    float vary = maxZ - minZ;
    float cascadeSplitLambda = 0.90f;
    for (int i = 0; i 

Values obtained for gSRVDSVRTVShadowCascade.Depths with the preliminary guide cascadeSplits settings match elements of the close to/far planes in scene house
Depth0 round 250
Depth1 round 650
Depth2 = farplane

Within the vertex/pixel shader

  cbuffer cbShadowCascade : register(b7)
  {
    matrix View;//used to get the place in scene view house for Enter.VPos
    matrix LightViewProjection[3];//the three viewproj cascaded matrices
    float4 Cascade;//xyz are the three depth limits; w!=3 if cascade not used
  }

  struct PS_INPUT
{
  …
 float4 Shadow[3] : TEXCOORD1;
};

PS_INPUT VS_Forward(VS_INPUT Enter)
{
 ….
  Output.Shadow1[0] = mul(Output.Pos, LightViewProjection[0]);//if used as common depth map
  Output.VPos = 0;
  Output.Shadow1[1] = 0;
  Output.Shadow1[2] = 0;
  if ( Cascade.w==3)
  {
    Output.VPos = mul(Output.Pos, View).xyz;
    Output.Shadow1[1] = mul(Output.Pos, LightViewProjection[1]);
    Output.Shadow1[2] = mul(Output.Pos, LightViewProjection[2]);
  }

Within the shadowing a part of the pixel shader

    float pVz = Enter.VPos.z; //place in scene view house to be in comparison with the scene view house cascade.depth Cascade[0-2] set within the fixed buffer.
    uint CIndex = (pVz

Another strategies are remodeling the frustrum to world after which to mild house however I see no modifications within the shadow rendering.

I am certainly lacking one thing.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles