-
Notifications
You must be signed in to change notification settings - Fork 486
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
scpeters
merged 7 commits into
gazebosim:gazebo11
from
WilliamLewww:wlew/shadow_caster_render_back_faces
Oct 15, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b438a21
Added SDF parameter for render back faces
WilliamLewww e5dfe78
Added SDF parameter for render back faces
WilliamLewww 08c1f55
Added default value for shaderCasterRenderBackFacesr
WilliamLewww 75ef2f4
Use true/false for initializing bool
WilliamLewww abe295e
Removed reinitialization of shadowCasterRenderBackFaces and shadowCas…
WilliamLewww 349b235
Added tests for shadow_caster_render_back_faces param
WilliamLewww ef25689
fix xml in default_shadow_caster.world
scpeters File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#include "gazebo/test/ServerFixture.hh" | ||
#include "gazebo/sensors/sensors.hh" | ||
|
||
using namespace gazebo; | ||
class ShadowCasterRenderBackFacesTest : public ServerFixture | ||
{ | ||
/// \brief Test rendering back faces | ||
public: void ShadowCasterBackFaces(); | ||
|
||
/// \brief Test rendering without back face | ||
public: void ShadowCasterNoBackFaces(); | ||
|
||
/// \brief Counter for the numbder of image messages received. | ||
public: unsigned int imageCount = 0u; | ||
|
||
/// \brief Depth data buffer. | ||
public: unsigned char* imageBuffer = nullptr; | ||
|
||
/// \brief Camera image callback | ||
/// \param[in] _msg Message with image data containing raw image values. | ||
public: void OnImage(ConstImageStampedPtr &_msg); | ||
}; | ||
|
||
///////////////////////////////////////////////// | ||
void ShadowCasterRenderBackFacesTest::OnImage(ConstImageStampedPtr &_msg) | ||
{ | ||
unsigned int imageSamples = _msg->image().width() *_msg->image().height() * 3; | ||
memcpy(this->imageBuffer, _msg->image().data().c_str(), imageSamples); | ||
this->imageCount++; | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
// \brief The shadow caster will render back faces; The plane in the world will | ||
/// cast a shadow | ||
void ShadowCasterRenderBackFacesTest::ShadowCasterBackFaces() | ||
{ | ||
this->Load("worlds/shadow_caster_back_faces.world"); | ||
|
||
// Make sure the render engine is available. | ||
if (rendering::RenderEngine::Instance()->GetRenderPathType() == | ||
rendering::RenderEngine::NONE) | ||
{ | ||
gzerr << "No rendering engine, unable to run camera test\n"; | ||
return; | ||
} | ||
|
||
sensors::CameraSensorPtr sensor = | ||
std::dynamic_pointer_cast<sensors::CameraSensor>( | ||
sensors::get_sensor("camera_normal")); | ||
EXPECT_TRUE(sensor != nullptr); | ||
EXPECT_TRUE(sensor->IsActive()); | ||
|
||
unsigned int width = 320; | ||
unsigned int height = 240; | ||
|
||
this->imageCount = 0; | ||
this->imageBuffer = new unsigned char[width * height*3]; | ||
|
||
transport::NodePtr node(new transport::Node()); | ||
node->Init(); | ||
|
||
std::string topic = sensor->Topic(); | ||
EXPECT_TRUE(!topic.empty()); | ||
|
||
transport::SubscriberPtr sub = node->Subscribe(topic, | ||
&ShadowCasterRenderBackFacesTest::OnImage, this); | ||
|
||
// wait for a few images | ||
int i = 0; | ||
while (this->imageCount < 10 && i < 300) | ||
{ | ||
common::Time::MSleep(10); | ||
i++; | ||
} | ||
EXPECT_LT(i, 300); | ||
|
||
for (unsigned int x = 0; x < 320 * 240; x += 600) { | ||
EXPECT_GT(50, this->imageBuffer[3 * x]); | ||
EXPECT_GT(50, this->imageBuffer[3 * x + 1]); | ||
EXPECT_GT(50, this->imageBuffer[3 * x + 2]); | ||
} | ||
|
||
delete this->imageBuffer; | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
TEST_F(ShadowCasterRenderBackFacesTest, ShadowCasterBackFaces) | ||
{ | ||
ShadowCasterBackFaces(); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
// \brief The shadow caster will not render back faces; The plane in the world | ||
/// will not cast a shadow | ||
void ShadowCasterRenderBackFacesTest::ShadowCasterNoBackFaces() | ||
{ | ||
this->Load("worlds/shadow_caster_no_back_faces.world"); | ||
|
||
// Make sure the render engine is available. | ||
if (rendering::RenderEngine::Instance()->GetRenderPathType() == | ||
rendering::RenderEngine::NONE) | ||
{ | ||
gzerr << "No rendering engine, unable to run camera test\n"; | ||
return; | ||
} | ||
|
||
sensors::CameraSensorPtr sensor = | ||
std::dynamic_pointer_cast<sensors::CameraSensor>( | ||
sensors::get_sensor("camera_normal")); | ||
EXPECT_TRUE(sensor != nullptr); | ||
EXPECT_TRUE(sensor->IsActive()); | ||
|
||
unsigned int width = 320; | ||
unsigned int height = 240; | ||
|
||
this->imageCount = 0; | ||
this->imageBuffer = new unsigned char[width * height*3]; | ||
|
||
transport::NodePtr node(new transport::Node()); | ||
node->Init(); | ||
|
||
std::string topic = sensor->Topic(); | ||
EXPECT_TRUE(!topic.empty()); | ||
|
||
transport::SubscriberPtr sub = node->Subscribe(topic, | ||
&ShadowCasterRenderBackFacesTest::OnImage, this); | ||
|
||
// wait for a few images | ||
int i = 0; | ||
while (this->imageCount < 10 && i < 300) | ||
{ | ||
common::Time::MSleep(10); | ||
i++; | ||
} | ||
EXPECT_LT(i, 300); | ||
|
||
for (unsigned int x = 0; x < 320 * 240; x += 600) { | ||
EXPECT_LT(50, this->imageBuffer[3 * x]); | ||
EXPECT_LT(50, this->imageBuffer[3 * x + 1]); | ||
EXPECT_LT(50, this->imageBuffer[3 * x + 2]); | ||
} | ||
|
||
delete this->imageBuffer; | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
TEST_F(ShadowCasterRenderBackFacesTest, ShadowCasterNoBackFaces) | ||
{ | ||
ShadowCasterNoBackFaces(); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
int main(int argc, char **argv) | ||
{ | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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