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 to 1.7 spec and PBR material DOM #429

Merged
merged 5 commits into from
Dec 15, 2020
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
15 changes: 15 additions & 0 deletions include/sdf/Pbr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ namespace sdf
/// \param[in] _map Filename of the emissive map.
public: void SetEmissiveMap(const std::string &_map);

/// \brief Get the light map filename. This will be an empty string
/// if an light map has not been set.
/// \return Filename of the light map, or empty string if a light
/// map has not been specified.
public: std::string LightMap() const;
Copy link
Member

Choose a reason for hiding this comment

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

I know this matches the name of the SDF element, but I think it would be more informative if this accessor was called LightMapFileName

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh I'm going back and forth on this. I'm trying to keep consistency with the sdf spec, the msg field in proto, and ign-rendering API. I think there is advantage to keeping the the public APIs consistent. If a more informative function name is preferred here, maybe we can also consider deprecating other functions in this class in favor of *MapFilename()?

Copy link
Member

Choose a reason for hiding this comment

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

ok, I hadn't thought about the API of other packages. it's fine as is


/// \brief Set the light map filename.
/// \param[in] _map Filename of the light map.
/// \param[in] _uvSet Index of the light map texture coordinate set
public: void SetLightMap(const std::string &_map, unsigned int _uvSet = 0u);

/// \brief Get the light map texture coordinate set.
/// \return Index of the texture coordinate set
public: unsigned int LightMapTexCoordSet() const;

/// \brief Get the metalness value of the material for metal workflow
/// \return metalness value of the material
public: double Metalness() const;
Expand Down
15 changes: 15 additions & 0 deletions sdf/1.7/material.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@
<element name="emissive_map" type="string" default="" required="0">
<description>Filename of the emissive map.</description>
</element>

<element name="light_map" type="string" default="" required="0">
<attribute name="uv_set" type="unsigned int" default="0" required="0">
<description>Index of the texture coordinate set to use.</description>
</attribute>
<description>Filename of the light map. The light map is a prebaked light texutre that is applied over the albedo map</description>
scpeters marked this conversation as resolved.
Show resolved Hide resolved
</element>

</element>

<element name="specular" required="0">
Expand Down Expand Up @@ -131,6 +139,13 @@
<element name="emissive_map" type="string" default="" required="0">
<description>Filename of the emissive map.</description>
</element>

<element name="light_map" type="string" default="" required="0">
<attribute name="uv_set" type="unsigned int" default="0" required="0">
<description>Index of the texture coordinate set to use.</description>
</attribute>
<description>Filename of the light map. The light map is a prebaked light texutre that is applied over the albedo map</description>
scpeters marked this conversation as resolved.
Show resolved Hide resolved
</element>
</element>

</element>
Expand Down
33 changes: 33 additions & 0 deletions src/Pbr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class sdf::PbrWorkflowPrivate
/// \brief Emissive map
public: std::string emissiveMap = "";

/// \brief Light map
public: std::string lightMap;
scpeters marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Light map texture coordinate set
public: unsigned int lightMapUvSet = 0u;

/// \brief Roughness value (metal workflow only)
public: double roughness = 0.5;

Expand Down Expand Up @@ -140,6 +146,7 @@ bool PbrWorkflow::operator==(const PbrWorkflow &_workflow) const
&& (this->dataPtr->glossinessMap == _workflow.dataPtr->glossinessMap)
&& (this->dataPtr->environmentMap == _workflow.dataPtr->environmentMap)
&& (this->dataPtr->emissiveMap == _workflow.dataPtr->emissiveMap)
&& (this->dataPtr->lightMap == _workflow.dataPtr->lightMap)
&& (this->dataPtr->ambientOcclusionMap ==
_workflow.dataPtr->ambientOcclusionMap)
&& (ignition::math::equal(
Expand Down Expand Up @@ -212,6 +219,13 @@ Errors PbrWorkflow::Load(sdf::ElementPtr _sdf)
this->dataPtr->emissiveMap = _sdf->Get<std::string>("emissive_map",
this->dataPtr->emissiveMap).first;

if (_sdf->HasElement("light_map"))
{
sdf::ElementPtr lightMapElem = _sdf->GetElement("light_map");
this->dataPtr->lightMap = lightMapElem->Get<std::string>();
this->dataPtr->lightMapUvSet = lightMapElem->Get<unsigned int>("uv_set");
chapulina marked this conversation as resolved.
Show resolved Hide resolved
}

return errors;
}

Expand Down Expand Up @@ -366,6 +380,25 @@ void PbrWorkflow::SetEmissiveMap(const std::string &_map)
this->dataPtr->emissiveMap = _map;
}

