Repository navigation
PlanarShadowMap: fix the depth range of SetupWholeSceneDirectionalLightView - #56
Open
ASDAlexander77 wants to merge 1 commit into
Open
ASDAlexander77 wants to merge 1 commit into
ASDAlexander77 wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SetupWholeSceneDirectionalLightViewfits an orthographic projection to the scene's bounds in the light's view space, then callsorthoProjD3DStyle(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::GetDirectionis the node's -Z, and thescaling(1, 1, -1)flips it), so the scene spansm_mins.z(nearest the light) tom_maxs.z, andorthoProjD3DStylemapszNearto depth 0 andzFarto 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:
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 fixesCascadedShadowMap's per-object shadows:SetupPerObjectShadowcalls this function with each object's bounds, which are rarely centered on the light's node.SetupDynamicDirectionalLightViewis 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