Formalize directional shadow runtime contracts
This commit is contained in:
33
engine/src/Rendering/Shadow/DirectionalShadowData.cpp
Normal file
33
engine/src/Rendering/Shadow/DirectionalShadowData.cpp
Normal 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
|
||||
Reference in New Issue
Block a user