From c39acbccb9813704906a065535715212519aca4a Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 4 Feb 2021 18:54:47 +0100 Subject: [PATCH 1/2] Added lights intensity field Signed-off-by: ahcorde --- include/sdf/Light.hh | 8 ++++++++ sdf/1.8/light.sdf | 4 ++++ src/Light.cc | 19 +++++++++++++++++++ src/Light_TEST.cc | 12 ++++++++++++ test/integration/light_dom.cc | 3 +++ test/sdf/world_complete.sdf | 1 + 6 files changed, 47 insertions(+) diff --git a/include/sdf/Light.hh b/include/sdf/Light.hh index 41b875287..2952bd754 100644 --- a/include/sdf/Light.hh +++ b/include/sdf/Light.hh @@ -147,6 +147,14 @@ namespace sdf /// \param[in] _cast True to indicate that the light casts shadows. public: void SetCastShadows(const bool _cast); + /// \brief Get the light intensity + /// \return The light intensity + public: double Intensity() const; + + /// \brief Set the light intensity + /// \param[in] _intensity New light intensity + public: void SetIntensity(const double _intensity); + /// \brief Get the diffuse color. The diffuse color is /// specified by a set of three numbers representing red/green/blue, /// each in the range of [0,1]. diff --git a/sdf/1.8/light.sdf b/sdf/1.8/light.sdf index e1c0436b0..c9e1f237b 100644 --- a/sdf/1.8/light.sdf +++ b/sdf/1.8/light.sdf @@ -14,6 +14,10 @@ When true, the light will cast shadows. + + Scale factor to set the relative power of a light. + + diff --git a/src/Light.cc b/src/Light.cc index 98b8c453c..87b9fa15b 100644 --- a/src/Light.cc +++ b/src/Light.cc @@ -51,6 +51,9 @@ class sdf::LightPrivate /// \brief True if the light should cast shadows. public: bool castShadows = false; + /// \brief Spot light falloff. + public: double intensity = 1.0; + /// \brief The attenation range. public: double attenuationRange = 10.0; @@ -140,6 +143,7 @@ void Light::CopyFrom(const Light &_light) this->dataPtr->spotInnerAngle = _light.dataPtr->spotInnerAngle; this->dataPtr->spotOuterAngle = _light.dataPtr->spotOuterAngle; this->dataPtr->spotFalloff = _light.dataPtr->spotFalloff; + this->dataPtr->intensity = _light.dataPtr->intensity; } ///////////////////////////////////////////////// @@ -195,6 +199,9 @@ Errors Light::Load(ElementPtr _sdf) this->dataPtr->castShadows = _sdf->Get("cast_shadows", this->dataPtr->castShadows).first; + this->dataPtr->intensity = _sdf->Get("intensity", + this->dataPtr->intensity).first; + this->dataPtr->diffuse = _sdf->Get("diffuse", this->dataPtr->diffuse).first; @@ -340,6 +347,18 @@ sdf::ElementPtr Light::Element() const return this->dataPtr->sdf; } +///////////////////////////////////////////////// +double Light::Intensity() const +{ + return this->dataPtr->intensity; +} + +///////////////////////////////////////////////// +void Light::SetIntensity(const double _intensity) +{ + this->dataPtr->intensity = _intensity; +} + ///////////////////////////////////////////////// bool Light::CastShadows() const { diff --git a/src/Light_TEST.cc b/src/Light_TEST.cc index 238b411a0..758cf7955 100644 --- a/src/Light_TEST.cc +++ b/src/Light_TEST.cc @@ -98,6 +98,10 @@ TEST(DOMLight, DefaultConstruction) EXPECT_DOUBLE_EQ(0.0, light.SpotFalloff()); light.SetSpotFalloff(4.3); EXPECT_DOUBLE_EQ(4.3, light.SpotFalloff()); + + EXPECT_DOUBLE_EQ(1.0, light.Intensity()); + light.SetIntensity(0.3); + EXPECT_DOUBLE_EQ(0.3, light.Intensity()); } ///////////////////////////////////////////////// @@ -119,6 +123,7 @@ TEST(DOMLight, CopyConstructor) light.SetSpotInnerAngle(1.9); light.SetSpotOuterAngle(3.3); light.SetSpotFalloff(0.9); + light.SetIntensity(1.7); sdf::Light light2(light); EXPECT_EQ("test_copy_light", light2.Name()); @@ -136,6 +141,7 @@ TEST(DOMLight, CopyConstructor) EXPECT_EQ(ignition::math::Angle(1.9), light2.SpotInnerAngle()); EXPECT_EQ(ignition::math::Angle(3.3), light2.SpotOuterAngle()); EXPECT_DOUBLE_EQ(0.9, light2.SpotFalloff()); + EXPECT_DOUBLE_EQ(1.7, light2.Intensity()); } ///////////////////////////////////////////////// @@ -157,6 +163,7 @@ TEST(DOMLight, CopyAssignmentOperator) light.SetSpotInnerAngle(1.9); light.SetSpotOuterAngle(3.3); light.SetSpotFalloff(0.9); + light.SetIntensity(1.7); sdf::Light light2; light2 = light; @@ -175,6 +182,7 @@ TEST(DOMLight, CopyAssignmentOperator) EXPECT_EQ(ignition::math::Angle(1.9), light2.SpotInnerAngle()); EXPECT_EQ(ignition::math::Angle(3.3), light2.SpotOuterAngle()); EXPECT_DOUBLE_EQ(0.9, light2.SpotFalloff()); + EXPECT_DOUBLE_EQ(1.7, light2.Intensity()); } ///////////////////////////////////////////////// @@ -196,6 +204,7 @@ TEST(DOMLight, MoveConstructor) light.SetSpotInnerAngle(1.9); light.SetSpotOuterAngle(3.3); light.SetSpotFalloff(0.9); + light.SetIntensity(1.7); sdf::Light light2(std::move(light)); EXPECT_EQ("test_light_assignment", light2.Name()); @@ -213,6 +222,7 @@ TEST(DOMLight, MoveConstructor) EXPECT_EQ(ignition::math::Angle(1.9), light2.SpotInnerAngle()); EXPECT_EQ(ignition::math::Angle(3.3), light2.SpotOuterAngle()); EXPECT_DOUBLE_EQ(0.9, light2.SpotFalloff()); + EXPECT_DOUBLE_EQ(1.7, light2.Intensity()); } ///////////////////////////////////////////////// @@ -234,6 +244,7 @@ TEST(DOMLight, MoveAssignment) light.SetSpotInnerAngle(1.9); light.SetSpotOuterAngle(3.3); light.SetSpotFalloff(0.9); + light.SetIntensity(1.7); sdf::Light light2; light2 = std::move(light); @@ -252,6 +263,7 @@ TEST(DOMLight, MoveAssignment) EXPECT_EQ(ignition::math::Angle(1.9), light2.SpotInnerAngle()); EXPECT_EQ(ignition::math::Angle(3.3), light2.SpotOuterAngle()); EXPECT_DOUBLE_EQ(0.9, light2.SpotFalloff()); + EXPECT_DOUBLE_EQ(1.7, light2.Intensity()); } ///////////////////////////////////////////////// diff --git a/test/integration/light_dom.cc b/test/integration/light_dom.cc index e2d4e8396..d5bb554a6 100644 --- a/test/integration/light_dom.cc +++ b/test/integration/light_dom.cc @@ -59,6 +59,7 @@ TEST(DOMWorld, LoadLights) EXPECT_DOUBLE_EQ(1.0, pointLight->LinearAttenuationFactor()); EXPECT_DOUBLE_EQ(0.0, pointLight->ConstantAttenuationFactor()); EXPECT_DOUBLE_EQ(20.2, pointLight->QuadraticAttenuationFactor()); + EXPECT_DOUBLE_EQ(1.0, pointLight->Intensity()); const sdf::Light *spotLight = world->LightByIndex(1); ASSERT_NE(nullptr, spotLight); @@ -68,6 +69,7 @@ TEST(DOMWorld, LoadLights) EXPECT_DOUBLE_EQ(0.1, spotLight->SpotInnerAngle().Radian()); EXPECT_DOUBLE_EQ(0.5, spotLight->SpotOuterAngle().Radian()); EXPECT_DOUBLE_EQ(2.2, spotLight->SpotFalloff()); + EXPECT_DOUBLE_EQ(1.0, spotLight->Intensity()); const sdf::Light *dirLight = world->LightByIndex(2); ASSERT_NE(nullptr, dirLight); @@ -84,6 +86,7 @@ TEST(DOMWorld, LoadLights) EXPECT_DOUBLE_EQ(0.0, dirLight->LinearAttenuationFactor()); EXPECT_DOUBLE_EQ(1.0, dirLight->ConstantAttenuationFactor()); EXPECT_DOUBLE_EQ(0.0, dirLight->QuadraticAttenuationFactor()); + EXPECT_DOUBLE_EQ(1.8, dirLight->Intensity()); const sdf::Model *model = world->ModelByIndex(0); ASSERT_NE(nullptr, model); diff --git a/test/sdf/world_complete.sdf b/test/sdf/world_complete.sdf index e0004de8e..07612318f 100644 --- a/test/sdf/world_complete.sdf +++ b/test/sdf/world_complete.sdf @@ -58,6 +58,7 @@ 2.0 -100.2 + 1.8 From 8450435f9d4e1fb6643a4cbc7baebb63a537e2c2 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 5 Feb 2021 08:01:17 +0100 Subject: [PATCH 2/2] Updated comment Signed-off-by: ahcorde --- src/Light.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Light.cc b/src/Light.cc index 87b9fa15b..1882b5d98 100644 --- a/src/Light.cc +++ b/src/Light.cc @@ -51,7 +51,7 @@ class sdf::LightPrivate /// \brief True if the light should cast shadows. public: bool castShadows = false; - /// \brief Spot light falloff. + /// \brief Light intensity public: double intensity = 1.0; /// \brief The attenation range.