mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +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
|
|
@ -2607,11 +2607,13 @@ bool M2Renderer::initializeShadow(VkRenderPass shadowRenderPass) {
|
|||
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 (instances.empty() || models.empty()) return;
|
||||
|
||||
struct ShadowPush { glm::mat4 lightSpaceMatrix; glm::mat4 model; };
|
||||
const float shadowRadiusSq = shadowRadius * shadowRadius;
|
||||
|
||||
// Helper lambda to draw instances with a given foliageSway setting
|
||||
auto drawPass = [&](bool foliagePass) {
|
||||
|
|
@ -2641,6 +2643,10 @@ void M2Renderer::renderShadow(VkCommandBuffer cmd, const glm::mat4& lightSpaceMa
|
|||
const M2ModelGPU* currentModel = nullptr;
|
||||
|
||||
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);
|
||||
if (modelIt == models.end()) continue;
|
||||
const M2ModelGPU& model = modelIt->second;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue