diff --git a/include/sdf/Pbr.hh b/include/sdf/Pbr.hh index 564315d85..f1b5a0498 100644 --- a/include/sdf/Pbr.hh +++ b/include/sdf/Pbr.hh @@ -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; + + /// \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; diff --git a/sdf/1.7/material.sdf b/sdf/1.7/material.sdf index 00ed20924..be398d366 100644 --- a/sdf/1.7/material.sdf +++ b/sdf/1.7/material.sdf @@ -95,6 +95,14 @@ Filename of the emissive map. + + + + Index of the texture coordinate set to use. + + Filename of the light map. The light map is a prebaked light texture that is applied over the albedo map + + @@ -131,6 +139,13 @@ Filename of the emissive map. + + + + Index of the texture coordinate set to use. + + Filename of the light map. The light map is a prebaked light texture that is applied over the albedo map + diff --git a/src/Pbr.cc b/src/Pbr.cc index dbfd06041..63fd5800c 100644 --- a/src/Pbr.cc +++ b/src/Pbr.cc @@ -55,6 +55,12 @@ class sdf::PbrWorkflowPrivate /// \brief Emissive map public: std::string emissiveMap = ""; + /// \brief Light map + public: std::string lightMapFilename; + + /// \brief Light map texture coordinate set + public: unsigned int lightMapUvSet = 0u; + /// \brief Roughness value (metal workflow only) public: double roughness = 0.5; @@ -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->lightMapFilename == _workflow.dataPtr->lightMapFilename) && (this->dataPtr->ambientOcclusionMap == _workflow.dataPtr->ambientOcclusionMap) && (ignition::math::equal( @@ -212,6 +219,14 @@ Errors PbrWorkflow::Load(sdf::ElementPtr _sdf) this->dataPtr->emissiveMap = _sdf->Get("emissive_map", this->dataPtr->emissiveMap).first; + if (_sdf->HasElement("light_map")) + { + sdf::ElementPtr lightMapElem = _sdf->GetElement("light_map"); + this->dataPtr->lightMapFilename = lightMapElem->Get(); + this->dataPtr->lightMapUvSet = lightMapElem->Get("uv_set", + this->dataPtr->lightMapUvSet).first; + } + return errors; } @@ -366,6 +381,25 @@ void PbrWorkflow::SetEmissiveMap(const std::string &_map) this->dataPtr->emissiveMap = _map; } +////////////////////////////////////////////////// +std::string PbrWorkflow::LightMap() const +{ + return this->dataPtr->lightMapFilename; +} + +////////////////////////////////////////////////// +void PbrWorkflow::SetLightMap(const std::string &_map, unsigned int _uvSet) +{ + this->dataPtr->lightMapFilename = _map; + this->dataPtr->lightMapUvSet = _uvSet; +} + +////////////////////////////////////////////////// +unsigned int PbrWorkflow::LightMapTexCoordSet() const +{ + return this->dataPtr->lightMapUvSet; +} + ////////////////////////////////////////////////// sdf::ElementPtr PbrWorkflow::Element() const { diff --git a/src/Pbr_TEST.cc b/src/Pbr_TEST.cc index 39d3892b4..5b4c95da8 100644 --- a/src/Pbr_TEST.cc +++ b/src/Pbr_TEST.cc @@ -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()); @@ -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); @@ -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()); @@ -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); @@ -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()); @@ -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); @@ -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()); @@ -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); @@ -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()); @@ -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); @@ -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()); @@ -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); @@ -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()); @@ -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); @@ -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()); @@ -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); @@ -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()); @@ -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()); @@ -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()); diff --git a/test/integration/material_pbr.cc b/test/integration/material_pbr.cc index 4eb8f6b3d..1d684deea 100644 --- a/test/integration/material_pbr.cc +++ b/test/integration/material_pbr.cc @@ -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 @@ -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 @@ -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 { @@ -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(0u, workflow->LightMapTexCoordSet()); } } } @@ -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()); + + + // light map + EXPECT_TRUE(metalElem->HasElement("light_map")); + sdf::ElementPtr lightMapElem = metalElem->GetElement("light_map"); + EXPECT_EQ("light_map.png", lightMapElem->Get()); + EXPECT_EQ(1u, lightMapElem->Get("uv_set")); } // visual specular workflow @@ -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()); + + // light map + EXPECT_TRUE(specularElem->HasElement("light_map")); + sdf::ElementPtr lightMapElem = specularElem->GetElement("light_map"); + EXPECT_EQ("light_map.png", lightMapElem->Get()); + EXPECT_EQ(2u, lightMapElem->Get("uv_set")); } // visual all @@ -484,6 +513,12 @@ TEST(Material, MaterialPBR) sdf::ElementPtr emissiveMapElem = specularElem->GetElement("emissive_map"); EXPECT_EQ("emissive_map.png", emissiveMapElem->Get()); + + // light map + EXPECT_TRUE(specularElem->HasElement("light_map")); + sdf::ElementPtr lightMapElem = specularElem->GetElement("light_map"); + EXPECT_EQ("light_map.png", lightMapElem->Get()); + EXPECT_EQ(3u, lightMapElem->Get("uv_set")); } { @@ -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()); + + // light map + EXPECT_TRUE(metalElem->HasElement("light_map")); + sdf::ElementPtr lightMapElem = metalElem->GetElement("light_map"); + EXPECT_EQ("light_map.png", lightMapElem->Get()); + EXPECT_EQ(0u, lightMapElem->Get("uv_set")); } } } - - diff --git a/test/sdf/material_pbr.sdf b/test/sdf/material_pbr.sdf index b7987dd99..8ee2604aa 100644 --- a/test/sdf/material_pbr.sdf +++ b/test/sdf/material_pbr.sdf @@ -16,6 +16,7 @@ environment_map.png ambient_occlusion_map.png emissive_map.png + light_map.png @@ -35,6 +36,7 @@ environment_map.png ambient_occlusion_map.png emissive_map.png + light_map.png @@ -56,6 +58,7 @@ environment_map.png ambient_occlusion_map.png emissive_map.png + light_map.png albedo_map.png @@ -67,6 +70,7 @@ environment_map.png ambient_occlusion_map.png emissive_map.png + light_map.png