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

LensFlare: parameterize number of occlusion steps #3234

Merged
merged 7 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
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
24 changes: 23 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.0;
};

//////////////////////////////////////////////////
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 @@ -356,6 +367,9 @@ namespace gazebo
public: ignition::math::Vector3d lensFlareColor
= ignition::math::Vector3d(1.0, 1.0, 1.0);

/// \brief Color of lens flare.
public: double lensFlareOcclusionSteps = 10.0;

/// \brief Compositor name to be used for lens flare
public: std::string compositorName = "CameraLensFlare/Default";

Expand Down Expand Up @@ -423,6 +437,8 @@ void LensFlare::SetCamera(CameraPtr _camera)
this->dataPtr->lensFlareScale);
this->dataPtr->lensFlareCompositorListener->SetColor(
this->dataPtr->lensFlareColor);
this->dataPtr->lensFlareCompositorListener->SetOcclusionSteps(
this->dataPtr->lensFlareOcclusionSteps);

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

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

//////////////////////////////////////////////////
void LensFlare::SetCompositorName(const std::string &_name)
{
Expand Down
12 changes: 12 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 Expand Up @@ -123,6 +129,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 Set the name of the lens flare compositor to use the next
/// time SetCamera is called.
/// \param[in] _name Name of the compositor to use
Expand Down
23 changes: 22 additions & 1 deletion 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.0;

/// \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 @@ -153,8 +172,10 @@ void LensFlareSensorPlugin::AddLensFlare(rendering::CameraPtr _camera)
{
lensFlare->SetCompositorName(this->dataPtr->compositorName);
}
lensFlare->SetCamera(_camera);
lensFlare->SetScale(this->dataPtr->scale);
lensFlare->SetColor(this->dataPtr->color);
lensFlare->SetOcclusionSteps(this->dataPtr->occlusionSteps);
// SetCamera must be called last
lensFlare->SetCamera(_camera);
this->dataPtr->lensFlares.push_back(lensFlare);
}
13 changes: 10 additions & 3 deletions plugins/LensFlareSensorPlugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ namespace gazebo
/// \brief Plugin that adds lens flare effect to a camera or multicamera
/// sensor
/// The plugin has the following optional parameter:
/// <compositor> Name of the lens flare compositor to use.
/// <scale> Scale of lens flare. Must be greater than 0
/// <color> Color of lens flare.
/// <color> Color of lens flare.
/// <compositor> Name of the lens flare compositor to use.
/// <occlusion_steps> Number of steps used when checking for occlusions.
/// <scale> Scale of lens flare. Must be greater than 0.
/// \todo A potentially useful feature would be an option for constantly
/// updating the flare color to match the light source color.
class GZ_PLUGIN_VISIBLE LensFlareSensorPlugin : public SensorPlugin
Expand All @@ -53,6 +54,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 Add lens flare effect to a camera
/// \param[in] _camera Camera to add the lens flare effect to.
private: void AddLensFlare(rendering::CameraPtr _camera);
Expand Down