From 7b563e6ecf8135429241bfdf594b0516db97287e Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Tue, 9 Jul 2024 16:05:09 +0800 Subject: [PATCH] fix disabled shadow inconsistency (#17337) --- .../pipeline/custom/NativeBuiltinUtils.cpp | 11 +++++------ .../pipeline/custom/NativeBuiltinUtils.h | 2 +- .../pipeline/custom/NativeSceneCulling.cpp | 18 ++++++++++-------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp b/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp index dd39e58dbc7..51bc57f3c25 100644 --- a/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp @@ -30,7 +30,6 @@ #include "cocos/renderer/pipeline/PipelineSceneData.h" #include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h" #include "cocos/renderer/pipeline/custom/NativePipelineTypes.h" -#include "cocos/renderer/pipeline/custom/NativeTypes.h" #include "cocos/renderer/pipeline/custom/NativeUtils.h" #include "cocos/renderer/pipeline/custom/RenderGraphTypes.h" #include "cocos/renderer/pipeline/custom/details/GslUtils.h" @@ -873,7 +872,7 @@ const BuiltinCascadedShadowMap *getBuiltinShadowCSM( return &csm; } -const geometry::Frustum &getBuiltinShadowFrustum( +const geometry::Frustum *getBuiltinShadowFrustum( const PipelineRuntime &pplRuntime, const scene::Camera &camera, const scene::DirectionalLight *mainLight, @@ -882,22 +881,22 @@ const geometry::Frustum &getBuiltinShadowFrustum( const auto &shadows = *ppl.pipelineSceneData->getShadows(); if (shadows.getType() == scene::ShadowType::PLANAR) { - return camera.getFrustum(); + return &camera.getFrustum(); } BuiltinCascadedShadowMapKey key{&camera, mainLight}; auto iter = ppl.builtinCSMs.find(key); if (iter == ppl.builtinCSMs.end()) { - throw std::runtime_error("Builtin shadow CSM not found"); + return nullptr; } const auto &csmLevel = mainLight->getCSMLevel(); const auto &csm = iter->second; if (mainLight->isShadowFixedArea() || csmLevel == scene::CSMLevel::LEVEL_1) { - return csm.specialLayer.validFrustum; + return &csm.specialLayer.validFrustum; } - return csm.layers[level].validFrustum; + return &csm.layers[level].validFrustum; } } // namespace render diff --git a/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.h b/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.h index 9c74502dfaa..553ea2af62a 100644 --- a/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.h +++ b/native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.h @@ -111,7 +111,7 @@ const BuiltinCascadedShadowMap *getBuiltinShadowCSM( const scene::Camera &camera, const scene::DirectionalLight *mainLight); -const geometry::Frustum &getBuiltinShadowFrustum( +const geometry::Frustum *getBuiltinShadowFrustum( const PipelineRuntime &pplRuntime, const scene::Camera &camera, const scene::DirectionalLight *mainLight, diff --git a/native/cocos/renderer/pipeline/custom/NativeSceneCulling.cpp b/native/cocos/renderer/pipeline/custom/NativeSceneCulling.cpp index e0cc23e39b8..223112452f3 100644 --- a/native/cocos/renderer/pipeline/custom/NativeSceneCulling.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeSceneCulling.cpp @@ -345,14 +345,16 @@ void SceneCulling::batchFrustumCulling(const NativePipeline& ppl) { break; case scene::LightType::DIRECTIONAL: { const auto* mainLight = dynamic_cast(light); - const auto& frustum = getBuiltinShadowFrustum(ppl, camera, mainLight, level); - sceneCulling( - skyboxModel, - *scene, camera, - frustum, - bCastShadow, - nullptr, - models); + const auto* frustum = getBuiltinShadowFrustum(ppl, camera, mainLight, level); + if (frustum) { + sceneCulling( + skyboxModel, + *scene, camera, + *frustum, + bCastShadow, + nullptr, + models); + } } break; default: // noop