From 7bf2fc0fba8e153c03fc62f0809dd1b3444ea6ea Mon Sep 17 00:00:00 2001 From: troublemaker52025 Date: Thu, 18 Nov 2021 11:18:02 +0800 Subject: [PATCH] merge valid punctual light culling for v3.4.0 (#4048) * merge valid punctual light culling for v3.4.0 --- .../renderer/pipeline/PipelineSceneData.h | 9 ++- .../pipeline/RenderAdditiveLightQueue.cpp | 73 ++++++------------- .../pipeline/RenderAdditiveLightQueue.h | 5 +- .../cocos/renderer/pipeline/SceneCulling.cpp | 33 +++++---- native/cocos/renderer/pipeline/SceneCulling.h | 2 +- .../pipeline/ShadowMapBatchedQueue.cpp | 2 +- .../pipeline/forward/ForwardPipeline.cpp | 7 +- .../renderer/pipeline/shadow/ShadowFlow.cpp | 67 +++++++++++++---- .../renderer/pipeline/shadow/ShadowFlow.h | 2 + 9 files changed, 111 insertions(+), 89 deletions(-) diff --git a/native/cocos/renderer/pipeline/PipelineSceneData.h b/native/cocos/renderer/pipeline/PipelineSceneData.h index 4220780f7b..d8c6f2a8cb 100644 --- a/native/cocos/renderer/pipeline/PipelineSceneData.h +++ b/native/cocos/renderer/pipeline/PipelineSceneData.h @@ -57,6 +57,8 @@ public: inline void setDirShadowObjects(RenderObjectList &&ro) { _dirShadowObjects = std::forward(ro); } inline const RenderObjectList & getCastShadowObjects() const { return _castShadowObjects; } inline void setCastShadowObjects(RenderObjectList &&ro) { _castShadowObjects = std::forward(ro); } + inline const vector & getValidPunctualLights() const { return _validPunctualLights; } + inline void setValidPunctualLights(vector &&validPunctualLights) { _validPunctualLights = std::forward>(validPunctualLights); } inline float getShadowCameraFar() const { return _shadowCameraFar; } inline void setShadowCameraFar(float shadowDistance) { _shadowCameraFar = shadowDistance; } inline Mat4 getMatShadowView() const { return _matShadowView; } @@ -67,9 +69,10 @@ public: inline void setMatShadowViewProj(const Mat4 &matShadowViewProj) { _matShadowViewProj = matShadowViewProj; } private: - RenderObjectList _renderObjects; - RenderObjectList _dirShadowObjects; - RenderObjectList _castShadowObjects; + RenderObjectList _renderObjects; + RenderObjectList _dirShadowObjects; + RenderObjectList _castShadowObjects; + vector _validPunctualLights; scene::PipelineSharedSceneData *_sharedSceneData = nullptr; RenderPipeline * _pipeline = nullptr; diff --git a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp index 7ca7b58f18..b8b794874a 100644 --- a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp +++ b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp @@ -39,7 +39,6 @@ #include "forward/ForwardPipeline.h" #include "gfx-base/GFXDevice.h" #include "scene/RenderScene.h" -#include "scene/Sphere.h" namespace cc { namespace pipeline { @@ -69,14 +68,13 @@ RenderAdditiveLightQueue ::~RenderAdditiveLightQueue() { CC_SAFE_DELETE(_batchedQueue); CC_SAFE_DESTROY(_firstLightBufferView); CC_SAFE_DESTROY(_lightBuffer); - destroy(); } void RenderAdditiveLightQueue::recordCommandBuffer(gfx::Device *device, scene::Camera *camera, gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer) { _instancedQueue->recordCommandBuffer(device, renderPass, cmdBuffer); _batchedQueue->recordCommandBuffer(device, renderPass, cmdBuffer); - bool enableOcclusionQuery = _pipeline->getOcclusionQueryEnabled(); - auto offset = _pipeline->getPipelineUBO()->getCurrentCameraUBOOffset(); + const bool enableOcclusionQuery = _pipeline->getOcclusionQueryEnabled(); + const auto offset = _pipeline->getPipelineUBO()->getCurrentCameraUBOOffset(); for (const auto &lightPass : _lightPasses) { const auto *const subModel = lightPass.subModel; @@ -111,9 +109,9 @@ void RenderAdditiveLightQueue::gatherLightPasses(const scene::Camera *camera, gf clear(); - gatherValidLights(camera); + _validPunctualLights = _pipeline->getPipelineSceneData()->getValidPunctualLights(); - if (_validLights.empty()) return; + if (_validPunctualLights.empty()) return; updateUBOs(camera, cmdBuffer); updateLightDescriptorSet(camera, cmdBuffer); @@ -146,13 +144,9 @@ void RenderAdditiveLightQueue::gatherLightPasses(const scene::Camera *camera, gf _batchedQueue->uploadBuffers(cmdBuffer); } -void RenderAdditiveLightQueue::destroy() const { -} - void RenderAdditiveLightQueue::clear() { _instancedQueue->clear(); _batchedQueue->clear(); - _validLights.clear(); for (auto lightPass : _lightPasses) { lightPass.dynamicOffsets.clear(); @@ -161,27 +155,6 @@ void RenderAdditiveLightQueue::clear() { _lightPasses.clear(); } -void RenderAdditiveLightQueue::gatherValidLights(const scene::Camera *camera) { - const auto *const scene = camera->scene; - scene::Sphere sphere; - - for (auto *light : scene->getSphereLights()) { - sphere.setCenter(light->getPosition()); - sphere.setRadius(light->getRange()); - if (sphere.sphereFrustum(camera->frustum)) { - _validLights.emplace_back(static_cast(light)); - } - } - - for (auto *light : scene->getSpotLights()) { - sphere.setCenter(light->getPosition()); - sphere.setRadius(light->getRange()); - if (sphere.sphereFrustum(camera->frustum)) { - _validLights.emplace_back(static_cast(light)); - } - } -} - bool RenderAdditiveLightQueue::cullSphereLight(const scene::SphereLight *light, const scene::Model *model) { return model->getWorldBounds() && !model->getWorldBounds()->aabbAabb(light->getAABB()); } @@ -193,14 +166,14 @@ bool RenderAdditiveLightQueue::cullSpotLight(const scene::SpotLight *light, cons void RenderAdditiveLightQueue::addRenderQueue(const scene::Pass *pass, const scene::SubModel *subModel, const scene::Model *model, uint lightPassIdx) { const auto batchingScheme = pass->getBatchingScheme(); if (batchingScheme == scene::BatchingSchemes::INSTANCING) { // instancing - for (auto idx : _lightIndices) { + for (const auto idx : _lightIndices) { auto *buffer = InstancedBuffer::get(subModel->getPass(lightPassIdx), idx); buffer->merge(model, subModel, lightPassIdx); buffer->setDynamicOffset(0, _lightBufferStride * idx); _instancedQueue->add(buffer); } } else if (batchingScheme == scene::BatchingSchemes::VB_MERGING) { // vb-merging - for (auto idx : _lightIndices) { + for (const auto idx : _lightIndices) { auto *buffer = BatchedBuffer::get(subModel->getPass(lightPassIdx), idx); buffer->merge(subModel, lightPassIdx, model); buffer->setDynamicOffset(0, _lightBufferStride * idx); @@ -224,11 +197,11 @@ void RenderAdditiveLightQueue::addRenderQueue(const scene::Pass *pass, const sce } void RenderAdditiveLightQueue::updateUBOs(const scene::Camera *camera, gfx::CommandBuffer *cmdBuffer) { - const auto exposure = camera->exposure; - const auto validLightCount = _validLights.size(); - auto *const sceneData = _pipeline->getPipelineSceneData(); + const auto exposure = camera->exposure; + const auto validLightCount = _validPunctualLights.size(); + const auto *sceneData = _pipeline->getPipelineSceneData(); - auto *const sharedData = sceneData->getSharedData(); + const auto *sharedData = sceneData->getSharedData(); const auto *shadowInfo = sharedData->shadow; size_t offset = 0; if (validLightCount > _lightBufferCount) { @@ -241,10 +214,10 @@ void RenderAdditiveLightQueue::updateUBOs(const scene::Camera *camera, gfx::Comm } for (unsigned l = 0; l < validLightCount; l++, offset += _lightBufferElementCount) { - auto * light = _validLights[l]; + const auto *light = _validPunctualLights[l]; const bool isSpotLight = scene::LightType::SPOT == light->getType(); - const auto *spotLight = isSpotLight ? static_cast(light) : nullptr; - const auto *sphereLight = isSpotLight ? nullptr : static_cast(light); + const auto *spotLight = isSpotLight ? static_cast(light) : nullptr; + const auto *sphereLight = isSpotLight ? nullptr : static_cast(light); auto index = offset + UBOForwardLight::LIGHT_POS_OFFSET; const auto &position = isSpotLight ? spotLight->getPosition() : sphereLight->getPosition(); @@ -269,8 +242,8 @@ void RenderAdditiveLightQueue::updateUBOs(const scene::Camera *camera, gfx::Comm _lightBufferData[index++] = color.z; } - float luminanceHDR = isSpotLight ? spotLight->getLuminanceHDR() : sphereLight->getLuminanceHDR(); - float luminanceLDR = isSpotLight ? spotLight->getLuminanceLDR() : sphereLight->getLuminanceLDR(); + const float luminanceHDR = isSpotLight ? spotLight->getLuminanceHDR() : sphereLight->getLuminanceHDR(); + const float luminanceLDR = isSpotLight ? spotLight->getLuminanceLDR() : sphereLight->getLuminanceLDR(); if (sharedData->isHDR) { _lightBufferData[index] = luminanceHDR * exposure * _lightMeterScale; } else { @@ -303,7 +276,7 @@ void RenderAdditiveLightQueue::updateUBOs(const scene::Camera *camera, gfx::Comm } void RenderAdditiveLightQueue::updateLightDescriptorSet(const scene::Camera *camera, gfx::CommandBuffer *cmdBuffer) { - auto *const sceneData = _pipeline->getPipelineSceneData(); + const auto * sceneData = _pipeline->getPipelineSceneData(); auto * shadowInfo = sceneData->getSharedData()->shadow; const auto *const scene = camera->scene; auto * device = gfx::Device::getInstance(); @@ -312,8 +285,8 @@ void RenderAdditiveLightQueue::updateLightDescriptorSet(const scene::Camera *cam const float packing = hFTexture ? 0.0F : 1.0F; const scene::Light *mainLight = scene->getMainLight(); - for (uint i = 0; i < _validLights.size(); ++i) { - const auto *light = _validLights[i]; + for (uint i = 0; i < _validPunctualLights.size(); ++i) { + const auto *light = _validPunctualLights[i]; auto * descriptorSet = _pipeline->getGlobalDSManager()->getOrCreateDescriptorSet(i); if (!descriptorSet) { continue; @@ -388,7 +361,7 @@ void RenderAdditiveLightQueue::updateLightDescriptorSet(const scene::Camera *cam break; } - const float color[4] = {shadowInfo->color.x, shadowInfo->color.y, shadowInfo->color.z, shadowInfo->color.w}; + float color[4] = {shadowInfo->color.x, shadowInfo->color.y, shadowInfo->color.z, shadowInfo->color.w}; memcpy(_shadowUBO.data() + UBOShadow::SHADOW_COLOR_OFFSET, &color, sizeof(float) * 4); descriptorSet->update(); @@ -401,9 +374,9 @@ bool RenderAdditiveLightQueue::getLightPassIndex(const scene::Model *model, vect lightPassIndices->clear(); bool hasValidLightPass = false; - for (auto *subModel : model->getSubModels()) { + for (const auto *subModel : model->getSubModels()) { int lightPassIndex = 0; - for (auto *pass : subModel->getPasses()) { + for (const auto *pass : subModel->getPasses()) { if (pass->getPhase() == _phaseID) { hasValidLightPass = true; break; @@ -418,8 +391,8 @@ bool RenderAdditiveLightQueue::getLightPassIndex(const scene::Model *model, vect void RenderAdditiveLightQueue::lightCulling(const scene::Model *model) { bool isCulled = false; - for (size_t i = 0; i < _validLights.size(); i++) { - const auto *const light = _validLights[i]; + for (size_t i = 0; i < _validPunctualLights.size(); i++) { + const auto *const light = _validPunctualLights[i]; switch (light->getType()) { case scene::LightType::SPHERE: isCulled = cullSphereLight(static_cast(light), model); diff --git a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.h b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.h index 83e88913ad..283bf90e1e 100644 --- a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.h +++ b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.h @@ -60,25 +60,22 @@ public: void recordCommandBuffer(gfx::Device *device, scene::Camera *camera, gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer); void gatherLightPasses(const scene::Camera *camera, gfx::CommandBuffer *cmdBuffer); - void destroy() const; private: static bool cullSphereLight(const scene::SphereLight *light, const scene::Model *model); static bool cullSpotLight(const scene::SpotLight *light, const scene::Model *model); void clear(); - void gatherValidLights(const scene::Camera *camera); void addRenderQueue(const scene::Pass *pass, const scene::SubModel *subModel, const scene::Model *model, uint lightPassIdx); void updateUBOs(const scene::Camera *camera, gfx::CommandBuffer *cmdBuffer); void updateLightDescriptorSet(const scene::Camera *camera, gfx::CommandBuffer *cmdBuffer); bool getLightPassIndex(const scene::Model *model, vector *lightPassIndices) const; void lightCulling(const scene::Model *model); - gfx::DescriptorSet *getOrCreateDescriptorSet(const scene::Light *light); RenderPipeline * _pipeline = nullptr; vector> _sortedSubModelsArray; vector> _sortedPSOCIArray; - vector _validLights; + vector _validPunctualLights; vector _lightIndices; vector _lightPasses; vector _dynamicOffsets; diff --git a/native/cocos/renderer/pipeline/SceneCulling.cpp b/native/cocos/renderer/pipeline/SceneCulling.cpp index aca920346c..9f4f520183 100644 --- a/native/cocos/renderer/pipeline/SceneCulling.cpp +++ b/native/cocos/renderer/pipeline/SceneCulling.cpp @@ -143,22 +143,30 @@ void updateDirLight(scene::Shadow *shadows, const scene::Light *light, std::arra memcpy(shadowUBO->data() + UBOShadow::SHADOW_COLOR_OFFSET, &color, sizeof(color)); } -void lightCollecting(scene::Camera *camera, std::vector *validLights) { - validLights->clear(); - auto * sphere = CC_NEW(scene::Sphere); - const auto * scene = camera->scene; - const scene::Light *mainLight = scene->getMainLight(); - validLights->emplace_back(mainLight); +void validPunctualLightsCulling(RenderPipeline *pipeline, scene::Camera *camera) { + const auto *const scene = camera->scene; + PipelineSceneData * sceneData = pipeline->getPipelineSceneData(); + vector validPunctualLights = sceneData->getValidPunctualLights(); + validPunctualLights.clear(); - for (auto *spotLight : scene->getSpotLights()) { - sphere->setCenter(spotLight->getPosition()); - sphere->setRadius(spotLight->getRange()); - if (sphere->interset(camera->frustum)) { - validLights->emplace_back(static_cast(spotLight)); + scene::Sphere sphere; + for (auto *light : scene->getSpotLights()) { + sphere.setCenter(light->getPosition()); + sphere.setRadius(light->getRange()); + if (sphere.sphereFrustum(camera->frustum)) { + validPunctualLights.emplace_back(static_cast(light)); } } - CC_SAFE_DELETE(sphere) + for (auto *light : scene->getSphereLights()) { + sphere.setCenter(light->getPosition()); + sphere.setRadius(light->getRange()); + if (sphere.sphereFrustum(camera->frustum)) { + validPunctualLights.emplace_back(static_cast(light)); + } + } + + sceneData->setValidPunctualLights(std::move(validPunctualLights)); } Mat4 getCameraWorldMatrix(const scene::Camera *camera) { @@ -307,7 +315,6 @@ void sceneCulling(RenderPipeline *pipeline, scene::Camera *camera) { } } - scene::AABB ab; RenderObjectList renderObjects; RenderObjectList castShadowObject; diff --git a/native/cocos/renderer/pipeline/SceneCulling.h b/native/cocos/renderer/pipeline/SceneCulling.h index cf8e62f8bb..6292c9c3ee 100644 --- a/native/cocos/renderer/pipeline/SceneCulling.h +++ b/native/cocos/renderer/pipeline/SceneCulling.h @@ -42,7 +42,7 @@ class RenderPipeline; RenderObject genRenderObject(const scene::Model *, const scene::Camera *); void quantizeDirLightShadowCamera(RenderPipeline *pipeline, const scene::Camera *camera, scene::Frustum *out); -void lightCollecting(scene::Camera *, std::vector *); +void validPunctualLightsCulling(RenderPipeline *pipeline, scene::Camera *camera); void sceneCulling(RenderPipeline *, scene::Camera *); void updateSphereLight(scene::Shadow *shadows, const scene::Light *light, std::array *); void updateDirLight(scene::Shadow *shadows, const scene::Light *light, std::array *); diff --git a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp index b4bc23ca9b..95a560112d 100644 --- a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp +++ b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp @@ -67,7 +67,7 @@ void ShadowMapBatchedQueue::gatherLightPasses(gfx::DescriptorSet *globalDS, cons } break; case scene::LightType::SPOT: { - const auto *spotLight = dynamic_cast(light); + const auto *spotLight = static_cast(light); const Mat4 matShadowView = light->getNode()->getWorldMatrix().getInversed(); Mat4 matShadowProj; Mat4::createPerspective(spotLight->getSpotAngle(), spotLight->getAspect(), 0.001F, spotLight->getRange(), &matShadowProj); diff --git a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp index 1387496774..73af4a543e 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp @@ -83,8 +83,8 @@ bool ForwardPipeline::activate(gfx::Swapchain *swapchain) { } void ForwardPipeline::render(const vector &cameras) { - auto *device = gfx::Device::getInstance(); - bool enableOcclusionQuery = getOcclusionQueryEnabled(); + auto * device = gfx::Device::getInstance(); + const bool enableOcclusionQuery = getOcclusionQueryEnabled(); if (enableOcclusionQuery) { device->getQueryPoolResults(_queryPools[0]); } @@ -101,6 +101,7 @@ void ForwardPipeline::render(const vector &cameras) { decideProfilerCamera(cameras); for (auto *camera : cameras) { + validPunctualLightsCulling(this, camera); sceneCulling(this, camera); for (auto *const flow : _flows) { flow->render(camera); @@ -125,7 +126,7 @@ void ForwardPipeline::render(const vector &cameras) { bool ForwardPipeline::activeRenderer(gfx::Swapchain *swapchain) { _commandBuffers.push_back(_device->getCommandBuffer()); _queryPools.push_back(_device->getQueryPool()); - auto *const sharedData = _pipelineSceneData->getSharedData(); + const auto *sharedData = _pipelineSceneData->getSharedData(); gfx::Sampler *const sampler = getGlobalDSManager()->getPointSampler(); diff --git a/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp b/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp index 99116143e1..f792175915 100644 --- a/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp +++ b/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp @@ -33,6 +33,7 @@ #include "gfx-base/GFXFramebuffer.h" #include "gfx-base/GFXRenderPass.h" #include "gfx-base/GFXTexture.h" +#include "scene/RenderScene.h" namespace cc { namespace pipeline { @@ -68,7 +69,7 @@ void ShadowFlow::render(scene::Camera *camera) { auto * shadowInfo = sceneData->getSharedData()->shadow; if (!shadowInfo->enabled || shadowInfo->shadowType != scene::ShadowType::SHADOWMAP) return; - lightCollecting(camera, &_validLights); + lightCollecting(); if (sceneData->getDirShadowObjects().empty() && sceneData->getRenderObjects().empty()) { clearShadowMap(camera); @@ -79,12 +80,25 @@ void ShadowFlow::render(scene::Camera *camera) { resizeShadowMap(&shadowInfo); } - const auto &shadowFramebufferMap = sceneData->getShadowFramebufferMap(); + const auto & shadowFramebufferMap = sceneData->getShadowFramebufferMap(); + const scene::DirectionalLight *mainLight = camera->scene->getMainLight(); + if (mainLight) { + gfx::DescriptorSet *globalDS = _pipeline->getDescriptorSet(); + if (!shadowFramebufferMap.count(mainLight)) { + initShadowFrameBuffer(_pipeline, mainLight); + } + + auto *shadowFrameBuffer = shadowFramebufferMap.at(mainLight); + for (auto *stage : _stages) { + auto *shadowStage = static_cast(stage); + shadowStage->setUsage(globalDS, mainLight, shadowFrameBuffer); + shadowStage->render(camera); + } + } + for (uint l = 0; l < _validLights.size(); ++l) { - const scene::Light *light = _validLights[l]; - const bool isMainLight = light->getType() == scene::LightType::DIRECTIONAL; - gfx::DescriptorSet *globalDS = isMainLight ? _pipeline->getDescriptorSet() - : _pipeline->getGlobalDSManager()->getOrCreateDescriptorSet(l - 1); + const scene::Light *light = _validLights[l]; + gfx::DescriptorSet *globalDS = _pipeline->getGlobalDSManager()->getOrCreateDescriptorSet(l); if (!shadowFramebufferMap.count(light)) { initShadowFrameBuffer(_pipeline, light); @@ -93,21 +107,46 @@ void ShadowFlow::render(scene::Camera *camera) { auto *shadowFrameBuffer = shadowFramebufferMap.at(light); for (auto *stage : _stages) { - auto *shadowStage = dynamic_cast(stage); + auto *shadowStage = static_cast(stage); shadowStage->setUsage(globalDS, light, shadowFrameBuffer); shadowStage->render(camera); } } } +void ShadowFlow::lightCollecting() { + _validLights.clear(); + + const vector validPunctualLights = _pipeline->getPipelineSceneData()->getValidPunctualLights(); + for (const scene::Light *light : validPunctualLights) { + if (light->getType() == scene::LightType::SPOT) { + _validLights.emplace_back(light); + } + } +} + void ShadowFlow::clearShadowMap(scene::Camera *camera) { - const auto *sceneData = _pipeline->getPipelineSceneData(); - const auto &shadowFramebufferMap = sceneData->getShadowFramebufferMap(); + const auto * sceneData = _pipeline->getPipelineSceneData(); + const auto & shadowFramebufferMap = sceneData->getShadowFramebufferMap(); + const scene::DirectionalLight *mainLight = camera->scene->getMainLight(); + + if (mainLight) { + gfx::DescriptorSet *globalDS = _pipeline->getDescriptorSet(); + if (!shadowFramebufferMap.count(mainLight)) { + initShadowFrameBuffer(_pipeline, mainLight); + } + + auto *shadowFrameBuffer = shadowFramebufferMap.at(mainLight); + for (auto *stage : _stages) { + auto *shadowStage = static_cast(stage); + shadowStage->setUsage(globalDS, mainLight, shadowFrameBuffer); + shadowStage->render(camera); + } + } + for (uint l = 0; l < _validLights.size(); ++l) { - const scene::Light *light = _validLights[l]; - const bool isMainLight = light->getType() == scene::LightType::DIRECTIONAL; - gfx::DescriptorSet *globalDS = isMainLight ? _pipeline->getDescriptorSet() - : _pipeline->getGlobalDSManager()->getOrCreateDescriptorSet(l - 1); + const scene::Light *light = _validLights[l]; + gfx::DescriptorSet *globalDS = _pipeline->getGlobalDSManager()->getOrCreateDescriptorSet(l); if (!shadowFramebufferMap.count(light)) { continue; @@ -115,7 +154,7 @@ void ShadowFlow::clearShadowMap(scene::Camera *camera) { auto *shadowFrameBuffer = shadowFramebufferMap.at(light); for (auto *stage : _stages) { - auto *shadowStage = dynamic_cast(stage); + auto *shadowStage = static_cast(stage); shadowStage->setUsage(globalDS, light, shadowFrameBuffer); shadowStage->clearFramebuffer(camera); } diff --git a/native/cocos/renderer/pipeline/shadow/ShadowFlow.h b/native/cocos/renderer/pipeline/shadow/ShadowFlow.h index d91e1519a8..b9b2e61c99 100644 --- a/native/cocos/renderer/pipeline/shadow/ShadowFlow.h +++ b/native/cocos/renderer/pipeline/shadow/ShadowFlow.h @@ -49,6 +49,8 @@ public: void destroy() override; private: + void lightCollecting(); + void clearShadowMap(scene::Camera *camera); void resizeShadowMap(scene::Shadow **shadowInfo);