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

Add lightmap demo #471

Merged
merged 9 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
111 changes: 111 additions & 0 deletions examples/worlds/lightmap.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" ?>
<!--

A world demonstrating an indoor environment model that uses a lightmap.
There are no dynamic lights or shadows in the scene.

-->

<sdf version="1.7">
<world name="lightmap">
<physics name="1ms" type="ignored">
<max_step_size>0.001</max_step_size>
<real_time_factor>1.0</real_time_factor>
</physics>
<plugin
filename="libignition-gazebo-physics-system.so"
chapulina marked this conversation as resolved.
Show resolved Hide resolved
name="ignition::gazebo::systems::Physics">
</plugin>
<plugin
filename="libignition-gazebo-user-commands-system.so"
name="ignition::gazebo::systems::UserCommands">
</plugin>
<plugin
filename="libignition-gazebo-scene-broadcaster-system.so"
name="ignition::gazebo::systems::SceneBroadcaster">
</plugin>

<scene>
<ambient>1.0 1.0 1.0</ambient>
<background>0.8 0.8 0.8</background>
<grid>false</grid>
</scene>

<gui fullscreen="0">

<!-- 3D scene -->
<plugin filename="GzScene3D" name="3D View">
<ignition-gui>
<title>3D View</title>
<property type="bool" key="showTitleBar">false</property>
<property type="string" key="state">docked</property>
</ignition-gui>

<engine>ogre2</engine>
<scene>scene</scene>
<ambient_light>1.0 1.0 1.0</ambient_light>
<background_color>0.8 0.8 0.8</background_color>
<camera_pose>-5.5 -2 0.5 0 0.0 0</camera_pose>
</plugin>

<!-- World control -->
<plugin filename="WorldControl" name="World control">
<ignition-gui>
<title>World control</title>
<property type="bool" key="showTitleBar">false</property>
<property type="bool" key="resizable">false</property>
<property type="double" key="height">72</property>
<property type="double" key="width">121</property>
<property type="double" key="z">1</property>

<property type="string" key="state">floating</property>
<anchors target="3D View">
<line own="left" target="left"/>
<line own="bottom" target="bottom"/>
</anchors>
</ignition-gui>

<play_pause>true</play_pause>
<step>true</step>
<start_paused>true</start_paused>
<service>/world/lightmap/control</service>
<stats_topic>/world/lightmap/stats</stats_topic>
chapulina marked this conversation as resolved.
Show resolved Hide resolved

</plugin>

<!-- World statistics -->
<plugin filename="WorldStats" name="World stats">
<ignition-gui>
<title>World stats</title>
<property type="bool" key="showTitleBar">false</property>
<property type="bool" key="resizable">false</property>
<property type="double" key="height">110</property>
<property type="double" key="width">290</property>
<property type="double" key="z">1</property>

<property type="string" key="state">floating</property>
<anchors target="3D View">
<line own="right" target="right"/>
<line own="bottom" target="bottom"/>
</anchors>
</ignition-gui>

<sim_time>true</sim_time>
<real_time>true</real_time>
<real_time_factor>true</real_time_factor>
<iterations>true</iterations>
<topic>/world/lightmap/stats</topic>
chapulina marked this conversation as resolved.
Show resolved Hide resolved

</plugin>
</gui>

<include>
<static>true</static>
<name>Indoor Lightmap</name>
<pose>0 0 0 0 0 0</pose>
<uri>https://fuel.ignitionrobotics.org/1.0/OpenRobotics/models/Indoor Lightmap</uri>
</include>


</world>
</sdf>
21 changes: 21 additions & 0 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ msgs::Material ignition::gazebo::convert(const sdf::Material &_in)
asFullPath(workflow->EnvironmentMap(), _in.FilePath()));
pbrMsg->set_emissive_map(workflow->EmissiveMap().empty() ? "" :
asFullPath(workflow->EmissiveMap(), _in.FilePath()));

// todo(anyone) add light_map to material.proto
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we ticket an issue for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This was addressed on gazebosim/gz-msgs#111. We could wait until ign-gazebo5 is updated to use ign-msgs7 and use the new field here (gazebo-tooling/release-tools#362)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure sounds good

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is unblocked now

