EDIT: Forward-Z cascaded shadow map failed...

This commit is contained in:
2025-10-20 14:26:08 +09:00
parent b419cc1148
commit 4dec20b60f
5 changed files with 17 additions and 13 deletions

View File

@@ -12,7 +12,7 @@ inline constexpr int kShadowCascadeCount = 4;
// Maximum shadow distance for CSM in view-space units
inline constexpr float kShadowCSMFar = 50.0f;
// Shadow map resolution used for stabilization (texel snapping). Must match actual image size.
inline constexpr float kShadowMapResolution = 2048.0f;
inline constexpr float kShadowMapResolution = 4096.0f;
// Extra XY expansion for cascade footprint (safety against FOV/aspect changes)
inline constexpr float kShadowCascadeRadiusScale = 1.15f;
// Additive XY margin in world units (light-space) beyond scaled radius

View File

@@ -35,6 +35,9 @@ void SamplerManager::init(DeviceManager *deviceManager)
sh.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
sh.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
sh.compareEnable = VK_FALSE; // manual PCF
// Depth shadow maps are single-level; keep base LOD only and avoid mip filtering.
sh.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
sh.maxLod = 0.0f;
sh.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
vkCreateSampler(_deviceManager->device(), &sh, nullptr, &_shadowLinearClamp);
}

View File

@@ -76,7 +76,6 @@ struct GPUSceneData {
glm::vec4 sunlightDirection; // w for sun power
glm::vec4 sunlightColor;
// CSM data (unused by current shaders until wired)
glm::mat4 lightViewProjCascades[4];
glm::vec4 cascadeSplitsView;
};

View File

@@ -122,7 +122,7 @@ void SceneManager::update_scene()
glm::vec3 up = glm::normalize(glm::cross(L, right));
const float csmFar = kShadowCSMFar; // configurable shadow distance
const float lambda = 0.8f; // split weighting
const float lambda = 0.5f; // split weighting
const int cascades = kShadowCascadeCount;
float splits[4] = {0, 0, 0, 0};
@@ -213,7 +213,9 @@ void SceneManager::update_scene()
float bottom = centerLS.y - radius;
float top = centerLS.y + radius;
mat4 projLight = orthoRH_ZO(left, rightE, bottom, top, nearLS, farLS);
mat4 projLight = orthoRH_ZO(-40.f, 40.f, -40.f, 40.f, nearLS, farLS);
// projLight[1][1] *= -1.0f;
return projLight * viewLight;
};