Skip to content

Commit

Permalink
Skip particle passes in Ogre2DepthCamera if there are no particles in…
Browse files Browse the repository at this point in the history
… the scene (#971)



Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Feb 28, 2024
1 parent dc9fe05 commit b07e79d
Showing 1 changed file with 66 additions and 37 deletions.
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 @@ class gz::rendering::Ogre2DepthCameraPrivate
/// 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 @@ void Ogre2DepthCamera::Destroy()
{
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 @@ void Ogre2DepthCamera::CreateDepthTexture()
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);
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 @@ void Ogre2DepthCamera::CreateDepthTexture()
// quad pass
Ogre::CompositorPassQuadDef *passQuad =
static_cast<Ogre::CompositorPassQuadDef *>(
colorTargetDef->addPass(Ogre::PASS_QUAD));
this->dataPtr->colorTargetDef->addPass(Ogre::PASS_QUAD));
passQuad->mMaterialName = this->dataPtr->kSkyboxMaterialName + "_"
+ this->Name();
passQuad->mFrustumCorners =
Expand All @@ -785,7 +788,7 @@ void Ogre2DepthCamera::CreateDepthTexture()
{
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 @@ void Ogre2DepthCamera::CreateDepthTexture()
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 @@ void Ogre2DepthCamera::PreRender()
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

0 comments on commit b07e79d

Please sign in to comment.