59
59
#include < Compositor/Pass/PassScene/OgreCompositorPassSceneDef.h>
60
60
#include < OgreDepthBuffer.h>
61
61
#include < OgreImage2.h>
62
+ #include < OgreParticleSystemManager.h>
62
63
#include < OgreRoot.h>
63
64
#include < OgreSceneManager.h>
64
65
#include < OgreTechnique.h>
@@ -183,9 +184,11 @@ class gz::rendering::Ogre2DepthCameraPrivate
183
184
// / improvement.
184
185
public: const uint8_t kDepthExecutionMask = 0xEF ;
185
186
186
- // / \brief Pointer to the color target in the workspace
187
- public: Ogre::CompositorTargetDef *colorTarget {nullptr };
187
+ // / \brief Pointer to the color target definition in the workspace
188
+ public: Ogre::CompositorTargetDef *colorTargetDef {nullptr };
188
189
190
+ // / \brief Pointer to the particle target definition in the workspace
191
+ public: Ogre::CompositorTargetDef *particleTargetDef{nullptr };
189
192
};
190
193
191
194
using namespace gz ;
@@ -351,7 +354,8 @@ void Ogre2DepthCamera::Destroy()
351
354
{
352
355
ogreCompMgr->removeWorkspace (
353
356
this ->dataPtr ->ogreCompositorWorkspace );
354
- this ->dataPtr ->colorTarget = nullptr ;
357
+ this ->dataPtr ->colorTargetDef = nullptr ;
358
+ this ->dataPtr ->particleTargetDef = nullptr ;
355
359
}
356
360
357
361
if (this ->dataPtr ->depthMaterial )
@@ -735,25 +739,25 @@ void Ogre2DepthCamera::CreateDepthTexture()
735
739
rtvParticleTexture->depthAttachment .textureName = " particleDepthTexture" ;
736
740
737
741
baseNodeDef->setNumTargetPass (4 );
738
- Ogre::CompositorTargetDef * colorTargetDef =
742
+ this -> dataPtr -> colorTargetDef =
739
743
baseNodeDef->addTargetPass (" colorTexture" );
740
744
741
745
if (validBackground)
742
- colorTargetDef->setNumPasses (4 );
746
+ this -> dataPtr -> colorTargetDef ->setNumPasses (4 );
743
747
else
744
- colorTargetDef->setNumPasses (3 );
748
+ this -> dataPtr -> colorTargetDef ->setNumPasses (3 );
745
749
{
746
750
// clear pass
747
- Ogre::CompositorPassSceneDef *passClear =
748
- static_cast <Ogre::CompositorPassSceneDef *>(
749
- colorTargetDef->addPass (Ogre::PASS_CLEAR));
751
+ Ogre::CompositorPassClearDef *passClear =
752
+ static_cast <Ogre::CompositorPassClearDef *>(
753
+ this -> dataPtr -> colorTargetDef ->addPass (Ogre::PASS_CLEAR));
750
754
passClear->mExecutionMask = this ->dataPtr ->kDepthExecutionMask ;
751
755
752
756
// scene pass - opaque
753
757
{
754
758
Ogre::CompositorPassSceneDef *passScene =
755
759
static_cast <Ogre::CompositorPassSceneDef *>(
756
- colorTargetDef->addPass (Ogre::PASS_SCENE));
760
+ this -> dataPtr -> colorTargetDef ->addPass (Ogre::PASS_SCENE));
757
761
passScene->mShadowNode = this ->dataPtr ->kShadowNodeName ;
758
762
passScene->setVisibilityMask (IGN_VISIBILITY_ALL);
759
763
passScene->mIncludeOverlays = false ;
@@ -781,7 +785,7 @@ void Ogre2DepthCamera::CreateDepthTexture()
781
785
// quad pass
782
786
Ogre::CompositorPassQuadDef *passQuad =
783
787
static_cast <Ogre::CompositorPassQuadDef *>(
784
- colorTargetDef->addPass (Ogre::PASS_QUAD));
788
+ this -> dataPtr -> colorTargetDef ->addPass (Ogre::PASS_QUAD));
785
789
passQuad->mMaterialName = this ->dataPtr ->kSkyboxMaterialName + " _"
786
790
+ this ->Name ();
787
791
passQuad->mFrustumCorners =
@@ -793,7 +797,7 @@ void Ogre2DepthCamera::CreateDepthTexture()
793
797
{
794
798
Ogre::CompositorPassSceneDef *passScene =
795
799
static_cast <Ogre::CompositorPassSceneDef *>(
796
- colorTargetDef->addPass (Ogre::PASS_SCENE));
800
+ this -> dataPtr -> colorTargetDef ->addPass (Ogre::PASS_SCENE));
797
801
passScene->setVisibilityMask (IGN_VISIBILITY_ALL);
798
802
// todo(anyone) PbsMaterialsShadowNode is hardcoded.
799
803
// Although this may be just fine
@@ -823,20 +827,29 @@ void Ogre2DepthCamera::CreateDepthTexture()
823
827
passScene->setLightVisibilityMask (0x0 );
824
828
}
825
829
826
- Ogre::CompositorTargetDef *particleTargetDef =
830
+ // Ogre::CompositorTargetDef *particleTargetDef =
831
+ this ->dataPtr ->particleTargetDef =
827
832
baseNodeDef->addTargetPass (" particleTexture" );
828
- particleTargetDef->setNumPasses (1 );
833
+ this -> dataPtr -> particleTargetDef ->setNumPasses (2 );
829
834
{
835
+ // clear pass
836
+ Ogre::CompositorPassClearDef *passClear =
837
+ static_cast <Ogre::CompositorPassClearDef *>(
838
+ this ->dataPtr ->particleTargetDef ->addPass (Ogre::PASS_CLEAR));
839
+ passClear->setAllClearColours (Ogre::ColourValue::Black);
840
+ passClear->mExecutionMask = this ->dataPtr ->kDepthExecutionMask ;
841
+
830
842
// scene pass
831
843
Ogre::CompositorPassSceneDef *passScene =
832
844
static_cast <Ogre::CompositorPassSceneDef *>(
833
- particleTargetDef->addPass (Ogre::PASS_SCENE));
845
+ this -> dataPtr -> particleTargetDef ->addPass (Ogre::PASS_SCENE));
834
846
passScene->setAllLoadActions (Ogre::LoadAction::Clear);
835
847
passScene->setAllClearColours (Ogre::ColourValue::Black);
836
848
passScene->setVisibilityMask (
837
849
Ogre2ParticleEmitter::kParticleVisibilityFlags );
838
850
passScene->mEnableForwardPlus = false ;
839
851
passScene->setLightVisibilityMask (0x0 );
852
+ passScene->mExecutionMask = ~this ->dataPtr ->kDepthExecutionMask ;
840
853
}
841
854
842
855
// rt0 target - converts depth to xyz
@@ -1058,32 +1071,49 @@ void Ogre2DepthCamera::PreRender()
1058
1071
if (!this ->dataPtr ->ogreCompositorWorkspace )
1059
1072
this ->CreateWorkspaceInstance ();
1060
1073
1061
- if (!this ->dataPtr ->colorTarget )
1074
+
1075
+ // Disable color target (set to clear pass) if there are no rgb point cloud
1076
+ // connections
1077
+ if (this ->dataPtr ->colorTargetDef )
1062
1078
{
1063
- auto engine = Ogre2RenderEngine::Instance ();
1064
- auto ogreRoot = engine->OgreRoot ();
1065
- Ogre::CompositorManager2 *ogreCompMgr = ogreRoot->getCompositorManager2 ();
1066
- Ogre::CompositorNodeDef *nodeDef =
1067
- ogreCompMgr->getNodeDefinitionNonConst (
1068
- this ->dataPtr ->ogreCompositorBaseNodeDef );
1069
- this ->dataPtr ->colorTarget = nodeDef->getTargetPass (0 );
1079
+ Ogre::CompositorPassDefVec &colorPasses =
1080
+ this ->dataPtr ->colorTargetDef ->getCompositorPassesNonConst ();
1081
+ IGN_ASSERT (colorPasses.size () > 2u ,
1082
+ " Ogre2DepthCamera color target should contain more than 2 passes" );
1083
+ IGN_ASSERT (colorPasses[0 ]->getType () == Ogre::PASS_CLEAR,
1084
+ " Ogre2DepthCamera color target should start with a clear pass" );
1085
+ colorPasses[0 ]->mExecutionMask =
1086
+ (this ->dataPtr ->newRgbPointCloud .ConnectionCount () > 0u ) ?
1087
+ ~this ->dataPtr ->kDepthExecutionMask :this ->dataPtr ->kDepthExecutionMask ;
1088
+ for (unsigned int i = 1 ; i < colorPasses.size (); ++i)
1089
+ {
1090
+ colorPasses[i]->mExecutionMask =
1091
+ (this ->dataPtr ->newRgbPointCloud .ConnectionCount () > 0u ) ?
1092
+ this ->dataPtr ->kDepthExecutionMask :
1093
+ ~this ->dataPtr ->kDepthExecutionMask ;
1094
+ }
1070
1095
}
1071
1096
1072
- Ogre::CompositorPassDefVec &colorPasses =
1073
- this ->dataPtr ->colorTarget ->getCompositorPassesNonConst ();
1074
- IGN_ASSERT (colorPasses.size () > 2u ,
1075
- " Ogre2DepthCamera color target should contain more than 2 passes" );
1076
- IGN_ASSERT (colorPasses[0 ]->getType () == Ogre::PASS_CLEAR,
1077
- " Ogre2DepthCamera color target should start with a clear pass" );
1078
- colorPasses[0 ]->mExecutionMask =
1079
- (this ->dataPtr ->newRgbPointCloud .ConnectionCount () > 0u ) ?
1080
- ~this ->dataPtr ->kDepthExecutionMask :this ->dataPtr ->kDepthExecutionMask ;
1081
- for (unsigned int i = 1 ; i < colorPasses.size (); ++i)
1097
+ // Disable particle target (set to clear pass) if there are no particles
1098
+ if (this ->dataPtr ->particleTargetDef )
1082
1099
{
1083
- colorPasses[i]->mExecutionMask =
1084
- (this ->dataPtr ->newRgbPointCloud .ConnectionCount () > 0u ) ?
1085
- this ->dataPtr ->kDepthExecutionMask :
1086
- ~this ->dataPtr ->kDepthExecutionMask ;
1100
+ bool hasParticles =
1101
+ this ->scene ->OgreSceneManager ()->getMovableObjectIterator (
1102
+ Ogre::ParticleSystemFactory::FACTORY_TYPE_NAME).hasMoreElements ();
1103
+ Ogre::CompositorPassDefVec &particlePasses =
1104
+ this ->dataPtr ->particleTargetDef ->getCompositorPassesNonConst ();
1105
+ IGN_ASSERT (particlePasses.size () == 2u ,
1106
+ " Ogre2DepthCamera particle target should 2 passes" );
1107
+ IGN_ASSERT (particlePasses[0 ]->getType () == Ogre::PASS_CLEAR,
1108
+ " Ogre2DepthCamera particle target should start with a clear pass" );
1109
+ IGN_ASSERT (particlePasses[1 ]->getType () == Ogre::PASS_SCENE,
1110
+ " Ogre2DepthCamera particle target should end with a scene pass" );
1111
+ particlePasses[0 ]->mExecutionMask =
1112
+ (hasParticles) ? ~this ->dataPtr ->kDepthExecutionMask :
1113
+ this ->dataPtr ->kDepthExecutionMask ;
1114
+ particlePasses[1 ]->mExecutionMask =
1115
+ (hasParticles) ? this ->dataPtr ->kDepthExecutionMask :
1116
+ ~this ->dataPtr ->kDepthExecutionMask ;
1087
1117
}
1088
1118
1089
1119
// update depth camera render passes
0 commit comments