Formalize directional shadow runtime contracts

This commit is contained in:
2026-04-13 23:11:28 +08:00
parent 4362008b39
commit 0d6b8bf7d8
15 changed files with 740 additions and 178 deletions

View File

@@ -0,0 +1,33 @@
#include "Rendering/Shadow/DirectionalShadowData.h"
namespace XCEngine {
namespace Rendering {
RenderDirectionalShadowData BuildRenderDirectionalShadowData(
const DirectionalShadowRenderPlan& plan,
RHI::RHIResourceView* shadowMapView) {
RenderDirectionalShadowData shadowData = {};
if (!plan.IsValid() || shadowMapView == nullptr) {
return shadowData;
}
shadowData.enabled = true;
shadowData.viewProjection = plan.cameraData.viewProjection;
shadowData.shadowMap = shadowMapView;
const float texelWorldSize = plan.texelWorldSize > Math::EPSILON
? plan.texelWorldSize
: (plan.orthographicHalfExtent > Math::EPSILON && plan.mapWidth > 0u
? (plan.orthographicHalfExtent * 2.0f) / static_cast<float>(plan.mapWidth)
: 0.0f);
shadowData.mapMetrics.inverseMapSize = Math::Vector2(
1.0f / static_cast<float>(plan.mapWidth),
1.0f / static_cast<float>(plan.mapHeight));
shadowData.mapMetrics.worldTexelSize = texelWorldSize;
shadowData.sampling.enabled = 1.0f;
shadowData.sampling.settings = plan.sampling;
shadowData.casterBias.settings = plan.casterBias;
return shadowData;
}
} // namespace Rendering
} // namespace XCEngine