Skip to content

PlanarShadowMap: fix the depth range of SetupWholeSceneDirectionalLightView - #56

Open
ASDAlexander77 wants to merge 1 commit into
NVIDIA-RTX:mainfrom
ASDAlexander77:planar-shadow-map-whole-scene-depth-range
Open

ASDAlexander77 wants to merge 1 commit into
NVIDIA-RTX:mainfrom
ASDAlexander77:planar-shadow-map-whole-scene-depth-range

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Oct 10, 2026 •

Copy link
Copy Markdown

Problem

SetupWholeSceneDirectionalLightView fits an orthographic projection to the scene's bounds in the light's view space, then calls

orthoProjD3DStyle(mins.x, maxs.x, mins.y, maxs.y, -boundsView.m_maxs.z, -boundsView.m_mins.z);

That view space has +Z along the light direction (Light::GetDirection is the node's -Z, and the scaling(1, 1, -1) flips it), so the scene spans m_mins.z (nearest the light) to m_maxs.z, and orthoProjD3DStyle maps zNear to depth 0 and zFar to 1. Passing the range negated is only right when the bounds are symmetric about the light node's origin along its direction, which mostly holds for a light node at the center of a scene.

Otherwise part of the scene falls outside the shadow map's depth range:

  • D3D (depth clip disabled, NVRHI's default) clamps it to the near or far plane, so shadows are roughly right and the problem is easy to miss.
  • Vulkan clips it away (NVRHI can only disable depth clipping with VK_EXT_depth_clip_enable), so occluders vanish from the shadow map.

With Sponza and a sun added under the root node, about a third of the shadow map (two thirds of the texels the scene covers) was clamped to depth 0 on D3D12, and on Vulkan the roofs were missing from it entirely, so they cast no shadows.

Change

Pass boundsView.m_mins.z, boundsView.m_maxs.z. This also fixes CascadedShadowMap's per-object shadows: SetupPerObjectShadow calls this function with each object's bounds, which are rarely centered on the light's node. SetupDynamicDirectionalLightView is unaffected: its box is symmetric about the anchor.

After the change, the shadow map has no clamped texels, and D3D11, D3D12 and Vulkan render the same shadows.

🤖 Generated with Claude Code

…htView

The light's view space has +Z along the light direction (the node's -Z,
flipped), so the scene's depth range there is boundsView.m_mins.z to
m_maxs.z. The projection was given -m_maxs.z to -m_mins.z, which is right
only for scenes centered on the light's node along its direction; otherwise
part of the scene falls outside the shadow map's depth range: D3D clamps it
to the near or far plane, Vulkan clips it away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant