Skip to content

Commit

Permalink
LensFlare: initialize OGRE compositors during plugin initialization (#…
Browse files Browse the repository at this point in the history
…2764)

Initialize OGRE compositors in SetCamera() instead of Update()
so the compositor order can be better controlled.

Add #2754 and #2762 to changelog.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
  • Loading branch information
scpeters authored Jun 27, 2020
1 parent 7318ed2 commit 378310a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
11 changes: 10 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
## Gazebo 9

## Gazebo 9.xx.x (202x-xx-xx)

1. LensFlare: initialize OGRE compositors during plugin initialization
* [Pull request #2762](https://github.com/osrf/gazebo/pull/2762)

1. Fixes for ARM: FindSSE, TrackedVehiclePlugin and PluginInterfaceTest
* [Pull request #2754](https://github.com/osrf/gazebo/pull/2754)
* [Pull request #2748](https://github.com/osrf/gazebo/pull/2748)

## Gazebo 9.13.1 (2020-05-28)

1. Fix multiple reflectance maps and improve performance
* [Pull request #2724](https://github.com/osrf/gazebo/pull/2742)
* [Pull request #2742](https://github.com/osrf/gazebo/pull/2742)

## Gazebo 9.13.0 (2020-04-03)

Expand Down
63 changes: 34 additions & 29 deletions gazebo/rendering/LensFlare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ namespace gazebo
public: virtual void notifyMaterialRender(unsigned int _passId,
Ogre::MaterialPtr &_mat)
{
if (!this->light)
{
// return if this->light is not set, we may still be initializing
return;
}

GZ_ASSERT(!_mat.isNull(), "Null OGRE material");
// These calls are setting parameters that are declared in two places:
// 1. media/materials/scripts/gazebo.material, in
Expand Down Expand Up @@ -393,6 +399,32 @@ void LensFlare::SetCamera(CameraPtr _camera)
}

this->dataPtr->camera = _camera;

if (!this->dataPtr->lensFlareInstance)
{
// set up the lens flare instance
Ogre::MaterialPtr lensFlareMaterial =
Ogre::MaterialManager::getSingleton().getByName(
"Gazebo/CameraLensFlare");
lensFlareMaterial = lensFlareMaterial->clone(
"Gazebo/" + this->dataPtr->camera->Name() + "_CameraLensFlare");

this->dataPtr->lensFlareCompositorListener.reset(new
LensFlareCompositorListener(this->dataPtr->camera, nullptr));
this->dataPtr->lensFlareCompositorListener->SetScale(
this->dataPtr->lensFlareScale);

this->dataPtr->lensFlareInstance =
Ogre::CompositorManager::getSingleton().addCompositor(
this->dataPtr->camera->OgreViewport(), "CameraLensFlare/Default");
this->dataPtr->lensFlareInstance->getTechnique()->getOutputTargetPass()->
getPass(0)->setMaterial(lensFlareMaterial);

this->dataPtr->lensFlareInstance->setEnabled(true);
this->dataPtr->lensFlareInstance->addListener(
this->dataPtr->lensFlareCompositorListener.get());
}

this->dataPtr->preRenderConnection = event::Events::ConnectPreRender(
std::bind(&LensFlare::Update, this));
}
Expand Down Expand Up @@ -440,35 +472,8 @@ void LensFlare::Update()

this->dataPtr->lightName = directionalLight->Name();

if (!this->dataPtr->lensFlareInstance)
{
// set up the lens flare instance
Ogre::MaterialPtr lensFlareMaterial =
Ogre::MaterialManager::getSingleton().getByName(
"Gazebo/CameraLensFlare");
lensFlareMaterial = lensFlareMaterial->clone(
"Gazebo/" + this->dataPtr->camera->Name() + "_CameraLensFlare");

this->dataPtr->lensFlareCompositorListener.reset(new
LensFlareCompositorListener(this->dataPtr->camera, directionalLight));
this->dataPtr->lensFlareCompositorListener->SetScale(
this->dataPtr->lensFlareScale);

this->dataPtr->lensFlareInstance =
Ogre::CompositorManager::getSingleton().addCompositor(
this->dataPtr->camera->OgreViewport(), "CameraLensFlare/Default");
this->dataPtr->lensFlareInstance->getTechnique()->getOutputTargetPass()->
getPass(0)->setMaterial(lensFlareMaterial);

this->dataPtr->lensFlareInstance->setEnabled(true);
this->dataPtr->lensFlareInstance->addListener(
this->dataPtr->lensFlareCompositorListener.get());
}
else
{
this->dataPtr->lensFlareCompositorListener->SetLight(directionalLight);
this->dataPtr->lensFlareInstance->setEnabled(true);
}
this->dataPtr->lensFlareCompositorListener->SetLight(directionalLight);
this->dataPtr->lensFlareInstance->setEnabled(true);

// disconnect
this->dataPtr->preRenderConnection.reset();
Expand Down

0 comments on commit 378310a

Please sign in to comment.