From 6b1d056a33277adb1bafdf2d3b5fb802d8342bda Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Mon, 21 Dec 2020 13:23:54 -0800 Subject: [PATCH] Add Lightmap to material (#132) * fix frame number in video encoding Signed-off-by: Ian Chen * encode duplicate frames to ensure continuous pts Signed-off-by: Ian Chen * fix resetting video recording Signed-off-by: Ian Chen * support multiple texcoord set Signed-off-by: Ian Chen * add tex coord set count Signed-off-by: Ian Chen * add lightmap to material Signed-off-by: Ian Chen * fixing load time Signed-off-by: Ian Chen * more fixes Signed-off-by: Ian Chen * fix codecheck Signed-off-by: Ian Chen Co-authored-by: Louise Poubel --- graphics/include/ignition/common/Pbr.hh | 15 +++++++++++++++ graphics/src/Pbr.cc | 25 +++++++++++++++++++++++++ graphics/src/Pbr_TEST.cc | 18 ++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/graphics/include/ignition/common/Pbr.hh b/graphics/include/ignition/common/Pbr.hh index cd84c8573..68afde020 100644 --- a/graphics/include/ignition/common/Pbr.hh +++ b/graphics/include/ignition/common/Pbr.hh @@ -166,6 +166,21 @@ namespace common /// \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 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 light map 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/graphics/src/Pbr.cc b/graphics/src/Pbr.cc index f3024a303..cd96bda6a 100644 --- a/graphics/src/Pbr.cc +++ b/graphics/src/Pbr.cc @@ -50,6 +50,12 @@ class ignition::common::PbrPrivate /// \brief Emissive map public: std::string emissiveMap = ""; + /// \brief Light map + public: std::string lightMap; + + /// \brief Light map texture coordinate set + public: unsigned int lightMapUvSet = 0u; + /// \brief Roughness value (metal workflow only) public: double roughness = 0.5; @@ -293,6 +299,25 @@ void Pbr::SetEmissiveMap(const std::string &_map) this->dataPtr->emissiveMap = _map; } +////////////////////////////////////////////////// +std::string Pbr::LightMap() const +{ + return this->dataPtr->lightMap; +} + +////////////////////////////////////////////////// +void Pbr::SetLightMap(const std::string &_map, unsigned int _uvSet) +{ + this->dataPtr->lightMap = _map; + this->dataPtr->lightMapUvSet = _uvSet; +} + +////////////////////////////////////////////////// +unsigned int Pbr::LightMapTexCoordSet() const +{ + return this->dataPtr->lightMapUvSet; +} + ////////////////////////////////////////////////// PbrType Pbr::Type() const { diff --git a/graphics/src/Pbr_TEST.cc b/graphics/src/Pbr_TEST.cc index b7e89b072..de9a923d2 100644 --- a/graphics/src/Pbr_TEST.cc +++ b/graphics/src/Pbr_TEST.cc @@ -32,6 +32,8 @@ TEST(Pbr, BasicAPI) EXPECT_EQ(std::string(), pbr.RoughnessMap()); EXPECT_EQ(std::string(), pbr.MetalnessMap()); EXPECT_EQ(std::string(), pbr.EmissiveMap()); + EXPECT_EQ(std::string(), pbr.LightMap()); + EXPECT_EQ(0u, pbr.LightMapTexCoordSet()); EXPECT_DOUBLE_EQ(0.5, pbr.Roughness()); EXPECT_DOUBLE_EQ(0.0, pbr.Metalness()); EXPECT_EQ(std::string(), pbr.SpecularMap()); @@ -60,6 +62,10 @@ TEST(Pbr, BasicAPI) pbr.SetEmissiveMap("metal_emissive_map.png"); EXPECT_EQ("metal_emissive_map.png", pbr.EmissiveMap()); + pbr.SetLightMap("metal_light_map.png", 1u); + EXPECT_EQ("metal_light_map.png", pbr.LightMap()); + EXPECT_EQ(1u, pbr.LightMapTexCoordSet()); + pbr.SetRoughnessMap("roughness_map.png"); EXPECT_EQ("roughness_map.png", pbr.RoughnessMap()); @@ -89,6 +95,7 @@ TEST(Pbr, MoveCopy) pbr.SetEnvironmentMap("specular_env_map.png"); pbr.SetAmbientOcclusionMap("specular_ambient_occlusion_map.png"); pbr.SetEmissiveMap("specular_emissive_map.png"); + pbr.SetLightMap("specular_light_map.png", 2u); pbr.SetGlossinessMap("glossiness_map.png"); pbr.SetSpecularMap("specular_map.png"); pbr.SetGlossiness(0.1); @@ -102,6 +109,8 @@ TEST(Pbr, MoveCopy) EXPECT_EQ("specular_ambient_occlusion_map.png", pbr2.AmbientOcclusionMap()); EXPECT_EQ("specular_emissive_map.png", pbr2.EmissiveMap()); + EXPECT_EQ("specular_light_map.png", pbr2.LightMap()); + EXPECT_EQ(2u, pbr2.LightMapTexCoordSet()); EXPECT_EQ("specular_map.png", pbr2.SpecularMap()); EXPECT_EQ("glossiness_map.png", pbr2.GlossinessMap()); EXPECT_DOUBLE_EQ(0.1, pbr2.Glossiness()); @@ -122,6 +131,7 @@ TEST(Pbr, MoveCopy) pbr.SetEnvironmentMap("metal_env_map.png"); pbr.SetAmbientOcclusionMap("metal_ambient_occlusion_map.png"); pbr.SetEmissiveMap("metal_emissive_map.png"); + pbr.SetLightMap("metal_light_map.png", 3u); pbr.SetRoughnessMap("roughness_map.png"); pbr.SetMetalnessMap("metalness_map.png"); pbr.SetRoughness(0.8); @@ -136,6 +146,8 @@ TEST(Pbr, MoveCopy) EXPECT_EQ("metal_ambient_occlusion_map.png", pbr2.AmbientOcclusionMap()); EXPECT_EQ("metal_emissive_map.png", pbr2.EmissiveMap()); + EXPECT_EQ("metal_light_map.png", pbr2.LightMap()); + EXPECT_EQ(3u, pbr2.LightMapTexCoordSet()); EXPECT_EQ("roughness_map.png", pbr2.RoughnessMap()); EXPECT_EQ("metalness_map.png", pbr2.MetalnessMap()); EXPECT_DOUBLE_EQ(0.8, pbr2.Roughness()); @@ -156,6 +168,7 @@ TEST(Pbr, MoveCopy) pbr.SetEnvironmentMap("metal_env_map.png"); pbr.SetAmbientOcclusionMap("metal_ambient_occlusion_map.png"); pbr.SetEmissiveMap("metal_emissive_map.png"); + pbr.SetLightMap("metal_light_map.png", 1u); pbr.SetRoughnessMap("roughness_map.png"); pbr.SetMetalnessMap("metalness_map.png"); pbr.SetRoughness(0.8); @@ -171,6 +184,8 @@ TEST(Pbr, MoveCopy) EXPECT_EQ("metal_ambient_occlusion_map.png", pbr2.AmbientOcclusionMap()); EXPECT_EQ("metal_emissive_map.png", pbr2.EmissiveMap()); + EXPECT_EQ("metal_light_map.png", pbr2.LightMap()); + EXPECT_EQ(1u, pbr2.LightMapTexCoordSet()); EXPECT_EQ("roughness_map.png", pbr2.RoughnessMap()); EXPECT_EQ("metalness_map.png", pbr2.MetalnessMap()); EXPECT_DOUBLE_EQ(0.8, pbr2.Roughness()); @@ -191,6 +206,7 @@ TEST(Pbr, MoveCopy) pbr.SetEnvironmentMap("metal_env_map.png"); pbr.SetAmbientOcclusionMap("metal_ambient_occlusion_map.png"); pbr.SetEmissiveMap("metal_emissive_map.png"); + pbr.SetLightMap("metal_light_map.png", 2u); pbr.SetRoughnessMap("roughness_map.png"); pbr.SetMetalnessMap("metalness_map.png"); pbr.SetRoughness(0.18); @@ -205,6 +221,8 @@ TEST(Pbr, MoveCopy) EXPECT_EQ("metal_ambient_occlusion_map.png", pbr2.AmbientOcclusionMap()); EXPECT_EQ("metal_emissive_map.png", pbr2.EmissiveMap()); + EXPECT_EQ("metal_light_map.png", pbr2.LightMap()); + EXPECT_EQ(2u, pbr2.LightMapTexCoordSet()); EXPECT_EQ("roughness_map.png", pbr2.RoughnessMap()); EXPECT_EQ("metalness_map.png", pbr2.MetalnessMap()); EXPECT_DOUBLE_EQ(0.18, pbr2.Roughness());