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

Skip particle passes in Ogre2DepthCamera if there are no particles in the scene #971

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Changes from all 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
103 changes: 66 additions & 37 deletions ogre2/src/Ogre2DepthCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@
/// improvement.
public: const uint8_t kDepthExecutionMask = 0xEF;

/// \brief Pointer to the color target in the workspace
public: Ogre::CompositorTargetDef *colorTarget{nullptr};
/// \brief Pointer to the color target definition in the workspace
public: Ogre::CompositorTargetDef *colorTargetDef{nullptr};

/// \brief Pointer to the particle target definition in the workspace
public: Ogre::CompositorTargetDef *particleTargetDef{nullptr};
};

using namespace gz;
Expand Down Expand Up @@ -340,7 +342,8 @@
{
ogreCompMgr->removeWorkspace(
this->dataPtr->ogreCompositorWorkspace);
this->dataPtr->colorTarget = nullptr;
this->dataPtr->colorTargetDef = nullptr;
this->dataPtr->particleTargetDef = nullptr;
}

if (this->dataPtr->depthMaterial)
Expand Down Expand Up @@ -728,24 +731,24 @@
rtvParticleTexture->depthAttachment.textureName = "particleDepthTexture";

baseNodeDef->setNumTargetPass(4);
Ogre::CompositorTargetDef *colorTargetDef =
this->dataPtr->colorTargetDef =
baseNodeDef->addTargetPass("colorTexture");
if (validBackground)
colorTargetDef->setNumPasses(4);
this->dataPtr->colorTargetDef->setNumPasses(4);

Check warning on line 737 in ogre2/src/Ogre2DepthCamera.cc

View check run for this annotation

Codecov / codecov/patch

ogre2/src/Ogre2DepthCamera.cc#L737

Added line #L737 was not covered by tests
else
colorTargetDef->setNumPasses(3);
this->dataPtr->colorTargetDef->setNumPasses(3);
{
// clear pass
Ogre::CompositorPassSceneDef *passClear =
static_cast<Ogre::CompositorPassSceneDef *>(
colorTargetDef->addPass(Ogre::PASS_CLEAR));
Ogre::CompositorPassClearDef *passClear =
static_cast<Ogre::CompositorPassClearDef *>(
this->dataPtr->colorTargetDef->addPass(Ogre::PASS_CLEAR));
passClear->mExecutionMask = this->dataPtr->kDepthExecutionMask;

// scene pass - opaque
{
Ogre::CompositorPassSceneDef *passScene =
static_cast<Ogre::CompositorPassSceneDef *>(
colorTargetDef->addPass(Ogre::PASS_SCENE));
this->dataPtr->colorTargetDef->addPass(Ogre::PASS_SCENE));
passScene->mShadowNode = this->dataPtr->kShadowNodeName;
passScene->setVisibilityMask(GZ_VISIBILITY_ALL);
passScene->mIncludeOverlays = false;
Expand Down Expand Up @@ -773,7 +776,7 @@
// quad pass
Ogre::CompositorPassQuadDef *passQuad =
static_cast<Ogre::CompositorPassQuadDef *>(
colorTargetDef->addPass(Ogre::PASS_QUAD));
this->dataPtr->colorTargetDef->addPass(Ogre::PASS_QUAD));

Check warning on line 779 in ogre2/src/Ogre2DepthCamera.cc

View check run for this annotation

Codecov / codecov/patch

ogre2/src/Ogre2DepthCamera.cc#L779

Added line #L779 was not covered by tests
passQuad->mMaterialName = this->dataPtr->kSkyboxMaterialName + "_"
+ this->Name();
passQuad->mFrustumCorners =
Expand All @@ -785,7 +788,7 @@
{
Ogre::CompositorPassSceneDef *passScene =
static_cast<Ogre::CompositorPassSceneDef *>(
colorTargetDef->addPass(Ogre::PASS_SCENE));
this->dataPtr->colorTargetDef->addPass(Ogre::PASS_SCENE));
passScene->setVisibilityMask(GZ_VISIBILITY_ALL);
// todo(anyone) PbsMaterialsShadowNode is hardcoded.
// Although this may be just fine
Expand Down Expand Up @@ -815,20 +818,29 @@
passScene->setLightVisibilityMask(0x0);
}