chapulina marked this conversation as resolved.
Show resolved Hide resolved
// storing lightmap in header for now
auto data = out.mutable_header()->add_data();
data->set_key("lightmap");
data->add_value(workflow->LightMap().empty() ? "" :
asFullPath(workflow->LightMap(), _in.FilePath()));
data->add_value(std::to_string(workflow->LightMapTexCoordSet()));
}
}
return out;
Expand Down Expand Up @@ -338,6 +346,19 @@ sdf::Material ignition::gazebo::convert(const msgs::Material &_in)
workflow.SetEnvironmentMap(pbrMsg.environment_map());
workflow.SetAmbientOcclusionMap(pbrMsg.ambient_occlusion_map());
workflow.SetEmissiveMap(pbrMsg.emissive_map());

// todo(anyone) add light_map to material.proto
chapulina marked this conversation as resolved.
Show resolved Hide resolved
// lightmap is temporarily stored in header
for (int i = 0; i < _in.header().data_size(); ++i)
{
if (_in.header().data(i).key() == "lightmap")
{
workflow.SetLightMap(_in.header().data(i).value(0),
std::stoi(_in.header().data(i).value(1)));
break;
}
}

pbr.SetWorkflow(workflow.Type(), workflow);
out.SetPbrMaterial(pbr);
}
Expand Down
8 changes: 8 additions & 0 deletions src/Conversions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ TEST(Conversions, Material)
workflow.SetEmissiveMap("emissive_map.png");
workflow.SetGlossinessMap("dummy_glossiness_map.png");
workflow.SetSpecularMap("dummy_specular_map.png");
workflow.SetLightMap("light_map.png", 1u);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the light_map.png file suppose to exist?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I think this is just testing that the conversion between SDF and messages works fine, without worrying about resolving the file.

workflow.SetMetalness(0.3);
workflow.SetRoughness(0.9);
workflow.SetGlossiness(0.1);
Expand Down Expand Up @@ -247,6 +248,11 @@ TEST(Conversions, Material)
EXPECT_EQ("ambient_occlusion_map.png", pbrMsg.ambient_occlusion_map());
EXPECT_EQ("dummy_glossiness_map.png", pbrMsg.glossiness_map());
EXPECT_EQ("dummy_specular_map.png", pbrMsg.specular_map());

// todo(anyone) add light_map to material.proto
chapulina marked this conversation as resolved.
Show resolved Hide resolved
EXPECT_EQ("light_map.png", materialMsg.header().data(0).value(0));
EXPECT_EQ(1, std::stoi(materialMsg.header().data(0).value(1)));

EXPECT_DOUBLE_EQ(0.3, pbrMsg.metalness());
EXPECT_DOUBLE_EQ(0.9, pbrMsg.roughness());
EXPECT_DOUBLE_EQ(0.1, pbrMsg.glossiness());
Expand All @@ -272,6 +278,8 @@ TEST(Conversions, Material)
EXPECT_EQ("ambient_occlusion_map.png", newWorkflow->AmbientOcclusionMap());
EXPECT_EQ("dummy_glossiness_map.png", newWorkflow->GlossinessMap());
EXPECT_EQ("dummy_specular_map.png", newWorkflow->SpecularMap());
EXPECT_EQ("light_map.png", newWorkflow->LightMap());
EXPECT_EQ(1u, newWorkflow->LightMapTexCoordSet());
EXPECT_DOUBLE_EQ(0.3, newWorkflow->Metalness());
EXPECT_DOUBLE_EQ(0.9, newWorkflow->Roughness());
EXPECT_DOUBLE_EQ(0.1, newWorkflow->Glossiness());
Expand Down
18 changes: 17 additions & 1 deletion src/rendering/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ rendering::MaterialPtr SceneManager::LoadMaterial(
{
material->SetTexture(fullPath);
// Use alpha channel for transparency
material->SetAlphaFromTexture(true);
material->SetAlphaFromTexture(true, 0.5, false);
}
else
ignerr << "Unable to find file [" << albedoMap << "]\n";
Expand Down Expand Up @@ -531,6 +531,22 @@ rendering::MaterialPtr SceneManager::LoadMaterial(
else
ignerr << "Unable to find file [" << emissiveMap << "]\n";
}

// light map
std::string lightMap = workflow->LightMap();
if (!lightMap.empty())
{
std::string fullPath = common::findFile(lightMap);
chapulina marked this conversation as resolved.
Show resolved Hide resolved
if (!fullPath.empty())
{
unsigned int uvSet = workflow->LightMapTexCoordSet();
material->SetLightMap(fullPath, uvSet);
}
else
{
ignerr << "Unable to find file [" << lightMap << "]\n";
}
}
}
return material;
}
Expand Down