Skip to content

Commit

Permalink
fix disabled shadow inconsistency
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e committed Jul 9, 2024
1 parent 1590096 commit d67a878
Showing 1 changed file with 55 additions and 34 deletions.
89 changes: 55 additions & 34 deletions native/cocos/renderer/pipeline/custom/NativeBuiltinUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,47 +792,24 @@ void setLightUBO(
}
}

const BuiltinCascadedShadowMap *getBuiltinShadowCSM(
const PipelineRuntime &pplRuntime,
const scene::Camera &camera,
const scene::DirectionalLight *mainLight) {
const auto &ppl = dynamic_cast<const NativePipeline &>(pplRuntime);
// no main light
if (!mainLight) {
return nullptr;
}
// not attached to a node
if (!mainLight->getNode()) {
return nullptr;
}
const pipeline::PipelineSceneData &pplSceneData = *pplRuntime.getPipelineSceneData();
auto &csmLayers = *pplSceneData.getCSMLayers();
const auto &shadows = *pplSceneData.getShadows();
// shadow not enabled
if (!shadows.isEnabled()) {
return nullptr;
}
// shadow type is planar
if (shadows.getType() == scene::ShadowType::PLANAR) {
return nullptr;
}

// find csm
const BuiltinCascadedShadowMapKey key{&camera, mainLight};
auto iter = ppl.builtinCSMs.find(key);
if (iter != ppl.builtinCSMs.end()) {
return &iter->second;
}
namespace {

const BuiltinCascadedShadowMap *addBuiltinCSMInfo(
const NativePipeline &ppl,
const pipeline::PipelineSceneData &pplSceneData,
const scene::Camera &camera,
const scene::DirectionalLight *mainLight,
const BuiltinCascadedShadowMapKey &key,
pipeline::CSMLayers& csmLayers) {
// add new csm info
bool added = false;
std::tie(iter, added) = ppl.builtinCSMs.emplace(
auto res = ppl.builtinCSMs.emplace(
std::piecewise_construct,
std::forward_as_tuple(key),
std::forward_as_tuple());
CC_ENSURES(added);
CC_ENSURES(res.second);

auto &csm = iter->second;
auto &csm = res.first->second;

// update csm layers
csmLayers.update(&pplSceneData, &camera);
Expand Down Expand Up @@ -873,6 +850,50 @@ const BuiltinCascadedShadowMap *getBuiltinShadowCSM(
return &csm;
}

} // namespace

const BuiltinCascadedShadowMap *getBuiltinShadowCSM(
const PipelineRuntime &pplRuntime,
const scene::Camera &camera,
const scene::DirectionalLight *mainLight) {
const auto &ppl = dynamic_cast<const NativePipeline &>(pplRuntime);
// no main light
if (!mainLight) {
return nullptr;
}
// not attached to a node
if (!mainLight->getNode()) {
return nullptr;
}
const pipeline::PipelineSceneData &pplSceneData = *pplRuntime.getPipelineSceneData();
auto &csmLayers = *pplSceneData.getCSMLayers();
const auto &shadows = *pplSceneData.getShadows();

const BuiltinCascadedShadowMap *result = nullptr;

{ // find or create csm info
const BuiltinCascadedShadowMapKey key{&camera, mainLight};
auto iter = ppl.builtinCSMs.find(key);
if (iter != ppl.builtinCSMs.end()) {
result = &iter->second;
} else {
result = addBuiltinCSMInfo(ppl, pplSceneData, camera, mainLight, key, csmLayers);
}
}
CC_ENSURES(result);

// shadow not enabled
if (!shadows.isEnabled()) {
return nullptr;
}
// shadow type is planar
if (shadows.getType() == scene::ShadowType::PLANAR) {
return nullptr;
}

return result;
}

const geometry::Frustum &getBuiltinShadowFrustum(
const PipelineRuntime &pplRuntime,
const scene::Camera &camera,
Expand Down

0 comments on commit d67a878

Please sign in to comment.