Skip to content

Commit

Permalink
fix disabled shadow inconsistency (#17337)
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e authored Jul 9, 2024
1 parent 1aa1e56 commit 7b563e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
11 changes: 5 additions & 6 deletions native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 10 additions & 8 deletions native/cocos/renderer/pipeline/custom/NativeSceneCulling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,16 @@ void SceneCulling::batchFrustumCulling(const NativePipeline& ppl) {
break;
case scene::LightType::DIRECTIONAL: {
const auto* mainLight = dynamic_cast<const scene::DirectionalLight*>(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
Expand Down

0 comments on commit 7b563e6

Please sign in to comment.