Ogre::CompositorTargetDef *particleTargetDef =
// Ogre::CompositorTargetDef *particleTargetDef =
this->dataPtr->particleTargetDef =
baseNodeDef->addTargetPass("particleTexture");
particleTargetDef->setNumPasses(1);
this->dataPtr->particleTargetDef->setNumPasses(2);
{
// clear pass
Ogre::CompositorPassClearDef *passClear =
static_cast<Ogre::CompositorPassClearDef *>(
this->dataPtr->particleTargetDef->addPass(Ogre::PASS_CLEAR));
passClear->setAllClearColours(Ogre::ColourValue::Black);
passClear->mExecutionMask = this->dataPtr->kDepthExecutionMask;

// scene pass
Ogre::CompositorPassSceneDef *passScene =
static_cast<Ogre::CompositorPassSceneDef *>(
particleTargetDef->addPass(Ogre::PASS_SCENE));
this->dataPtr->particleTargetDef->addPass(Ogre::PASS_SCENE));
passScene->setAllLoadActions(Ogre::LoadAction::Clear);
passScene->setAllClearColours(Ogre::ColourValue::Black);
passScene->setVisibilityMask(
Ogre2ParticleEmitter::kParticleVisibilityFlags);
passScene->mEnableForwardPlus = false;
passScene->setLightVisibilityMask(0x0);
passScene->mExecutionMask = ~this->dataPtr->kDepthExecutionMask;
}

// rt0 target - converts depth to xyz
Expand Down Expand Up @@ -1044,32 +1056,49 @@
if (!this->dataPtr->ogreCompositorWorkspace)
this->CreateWorkspaceInstance();

if (!this->dataPtr->colorTarget)

// Disable color target (set to clear pass) if there are no rgb point cloud
// connections
if (this->dataPtr->colorTargetDef)
{
auto engine = Ogre2RenderEngine::Instance();
auto ogreRoot = engine->OgreRoot();
Ogre::CompositorManager2 *ogreCompMgr = ogreRoot->getCompositorManager2();
Ogre::CompositorNodeDef *nodeDef =
ogreCompMgr->getNodeDefinitionNonConst(
this->dataPtr->ogreCompositorBaseNodeDef);
this->dataPtr->colorTarget = nodeDef->getTargetPass(0);
Ogre::CompositorPassDefVec &colorPasses =
this->dataPtr->colorTargetDef->getCompositorPassesNonConst();
GZ_ASSERT(colorPasses.size() > 2u,
"Ogre2DepthCamera color target should contain more than 2 passes");
GZ_ASSERT(colorPasses[0]->getType() == Ogre::PASS_CLEAR,
"Ogre2DepthCamera color target should start with a clear pass");
colorPasses[0]->mExecutionMask =
(this->dataPtr->newRgbPointCloud.ConnectionCount() > 0u) ?
~this->dataPtr->kDepthExecutionMask :this->dataPtr->kDepthExecutionMask;
for (unsigned int i = 1; i < colorPasses.size(); ++i)
{
colorPasses[i]->mExecutionMask =
(this->dataPtr->newRgbPointCloud.ConnectionCount() > 0u) ?
this->dataPtr->kDepthExecutionMask :
~this->dataPtr->kDepthExecutionMask;
}
}

Ogre::CompositorPassDefVec &colorPasses =
this->dataPtr->colorTarget->getCompositorPassesNonConst();
GZ_ASSERT(colorPasses.size() > 2u,
"Ogre2DepthCamera color target should contain more than 2 passes");
GZ_ASSERT(colorPasses[0]->getType() == Ogre::PASS_CLEAR,
"Ogre2DepthCamera color target should start with a clear pass");
colorPasses[0]->mExecutionMask =
(this->dataPtr->newRgbPointCloud.ConnectionCount() > 0u) ?
~this->dataPtr->kDepthExecutionMask :this->dataPtr->kDepthExecutionMask;
for (unsigned int i = 1; i < colorPasses.size(); ++i)
// Disable particle target (set to clear pass) if there are no particles
if (this->dataPtr->particleTargetDef)
{
colorPasses[i]->mExecutionMask =
(this->dataPtr->newRgbPointCloud.ConnectionCount() > 0u) ?
this->dataPtr->kDepthExecutionMask :
~this->dataPtr->kDepthExecutionMask;
bool hasParticles =
this->scene->OgreSceneManager()->getMovableObjectIterator(
Ogre::ParticleSystemFactory::FACTORY_TYPE_NAME).hasMoreElements();
Ogre::CompositorPassDefVec &particlePasses =
this->dataPtr->particleTargetDef->getCompositorPassesNonConst();
GZ_ASSERT(particlePasses.size() == 2u,
"Ogre2DepthCamera particle target should 2 passes");
GZ_ASSERT(particlePasses[0]->getType() == Ogre::PASS_CLEAR,
"Ogre2DepthCamera particle target should start with a clear pass");
GZ_ASSERT(particlePasses[1]->getType() == Ogre::PASS_SCENE,
"Ogre2DepthCamera particle target should end with a scene pass");
particlePasses[0]->mExecutionMask =
(hasParticles) ? ~this->dataPtr->kDepthExecutionMask :
this->dataPtr->kDepthExecutionMask;
particlePasses[1]->mExecutionMask =
(hasParticles) ? this->dataPtr->kDepthExecutionMask :
~this->dataPtr->kDepthExecutionMask;
}

// update depth camera render passes
Expand Down