//////////////////////////////////////////////////
std::string PbrWorkflow::LightMap() const
{
return this->dataPtr->lightMap;
}

//////////////////////////////////////////////////
void PbrWorkflow::SetLightMap(const std::string &_map, unsigned int _uvSet)
{
this->dataPtr->lightMap = _map;
this->dataPtr->lightMapUvSet = _uvSet;
}

//////////////////////////////////////////////////
unsigned int PbrWorkflow::LightMapTexCoordSet() const
{
return this->dataPtr->lightMapUvSet;
}

//////////////////////////////////////////////////
sdf::ElementPtr PbrWorkflow::Element() const
{
Expand Down
34 changes: 34 additions & 0 deletions src/Pbr_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ TEST(DOMPbr, Construction)
EXPECT_EQ(std::string(), workflow.RoughnessMap());
EXPECT_EQ(std::string(), workflow.MetalnessMap());
EXPECT_EQ(std::string(), workflow.EmissiveMap());
EXPECT_EQ(std::string(), workflow.LightMap());
EXPECT_EQ(0u, workflow.LightMapTexCoordSet());
EXPECT_DOUBLE_EQ(0.5, workflow.Roughness());
EXPECT_DOUBLE_EQ(0.5, workflow.Metalness());
EXPECT_EQ(std::string(), workflow.SpecularMap());
Expand Down Expand Up @@ -70,6 +72,7 @@ TEST(DOMPbr, MoveConstructor)
workflow.SetEnvironmentMap("metal_env_map.png");
workflow.SetAmbientOcclusionMap("metal_ambient_occlusion_map.png");
workflow.SetEmissiveMap("metal_emissive_map.png");
workflow.SetLightMap("metal_light_map.png", 1u);
workflow.SetRoughnessMap("roughness_map.png");
workflow.SetMetalnessMap("metalness_map.png");
workflow.SetRoughness(0.8);
Expand All @@ -84,6 +87,8 @@ TEST(DOMPbr, MoveConstructor)
EXPECT_EQ("metal_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("metal_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("metal_light_map.png", workflow2.LightMap());
EXPECT_EQ(1u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("roughness_map.png", workflow2.RoughnessMap());
EXPECT_EQ("metalness_map.png", workflow2.MetalnessMap());
EXPECT_DOUBLE_EQ(0.8, workflow2.Roughness());
Expand All @@ -104,6 +109,7 @@ TEST(DOMPbr, MoveConstructor)
workflow.SetEnvironmentMap("specular_env_map.png");
workflow.SetAmbientOcclusionMap("specular_ambient_occlusion_map.png");
workflow.SetEmissiveMap("specular_emissive_map.png");
workflow.SetLightMap("specular_light_map.png", 2u);
workflow.SetGlossinessMap("glossiness_map.png");
workflow.SetSpecularMap("specular_map.png");
workflow.SetGlossiness(0.1);
Expand All @@ -117,6 +123,8 @@ TEST(DOMPbr, MoveConstructor)
EXPECT_EQ("specular_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("specular_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("specular_light_map.png", workflow2.LightMap());
EXPECT_EQ(2u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("specular_map.png", workflow2.SpecularMap());
EXPECT_EQ("glossiness_map.png", workflow2.GlossinessMap());
EXPECT_DOUBLE_EQ(0.1, workflow2.Glossiness());
Expand Down Expand Up @@ -155,6 +163,7 @@ TEST(DOMPbr, MoveAssignmentOperator)
workflow.SetEnvironmentMap("metal_env_map.png");
workflow.SetAmbientOcclusionMap("metal_ambient_occlusion_map.png");
workflow.SetEmissiveMap("metal_emissive_map.png");
workflow.SetLightMap("metal_light_map.png", 3u);
workflow.SetRoughnessMap("roughness_map.png");
workflow.SetMetalnessMap("metalness_map.png");
workflow.SetRoughness(0.8);
Expand All @@ -170,6 +179,8 @@ TEST(DOMPbr, MoveAssignmentOperator)
EXPECT_EQ("metal_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("metal_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("metal_light_map.png", workflow2.LightMap());
EXPECT_EQ(3u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("roughness_map.png", workflow2.RoughnessMap());
EXPECT_EQ("metalness_map.png", workflow2.MetalnessMap());
EXPECT_DOUBLE_EQ(0.8, workflow2.Roughness());
Expand All @@ -190,6 +201,7 @@ TEST(DOMPbr, MoveAssignmentOperator)
workflow.SetEnvironmentMap("specular_env_map.png");
workflow.SetAmbientOcclusionMap("specular_ambient_occlusion_map.png");
workflow.SetEmissiveMap("specular_emissive_map.png");
workflow.SetLightMap("specular_light_map.png", 1u);
workflow.SetGlossinessMap("glossiness_map.png");
workflow.SetSpecularMap("specular_map.png");
workflow.SetGlossiness(0.1);
Expand All @@ -204,6 +216,8 @@ TEST(DOMPbr, MoveAssignmentOperator)
EXPECT_EQ("specular_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("specular_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("specular_light_map.png", workflow2.LightMap());
EXPECT_EQ(1u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("specular_map.png", workflow2.SpecularMap());
EXPECT_EQ("glossiness_map.png", workflow2.GlossinessMap());
EXPECT_DOUBLE_EQ(0.1, workflow2.Glossiness());
Expand Down Expand Up @@ -241,6 +255,7 @@ TEST(DOMPbr, CopyConstructor)
workflow.SetEnvironmentMap("metal_env_map.png");
workflow.SetAmbientOcclusionMap("metal_ambient_occlusion_map.png");
workflow.SetEmissiveMap("metal_emissive_map.png");
workflow.SetLightMap("metal_light_map.png", 2u);
workflow.SetRoughnessMap("roughness_map.png");
workflow.SetMetalnessMap("metalness_map.png");
workflow.SetRoughness(0.8);
Expand All @@ -255,6 +270,8 @@ TEST(DOMPbr, CopyConstructor)
EXPECT_EQ("metal_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("metal_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("metal_light_map.png", workflow2.LightMap());
EXPECT_EQ(2u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("roughness_map.png", workflow2.RoughnessMap());
EXPECT_EQ("metalness_map.png", workflow2.MetalnessMap());
EXPECT_DOUBLE_EQ(0.8, workflow2.Roughness());
Expand All @@ -274,6 +291,7 @@ TEST(DOMPbr, CopyConstructor)
workflow.SetEnvironmentMap("specular_env_map.png");
workflow.SetAmbientOcclusionMap("specular_ambient_occlusion_map.png");
workflow.SetEmissiveMap("specular_emissive_map.png");
workflow.SetLightMap("specular_light_map.png", 1u);
workflow.SetGlossinessMap("glossiness_map.png");
workflow.SetSpecularMap("specular_map.png");
workflow.SetGlossiness(0.1);
Expand All @@ -287,6 +305,8 @@ TEST(DOMPbr, CopyConstructor)
EXPECT_EQ("specular_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("specular_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("specular_light_map.png", workflow2.LightMap());
EXPECT_EQ(1u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("specular_map.png", workflow2.SpecularMap());
EXPECT_EQ("glossiness_map.png", workflow2.GlossinessMap());
EXPECT_DOUBLE_EQ(0.1, workflow2.Glossiness());
Expand Down Expand Up @@ -325,6 +345,7 @@ TEST(DOMPbr, AssignmentOperator)
workflow.SetEnvironmentMap("metal_env_map.png");
workflow.SetAmbientOcclusionMap("metal_ambient_occlusion_map.png");
workflow.SetEmissiveMap("metal_emissive_map.png");
workflow.SetLightMap("metal_light_map.png", 1u);
workflow.SetRoughnessMap("roughness_map.png");
workflow.SetMetalnessMap("metalness_map.png");
workflow.SetRoughness(0.8);
Expand All @@ -339,6 +360,8 @@ TEST(DOMPbr, AssignmentOperator)
EXPECT_EQ("metal_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("metal_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("metal_light_map.png", workflow2.LightMap());
EXPECT_EQ(1u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("roughness_map.png", workflow2.RoughnessMap());
EXPECT_EQ("metalness_map.png", workflow2.MetalnessMap());
EXPECT_DOUBLE_EQ(0.8, workflow2.Roughness());
Expand All @@ -358,6 +381,7 @@ TEST(DOMPbr, AssignmentOperator)
workflow.SetEnvironmentMap("specular_env_map.png");
workflow.SetAmbientOcclusionMap("specular_ambient_occlusion_map.png");
workflow.SetEmissiveMap("specular_emissive_map.png");
workflow.SetLightMap("specular_light_map.png", 2u);
workflow.SetGlossinessMap("glossiness_map.png");
workflow.SetSpecularMap("specular_map.png");
workflow.SetGlossiness(0.1);
Expand All @@ -370,6 +394,8 @@ TEST(DOMPbr, AssignmentOperator)
EXPECT_EQ("specular_ambient_occlusion_map.png",
workflow2.AmbientOcclusionMap());
EXPECT_EQ("specular_emissive_map.png", workflow2.EmissiveMap());
EXPECT_EQ("specular_light_map.png", workflow2.LightMap());
EXPECT_EQ(2u, workflow2.LightMapTexCoordSet());
EXPECT_EQ("specular_map.png", workflow2.SpecularMap());
EXPECT_EQ("glossiness_map.png", workflow2.GlossinessMap());
EXPECT_DOUBLE_EQ(0.1, workflow2.Glossiness());
Expand Down Expand Up @@ -443,6 +469,10 @@ TEST(DOMPbr, Set)
workflow.SetEmissiveMap("metal_emissive_map.png");
EXPECT_EQ("metal_emissive_map.png", workflow.EmissiveMap());

workflow.SetLightMap("metal_light_map.png", 1u);
EXPECT_EQ("metal_light_map.png", workflow.LightMap());
EXPECT_EQ(1u, workflow.LightMapTexCoordSet());

workflow.SetRoughnessMap("roughness_map.png");
EXPECT_EQ("roughness_map.png", workflow.RoughnessMap());

Expand Down Expand Up @@ -491,6 +521,10 @@ TEST(DOMPbr, Set)
workflow.SetEmissiveMap("specular_emissive_map.png");
EXPECT_EQ("specular_emissive_map.png", workflow.EmissiveMap());

workflow.SetLightMap("specular_light_map.png", 1u);
EXPECT_EQ("specular_light_map.png", workflow.LightMap());
EXPECT_EQ(1u, workflow.LightMapTexCoordSet());

workflow.SetGlossinessMap("glossiness_map.png");
EXPECT_EQ("glossiness_map.png", workflow.GlossinessMap());

Expand Down
43 changes: 41 additions & 2 deletions test/integration/material_pbr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ TEST(Material, PbrDOM)

// emissive map
EXPECT_EQ("emissive_map.png", workflow->EmissiveMap());

// light map
EXPECT_EQ("light_map.png", workflow->LightMap());
EXPECT_EQ(1u, workflow->LightMapTexCoordSet());
}

// visual specular workflow
Expand Down Expand Up @@ -148,6 +152,10 @@ TEST(Material, PbrDOM)

// emissive map
EXPECT_EQ("emissive_map.png", workflow->EmissiveMap());

// light map
EXPECT_EQ("light_map.png", workflow->LightMap());
EXPECT_EQ(2u, workflow->LightMapTexCoordSet());
}

// visual all
Expand Down Expand Up @@ -203,6 +211,10 @@ TEST(Material, PbrDOM)

// emissive map
EXPECT_EQ("emissive_map.png", workflow->EmissiveMap());

// light map
EXPECT_EQ("light_map.png", workflow->LightMap());
EXPECT_EQ(3u, workflow->LightMapTexCoordSet());
}
// metal
{
Expand Down Expand Up @@ -237,6 +249,10 @@ TEST(Material, PbrDOM)

// emissive map
EXPECT_EQ("emissive_map.png", workflow->EmissiveMap());

// light map
EXPECT_EQ("light_map.png", workflow->LightMap());
EXPECT_EQ(4u, workflow->LightMapTexCoordSet());
}
}
}
Expand Down Expand Up @@ -343,6 +359,13 @@ TEST(Material, MaterialPBR)
EXPECT_TRUE(metalElem->HasElement("emissive_map"));
sdf::ElementPtr emissiveMapElem = metalElem->GetElement("emissive_map");
EXPECT_EQ("emissive_map.png", emissiveMapElem->Get<std::string>());


// light map
EXPECT_TRUE(metalElem->HasElement("light_map"));
sdf::ElementPtr lightMapElem = metalElem->GetElement("light_map");
EXPECT_EQ("light_map.png", lightMapElem->Get<std::string>());
EXPECT_EQ(1u, lightMapElem->Get<unsigned int>("uv_set"));
}

// visual specular workflow
Expand Down Expand Up @@ -412,6 +435,12 @@ TEST(Material, MaterialPBR)
EXPECT_TRUE(specularElem->HasElement("emissive_map"));
sdf::ElementPtr emissiveMapElem = specularElem->GetElement("emissive_map");
EXPECT_EQ("emissive_map.png", emissiveMapElem->Get<std::string>());

// light map
EXPECT_TRUE(specularElem->HasElement("light_map"));
sdf::ElementPtr lightMapElem = specularElem->GetElement("light_map");
EXPECT_EQ("light_map.png", lightMapElem->Get<std::string>());
EXPECT_EQ(2u, lightMapElem->Get<unsigned int>("uv_set"));
}

// visual all
Expand Down Expand Up @@ -484,6 +513,12 @@ TEST(Material, MaterialPBR)
sdf::ElementPtr emissiveMapElem =
specularElem->GetElement("emissive_map");
EXPECT_EQ("emissive_map.png", emissiveMapElem->Get<std::string>());

// light map
EXPECT_TRUE(specularElem->HasElement("light_map"));
sdf::ElementPtr lightMapElem = specularElem->GetElement("light_map");
EXPECT_EQ("light_map.png", lightMapElem->Get<std::string>());
EXPECT_EQ(3u, lightMapElem->Get<unsigned int>("uv_set"));
}

{
Expand Down Expand Up @@ -538,8 +573,12 @@ TEST(Material, MaterialPBR)
EXPECT_TRUE(metalElem->HasElement("emissive_map"));
sdf::ElementPtr emissiveMapElem = metalElem->GetElement("emissive_map");
EXPECT_EQ("emissive_map.png", emissiveMapElem->Get<std::string>());

// light map
EXPECT_TRUE(metalElem->HasElement("light_map"));
sdf::ElementPtr lightMapElem = metalElem->GetElement("light_map");
EXPECT_EQ("light_map.png", lightMapElem->Get<std::string>());
EXPECT_EQ(4u, lightMapElem->Get<unsigned int>("uv_set"));
}
}
}


Loading