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

LensFlare: initialize OGRE compositors during plugin initialization #2764

Merged
merged 3 commits into from
Jun 27, 2020
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
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