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

Workaround for wrong distortion material applied to some cameras #3136

Merged
Merged
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
16 changes: 14 additions & 2 deletions gazebo/rendering/Distortion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ namespace gazebo
/// \brief Ogre Material that contains the distortion shader
public: Ogre::MaterialPtr distortionMaterial;

/// \brief Ogre Texture that contains the distortion map
public: Ogre::TexturePtr distortionTexture;

/// \brief Connection for the pre render event.
public: event::ConnectionPtr preRenderConnection;

Expand All @@ -91,6 +94,14 @@ namespace gazebo
virtual void notifyMaterialRender(Ogre::uint32 _passId,
Ogre::MaterialPtr& _material)
{
// If more compositors are added to the camera in addition to the
// distortion compositor, an Ogre bug will cause the material for the
// last camera initialized to be used for all cameras. This workaround
// doesn't correct the material used, but it applies the correct texture
// to this active material.
_material->getTechnique(0)->getPass(_passId)->getTextureUnitState(1)->
setTexture(distortionTexture);

// @todo Explore more efficent implementations as it is run every frame
Ogre::GpuProgramParametersSharedPtr params =
_material->getTechnique(0)->getPass(_passId)
Expand Down Expand Up @@ -309,7 +320,7 @@ void Distortion::SetCamera(CameraPtr _camera)

// create the distortion map texture for the distortion instance
std::string texName = _camera->Name() + "_distortionTex";
Ogre::TexturePtr renderTexture =
this->dataPtr->distortionTexture =
Ogre::TextureManager::getSingleton().createManual(
texName,
"General",
Expand All @@ -318,7 +329,8 @@ void Distortion::SetCamera(CameraPtr _camera)
this->dataPtr->distortionTexHeight,
0,
Ogre::PF_FLOAT32_RGB);
Ogre::HardwarePixelBufferSharedPtr pixelBuffer = renderTexture->getBuffer();
Ogre::HardwarePixelBufferSharedPtr pixelBuffer =
this->dataPtr->distortionTexture->getBuffer();

// fill the distortion map, while interpolating to fill dead pixels
pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL);
Expand Down