Skip to content

Commit

Permalink
disable point light shadows, fix test, mutex
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
  • Loading branch information
iche033 committed Jan 14, 2021
1 parent 0eba224 commit 7aa1d35
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
25 changes: 18 additions & 7 deletions gazebo/rendering/Light.cc
Original file line number Diff line number Diff line change
Expand Up @@ -585,19 +585,30 @@ void Light::SetRange(const double _range)
//////////////////////////////////////////////////
void Light::SetCastShadows(const bool _cast)
{
this->dataPtr->light->setCastShadows(_cast);

if (_cast && this->dataPtr->light->getType() !=
Ogre::Light::LT_DIRECTIONAL)
if (this->dataPtr->light->getType() == Ogre::Light::LT_DIRECTIONAL)
{
if (this->dataPtr->shadowCameraSetup.isNull())
// directional light uses PSSM shadow camera and should already be
// configured in RTShaderSystem
this->dataPtr->light->setCastShadows(_cast);
}
else if (this->dataPtr->light->getType() == Ogre::Light::LT_SPOTLIGHT)
{
// use different shadow camera for spot light
this->dataPtr->light->setCastShadows(_cast);
if (_cast && this->dataPtr->shadowCameraSetup.isNull())
{
auto *setup = new Ogre::FocusedShadowCameraSetup();
this->dataPtr->shadowCameraSetup = Ogre::ShadowCameraSetupPtr(setup);
this->dataPtr->shadowCameraSetup =
Ogre::ShadowCameraSetupPtr(new Ogre::FocusedShadowCameraSetup());
this->dataPtr->light->setCustomShadowCameraSetup(
this->dataPtr->shadowCameraSetup);
RTShaderSystem::Instance()->UpdateShadows();
}
RTShaderSystem::Instance()->UpdateShadows();
}
else
{
// todo(anyone) make point light casts shadows
this->dataPtr->light->setCastShadows(false);
}
}

Expand Down
9 changes: 6 additions & 3 deletions gazebo/rendering/RTShaderSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ void RTShaderSystem::DetachViewport(Ogre::Viewport *_viewport, ScenePtr _scene)
void RTShaderSystem::UpdateShaders()
{
// shaders will be updated in the Update call on pre-render event.
std::lock_guard<std::mutex> lock(this->dataPtr->updateMutex);
this->dataPtr->updateShaders = true;
}

Expand Down Expand Up @@ -597,6 +598,7 @@ void RTShaderSystem::Update()
return;
}

std::lock_guard<std::mutex> lock(this->dataPtr->updateMutex);
if (this->dataPtr->updateShadows)
{
for (const auto &scene : this->dataPtr->scenes)
Expand Down Expand Up @@ -689,6 +691,7 @@ double RTShaderSystem::ShadowSplitPadding() const
/////////////////////////////////////////////////
void RTShaderSystem::UpdateShadows()
{
std::lock_guard<std::mutex> lock(this->dataPtr->updateMutex);
this->dataPtr->updateShadows = true;
}

Expand Down Expand Up @@ -742,9 +745,9 @@ void RTShaderSystem::UpdateShadows(ScenePtr _scene)
#endif
sceneMgr->setShadowTextureConfig(0,
this->dataPtr->shadowTextureSize, this->dataPtr->shadowTextureSize,
Ogre::PF_FLOAT32_R, 1);
sceneMgr->setShadowTextureConfig(1, texSize, texSize, Ogre::PF_FLOAT32_R, 2);
sceneMgr->setShadowTextureConfig(2, texSize, texSize, Ogre::PF_FLOAT32_R, 3);
Ogre::PF_FLOAT32_R);
sceneMgr->setShadowTextureConfig(1, texSize, texSize, Ogre::PF_FLOAT32_R);
sceneMgr->setShadowTextureConfig(2, texSize, texSize, Ogre::PF_FLOAT32_R);

#if defined(HAVE_OPENGL)
// Enable shadow map comparison, so shader can use
Expand Down
6 changes: 5 additions & 1 deletion gazebo/rendering/RTShaderSystemPrivate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef _GAZEBO_RTSHADERSYSTEM_PRIVATE_HH_
#define _GAZEBO_RTSHADERSYSTEM_PRIVATE_HH_

#include <mutex>
#include <string>
#include <vector>

Expand Down Expand Up @@ -56,7 +57,7 @@ namespace gazebo
/// \brief Flag to indicate that shaders need to be updated.
public: bool updateShaders;

/// \brief Flag to indicate that shaders need to be updated.
/// \brief Flag to indicate that shadows need to be updated.
public: bool updateShadows = false;

/// \brief Size of the Parallel Split Shadow Map (PSSM) shadow texture
Expand All @@ -82,6 +83,9 @@ namespace gazebo

/// \brief Flag to indicate if normal map should be enabled
public: bool enableNormalMap = true;

/// \brief Mutex to protect shaders and shadows update
public: std::mutex updateMutex;
};
}
}
Expand Down
5 changes: 3 additions & 2 deletions gazebo/rendering/RenderingLight_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ TEST_F(Light_TEST, CastShadows)
msg.set_cast_shadows(true);
spotLight->LoadFromMsg(msg);
EXPECT_EQ(spotLight->LightType(), "spot");
// issue #2083: spot light does not cast shadows
EXPECT_FALSE(spotLight->CastShadows());
// issue #2083: spot light generates shadow maps but they are not currently
// being rendered
EXPECT_TRUE(spotLight->CastShadows());
scene->RemoveLight(spotLight);
spotLight.reset();

Expand Down

0 comments on commit 7aa1d35

Please sign in to comment.