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

Optionally disable "render back faces" for the shadow caster #3117

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
40 changes: 34 additions & 6 deletions gazebo/physics/World.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ void World::Load(sdf::ElementPtr _sdf)
this->dataPtr->shadowCasterMaterialName = "Gazebo/shadow_caster";
}

if (this->dataPtr->sdf->GetElement("scene")->
HasElement("ignition:shadow_caster_render_back_faces"))
{
this->dataPtr->shadowCasterRenderBackFaces =
this->dataPtr->sdf->GetElement("scene")->
Get<bool>("ignition:shadow_caster_render_back_faces");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks fine. I think if we plane to add more shadow params in the future, we can consider adding a <shadows> </shadows> section to group these parameters

else
{
this->dataPtr->shadowCasterRenderBackFaces = 1;
scpeters marked this conversation as resolved.
Show resolved Hide resolved
}
WilliamLewww marked this conversation as resolved.
Show resolved Hide resolved

// The period at which messages are processed
this->dataPtr->processMsgsPeriod = common::Time(0, 200000000);

Expand Down Expand Up @@ -296,12 +308,21 @@ void World::Load(sdf::ElementPtr _sdf)
<< std::endl;
}

std::string shadowCasterService("/shadow_caster_material_name");
if (!this->dataPtr->ignNode.Advertise(shadowCasterService,
&World::ShadowCasterService, this))
std::string shadowCasterMaterialNameService("/shadow_caster_material_name");
if (!this->dataPtr->ignNode.Advertise(shadowCasterMaterialNameService,
&World::ShadowCasterMaterialNameService, this))
{
gzerr << "Error advertising service [" << shadowCasterService << "]"
<< std::endl;
gzerr << "Error advertising service [" <<
shadowCasterMaterialNameService << "]" << std::endl;
}

std::string shadowCasterRenderBackFacesService(
"/shadow_caster_render_back_faces");
if (!this->dataPtr->ignNode.Advertise(shadowCasterRenderBackFacesService,
&World::ShadowCasterRenderBackFacesService, this))
{
gzerr << "Error advertising service [" <<
shadowCasterRenderBackFacesService << "]" << std::endl;
}

// This should come before loading of entities
Expand Down Expand Up @@ -3368,8 +3389,15 @@ bool World::PluginInfoService(const ignition::msgs::StringMsg &_req,
}

//////////////////////////////////////////////////
bool World::ShadowCasterService(ignition::msgs::StringMsg &_res)
bool World::ShadowCasterMaterialNameService(ignition::msgs::StringMsg &_res)
{
_res.set_data(this->dataPtr->shadowCasterMaterialName.c_str());
return true;
}

//////////////////////////////////////////////////
bool World::ShadowCasterRenderBackFacesService(ignition::msgs::Boolean &_res)
{
_res.set_data(this->dataPtr->shadowCasterRenderBackFaces);
return true;
}
12 changes: 11 additions & 1 deletion gazebo/physics/World.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace ignition
{
class Plugin_V;
class StringMsg;
class Boolean;
}
}

Expand Down Expand Up @@ -654,7 +655,16 @@ namespace gazebo
/// \brief Callback for "<this_name>/shadow_caster_material_name" service.
/// \param[out] _response Message containing shadow caster material name
/// \return True if the info was successfully obtained.
private: bool ShadowCasterService(ignition::msgs::StringMsg &_response);
private: bool ShadowCasterMaterialNameService(
ignition::msgs::StringMsg &_response);

/// \brief Callback for "<this_name>/shadow_caster_render_back_faces"
/// service.
/// \param[out] _response Message containing shadow caster render back
/// faces
/// \return True if the info was successfully obtained.
private: bool ShadowCasterRenderBackFacesService(
ignition::msgs::Boolean &_response);

/// \internal
/// \brief Private data pointer.
Expand Down
3 changes: 3 additions & 0 deletions gazebo/physics/WorldPrivate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ namespace gazebo

