mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 17:43:52 +00:00
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:
parent
2cfa9d6b19
commit
2124761ea8
3 changed files with 20 additions and 3 deletions
|
|
@ -2302,7 +2302,8 @@ bool CharacterRenderer::initializeShadow(VkRenderPass shadowRenderPass) {
|
||||||
return true;
|
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 (!shadowPipeline_ || !shadowParamsSet_) return;
|
||||||
if (instances.empty() || models.empty()) 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; };
|
struct ShadowPush { glm::mat4 lightSpaceMatrix; glm::mat4 model; };
|
||||||
|
|
||||||
|
const float shadowRadiusSq = shadowRadius * shadowRadius;
|
||||||
for (auto& pair : instances) {
|
for (auto& pair : instances) {
|
||||||
auto& inst = pair.second;
|
auto& inst = pair.second;
|
||||||
if (!inst.visible) continue;
|
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);
|
auto modelIt = models.find(inst.modelId);
|
||||||
if (modelIt == models.end()) continue;
|
if (modelIt == models.end()) continue;
|
||||||
const M2ModelGPU& gpuModel = modelIt->second;
|
const M2ModelGPU& gpuModel = modelIt->second;
|
||||||
|
|
|
||||||
|
|
@ -2607,11 +2607,13 @@ bool M2Renderer::initializeShadow(VkRenderPass shadowRenderPass) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void M2Renderer::renderShadow(VkCommandBuffer cmd, const glm::mat4& lightSpaceMatrix, float globalTime) {
|
void M2Renderer::renderShadow(VkCommandBuffer cmd, const glm::mat4& lightSpaceMatrix, float globalTime,
|
||||||
|
const glm::vec3& shadowCenter, float shadowRadius) {
|
||||||
if (!shadowPipeline_ || !shadowParamsSet_) return;
|
if (!shadowPipeline_ || !shadowParamsSet_) return;
|
||||||
if (instances.empty() || models.empty()) return;
|
if (instances.empty() || models.empty()) return;
|
||||||
|
|
||||||
struct ShadowPush { glm::mat4 lightSpaceMatrix; glm::mat4 model; };
|
struct ShadowPush { glm::mat4 lightSpaceMatrix; glm::mat4 model; };
|
||||||
|
const float shadowRadiusSq = shadowRadius * shadowRadius;
|
||||||
|
|
||||||
// Helper lambda to draw instances with a given foliageSway setting
|
// Helper lambda to draw instances with a given foliageSway setting
|
||||||
auto drawPass = [&](bool foliagePass) {
|
auto drawPass = [&](bool foliagePass) {
|
||||||
|
|
@ -2641,6 +2643,10 @@ void M2Renderer::renderShadow(VkCommandBuffer cmd, const glm::mat4& lightSpaceMa
|
||||||
const M2ModelGPU* currentModel = nullptr;
|
const M2ModelGPU* currentModel = nullptr;
|
||||||
|
|
||||||
for (const auto& instance : instances) {
|
for (const auto& instance : instances) {
|
||||||
|
// Distance cull against shadow frustum
|
||||||
|
glm::vec3 diff = instance.position - shadowCenter;
|
||||||
|
if (glm::dot(diff, diff) > shadowRadiusSq) continue;
|
||||||
|
|
||||||
auto modelIt = models.find(instance.modelId);
|
auto modelIt = models.find(instance.modelId);
|
||||||
if (modelIt == models.end()) continue;
|
if (modelIt == models.end()) continue;
|
||||||
const M2ModelGPU& model = modelIt->second;
|
const M2ModelGPU& model = modelIt->second;
|
||||||
|
|
|
||||||
|
|
@ -1671,7 +1671,8 @@ bool WMORenderer::initializeShadow(VkRenderPass shadowRenderPass) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WMORenderer::renderShadow(VkCommandBuffer cmd, const glm::mat4& lightSpaceMatrix) {
|
void WMORenderer::renderShadow(VkCommandBuffer cmd, const glm::mat4& lightSpaceMatrix,
|
||||||
|
const glm::vec3& shadowCenter, float shadowRadius) {
|
||||||
if (!shadowPipeline_ || !shadowParamsSet_) return;
|
if (!shadowPipeline_ || !shadowParamsSet_) return;
|
||||||
if (instances.empty() || loadedModels.empty()) return;
|
if (instances.empty() || loadedModels.empty()) return;
|
||||||
|
|
||||||
|
|
@ -1681,7 +1682,11 @@ void WMORenderer::renderShadow(VkCommandBuffer cmd, const glm::mat4& lightSpaceM
|
||||||
|
|
||||||
struct ShadowPush { glm::mat4 lightSpaceMatrix; glm::mat4 model; };
|
struct ShadowPush { glm::mat4 lightSpaceMatrix; glm::mat4 model; };
|
||||||
|
|
||||||
|
const float shadowRadiusSq = shadowRadius * shadowRadius;
|
||||||
for (const auto& instance : instances) {
|
for (const auto& instance : instances) {
|
||||||
|
// Distance cull against shadow frustum
|
||||||
|
glm::vec3 diff = instance.position - shadowCenter;
|
||||||
|
if (glm::dot(diff, diff) > shadowRadiusSq) continue;
|
||||||
auto modelIt = loadedModels.find(instance.modelId);
|
auto modelIt = loadedModels.find(instance.modelId);
|
||||||
if (modelIt == loadedModels.end()) continue;
|
if (modelIt == loadedModels.end()) continue;
|
||||||
const ModelData& model = modelIt->second;
|
const ModelData& model = modelIt->second;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue