Add distance culling to shadow passes for CPU-bound shadow perf

All three shadow renderers (WMO, M2, Character) were iterating every
loaded instance with zero culling. Now skip instances outside the
180-unit shadow frustum radius via squared-distance check.
This commit is contained in:
Kelsi 2026-02-23 04:48:26 -08:00
parent 2cfa9d6b19
commit 2124761ea8
3 changed files with 20 additions and 3 deletions

View file

@ -2302,7 +2302,8 @@ bool CharacterRenderer::initializeShadow(VkRenderPass shadowRenderPass) {
return true;
}
void CharacterRenderer::renderShadow(VkCommandBuffer cmd, const glm::mat4& lightSpaceMatrix) {
void CharacterRenderer::renderShadow(VkCommandBuffer cmd, const glm::mat4& lightSpaceMatrix,
const glm::vec3& shadowCenter, float shadowRadius) {
if (!shadowPipeline_ || !shadowParamsSet_) return;
if (instances.empty() || models.empty()) return;
@ -2316,10 +2317,15 @@ void CharacterRenderer::renderShadow(VkCommandBuffer cmd, const glm::mat4& light
struct ShadowPush { glm::mat4 lightSpaceMatrix; glm::mat4 model; };
const float shadowRadiusSq = shadowRadius * shadowRadius;
for (auto& pair : instances) {
auto& inst = pair.second;
if (!inst.visible) continue;
// Distance cull against shadow frustum
glm::vec3 diff = inst.position - shadowCenter;
if (glm::dot(diff, diff) > shadowRadiusSq) continue;
auto modelIt = models.find(inst.modelId);
if (modelIt == models.end()) continue;
const M2ModelGPU& gpuModel = modelIt->second;