/// \brief Shadow caster material name from scene SDF
public: std::string shadowCasterMaterialName;

/// \brief Shadow caster render back faces from scene SDF
public: bool shadowCasterRenderBackFaces;
scpeters marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion gazebo/rendering/RTShaderSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,8 @@ void RTShaderSystem::UpdateShadows(ScenePtr _scene)
#endif

sceneMgr->setShadowTextureSelfShadow(false);
sceneMgr->setShadowCasterRenderBackFaces(true);
sceneMgr->setShadowCasterRenderBackFaces(
_scene->ShadowCasterRenderBackFaces());

// TODO: We have two different shadow caster materials, both taken from
// OGRE samples. They should be compared and tested.
Expand Down
60 changes: 45 additions & 15 deletions gazebo/rendering/Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,48 @@ Scene::Scene(const std::string &_name, const bool _enableVisualizations,
this->dataPtr->sceneSimTimePosesApplied = common::Time();
this->dataPtr->sceneSimTimePosesReceived = common::Time();

// Get shadow caster material name from physics::World
ignition::transport::Node node;
ignition::msgs::StringMsg rep;
const std::string serviceName = "/shadow_caster_material_name";
bool result;
unsigned int timeout = 5000;
bool executed = node.Request(serviceName,
timeout, rep, result);
if (executed)
{
if (result)
this->dataPtr->shadowCasterMaterialName = rep.data();
{
// Get shadow caster material name from physics::World
ignition::transport::Node node;
ignition::msgs::StringMsg rep;
const std::string serviceName = "/shadow_caster_material_name";
bool result;
unsigned int timeout = 5000;
bool executed = node.Request(serviceName,
timeout, rep, result);
if (executed)
{
if (result)
this->dataPtr->shadowCasterMaterialName = rep.data();
else
gzerr << "Service call[" << serviceName << "] failed" << std::endl;
}
else
gzerr << "Service call[" << serviceName << "] failed" << std::endl;
{
gzerr << "Service call[" << serviceName << "] timed out" << std::endl;
}
}
else

{
gzerr << "Service call[" << serviceName << "] timed out" << std::endl;
// Get shadow caster render back faces from physics::World
ignition::transport::Node node;
ignition::msgs::Boolean rep;
const std::string serviceName = "/shadow_caster_render_back_faces";
bool result;
unsigned int timeout = 5000;
bool executed = node.Request(serviceName,
timeout, rep, result);
if (executed)
{
if (result)
this->dataPtr->shadowCasterRenderBackFaces = rep.data();
else
gzerr << "Service call[" << serviceName << "] failed" << std::endl;
}
else
{
gzerr << "Service call[" << serviceName << "] timed out" << std::endl;
}
}
}

Expand Down Expand Up @@ -3311,6 +3335,12 @@ std::string Scene::ShadowCasterMaterialName() const
return this->dataPtr->shadowCasterMaterialName;
}

/////////////////////////////////////////////////
bool Scene::ShadowCasterRenderBackFaces() const
{
return this->dataPtr->shadowCasterRenderBackFaces;
}

/////////////////////////////////////////////////
void Scene::AddVisual(VisualPtr _vis)
{
Expand Down
4 changes: 4 additions & 0 deletions gazebo/rendering/Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ namespace gazebo
/// \return Name of the shadow caster material
public: std::string ShadowCasterMaterialName() const;

/// \brief Get the shadow caster render back faces
/// \return Shadow caster render back faces
public: bool ShadowCasterRenderBackFaces() const;

/// \brief Add a visual to the scene
/// \param[in] _vis Visual to add.
public: void AddVisual(VisualPtr _vis);
Expand Down
3 changes: 3 additions & 0 deletions gazebo/rendering/ScenePrivate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ namespace gazebo

/// \brief Shadow caster material name
public: std::string shadowCasterMaterialName = "Gazebo/shadow_caster";

/// \brief Shadow caster render back faces
public: bool shadowCasterRenderBackFaces = 1;
WilliamLewww marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
Expand Down