Skip to content

Commit

Permalink
Add lightmap demo (#471)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Nate Koenig <[email protected]>

Co-authored-by: Nate Koenig <[email protected]>
  • Loading branch information
iche033 and Nate Koenig authored Feb 1, 2021
1 parent 55ddac7 commit d719838
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
94 changes: 94 additions & 0 deletions examples/worlds/lightmap.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?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>
<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>

</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>

</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>
5 changes: 5 additions & 0 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ 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()));
pbrMsg->set_light_map(workflow->LightMap().empty() ? "" :
asFullPath(workflow->LightMap(), _in.FilePath()));
pbrMsg->set_light_map_texcoord_set(workflow->LightMapTexCoordSet());
}
}
return out;
Expand Down Expand Up @@ -363,6 +366,8 @@ 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());
workflow.SetLightMap(pbrMsg.light_map(), pbrMsg.light_map_texcoord_set());

pbr.SetWorkflow(workflow.Type(), workflow);
out.SetPbrMaterial(pbr);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Conversions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,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);
workflow.SetMetalness(0.3);
workflow.SetRoughness(0.9);
workflow.SetGlossiness(0.1);
Expand Down Expand Up @@ -257,6 +258,9 @@ 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());
EXPECT_EQ("light_map.png", pbrMsg.light_map());
EXPECT_EQ(1u, pbrMsg.light_map_texcoord_set());

EXPECT_DOUBLE_EQ(0.3, pbrMsg.metalness());
EXPECT_DOUBLE_EQ(0.9, pbrMsg.roughness());
EXPECT_DOUBLE_EQ(0.1, pbrMsg.glossiness());
Expand Down Expand Up @@ -284,6 +288,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
17 changes: 17 additions & 0 deletions src/rendering/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,23 @@ 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(
asFullPath(lightMap, _material.FilePath()));
if (!fullPath.empty())
{
unsigned int uvSet = workflow->LightMapTexCoordSet();
material->SetLightMap(fullPath, uvSet);
}
else
{
ignerr << "Unable to find file [" << lightMap << "]\n";
}
}
}
return material;
}
Expand Down

0 comments on commit d719838

Please sign in to comment.