Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix disabled shadow inconsistency #17337

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 56 additions & 35 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 @@ -792,47 +791,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 +849,51 @@ 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();

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

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);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always insert csm info.

CC_ENSURES(result);

// shadow not enabled
if (!shadows.isEnabled()) {
return nullptr;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also check it as soon as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check shadow not enabled earlier caused the mismatch. When doing the rendering, csm info is always needed.


return result;
}

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