Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
LensFlare: param for number of occlusion steps
Browse files Browse the repository at this point in the history
There is a significant amount of CPU time taken
when checking for occlusions in the LensFlare
compositor listener. This exposes the number
of steps taken when checking occlusions to allow
users to attempt to speed up this process.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
  • Loading branch information
scpeters committed Jun 10, 2022
1 parent e2849f9 commit 45bac85
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
21 changes: 20 additions & 1 deletion gazebo/rendering/LensFlare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ namespace gazebo
/// \brief Color of lens flare.
public: ignition::math::Vector3d color
= ignition::math::Vector3d(1.0, 1.0, 1.0);

/// \brief Number of steps to take in each direction when checking for
/// occlusion.
public: double occlusionSteps = 10;
};

//////////////////////////////////////////////////
Expand Down Expand Up @@ -95,6 +99,13 @@ namespace gazebo
this->dataPtr->color = _color;
}

//////////////////////////////////////////////////
void LensFlareCompositorListener::SetOcclusionSteps(
double _occlusionSteps)
{
this->dataPtr->occlusionSteps = _occlusionSteps;
}

//////////////////////////////////////////////////
void LensFlareCompositorListener::notifyMaterialRender(unsigned int _passId,
Ogre::MaterialPtr &_mat)
Expand Down Expand Up @@ -313,7 +324,7 @@ namespace gazebo
// work in normalized device coordinates
// lens flare's halfSize is just an approximated value
double halfSize = 0.05 * this->dataPtr->scale;
double steps = 10;
double steps = this->dataPtr->occlusionSteps;
double stepSize = halfSize * 2 / steps;
double cx = _imgPos.X();
double cy = _imgPos.Y();
Expand Down Expand Up @@ -423,6 +434,8 @@ void LensFlare::SetCamera(CameraPtr _camera)
this->dataPtr->lensFlareScale);
this->dataPtr->lensFlareCompositorListener->SetColor(
this->dataPtr->lensFlareColor);
this->dataPtr->lensFlareCompositorListener->SetOcclusionSteps(
this->dataPtr->lensFlareColor);

This comment has been minimized.

Copy link
@mallanmba

mallanmba Jun 10, 2022

Contributor

shouldn't this be this->dataPtr->occlusionSteps?


this->dataPtr->lensFlareInstance =
Ogre::CompositorManager::getSingleton().addCompositor(
Expand Down Expand Up @@ -463,6 +476,12 @@ void LensFlare::SetColor(const ignition::math::Vector3d &_color)
}
}

//////////////////////////////////////////////////
void LensFlare::SetOcclusionSteps(double _occlusionSteps)
{
this->dataPtr->occlusionSteps = _occlusionSteps;
}

//////////////////////////////////////////////////
void LensFlare::SetCompositorName(const std::string &_name)
{
Expand Down
6 changes: 6 additions & 0 deletions gazebo/rendering/LensFlare.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ namespace gazebo
/// \param[in] _color Color of lens flare
public: void SetColor(const ignition::math::Vector3d &_color);

/// \brief Set the number of steps to take in each direction when
/// checking for occlusions.
/// \param[in] _occlusionSteps number of steps to take in each direction
/// when checking for occlusion.
public: void SetOcclusionSteps(double _occlusionSteps);

/// \brief Callback that OGRE will invoke for us on each render call
/// \param[in] _passID OGRE material pass ID.
/// \param[in] _mat Pointer to OGRE material.
Expand Down
20 changes: 20 additions & 0 deletions plugins/LensFlareSensorPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ namespace gazebo
public: ignition::math::Vector3d color
= ignition::math::Vector3d(1.4, 1.2, 1.0);

/// \brief Lens flare occlusion steps
public: double occlusionSteps = 10;

/// \brief Lens flare compositor name
public: std::string compositorName;
};
Expand Down Expand Up @@ -87,6 +90,11 @@ void LensFlareSensorPlugin::Load(sensors::SensorPtr _sensor,
this->dataPtr->color = _sdf->Get<ignition::math::Vector3d>("color");
}

if (_sdf->HasElement("occlusion_steps"))
{
this->dataPtr->occlusionSteps = _sdf->Get<double>("occlusion_steps");
}

const std::string compositorName = "compositor";
if (_sdf->HasElement(compositorName))
{
Expand Down Expand Up @@ -141,6 +149,17 @@ void LensFlareSensorPlugin::SetColor(const ignition::math::Vector3d &_color)
}
}

/////////////////////////////////////////////////
void LensFlareSensorPlugin::SetOcclusionSteps(double _occlusionSteps)
{
this->dataPtr->occlusionSteps = _occlusionSteps;

for (auto flare : this->dataPtr->lensFlares)
{
flare->SetOcclusionSteps(occlusionSteps);
}
}

/////////////////////////////////////////////////
void LensFlareSensorPlugin::AddLensFlare(rendering::CameraPtr _camera)
{
Expand All @@ -156,5 +175,6 @@ void LensFlareSensorPlugin::AddLensFlare(rendering::CameraPtr _camera)
lensFlare->SetCamera(_camera);
lensFlare->SetScale(this->dataPtr->scale);
lensFlare->SetColor(this->dataPtr->color);
lensFlare->SetOcclusionSteps(this->dataPtr->occlusionSteps);
this->dataPtr->lensFlares.push_back(lensFlare);
}

0 comments on commit 45bac85

Please sign in to comment.