From f16c355d117ebfc10abf43b38f913c0ca4f0473b Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Mon, 8 Mar 2021 12:36:31 +0200 Subject: [PATCH] Add a new body parameter "reflectivity" complementing albedos --- src/celengine/body.cpp | 15 ++++++++++++++- src/celengine/body.h | 7 +++++-- src/celengine/render.cpp | 2 +- src/celengine/solarsys.cpp | 30 +++++++++++++++++++++++++++--- src/celscript/lua/celx_object.cpp | 3 +++ 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/celengine/body.cpp b/src/celengine/body.cpp index b4fd75ea0..74e06b3fc 100644 --- a/src/celengine/body.cpp +++ b/src/celengine/body.cpp @@ -79,6 +79,7 @@ void Body::setDefaultProperties() density = 0.0f; bondAlbedo = 0.5f; geomAlbedo = 0.5f; + reflectivity = 0.5f; temperature = 0.0f; tempDiscrepancy = 0.0f; geometryOrientation = Quaternionf::Identity(); @@ -347,6 +348,18 @@ void Body::setBondAlbedo(float _bondAlbedo) } +float Body::getReflectivity() const +{ + return reflectivity; +} + + +void Body::setReflectivity(float _reflectivity) +{ + reflectivity = _reflectivity; +} + + float Body::getTemperature(double time) const { if (temperature > 0) @@ -789,7 +802,7 @@ float Body::getLuminosity(float sunLuminosity, // Compute the total energy hitting the planet double incidentEnergy = satIrradiance * circleArea(radius * 1000); - double reflectedEnergy = incidentEnergy * geomAlbedo; + double reflectedEnergy = incidentEnergy * getReflectivity(); // Compute the luminosity (i.e. power relative to solar power) return (float) (reflectedEnergy / astro::SOLAR_POWER); diff --git a/src/celengine/body.h b/src/celengine/body.h index 545b5e036..b96ba9862 100644 --- a/src/celengine/body.h +++ b/src/celengine/body.h @@ -233,12 +233,14 @@ class Body : public AstroObject void setDensity(float); // Albedo functions and temperature - /* [[deprecated]] */ float getAlbedo() const; - /* [[deprecated]] */ void setAlbedo(float); + [[deprecated]] float getAlbedo() const; + [[deprecated]] void setAlbedo(float); float getGeomAlbedo() const; void setGeomAlbedo(float); float getBondAlbedo() const; void setBondAlbedo(float); + float getReflectivity() const; + void setReflectivity(float); float getTemperature(double t = 0) const; void setTemperature(float); float getTempDiscrepancy() const; @@ -392,6 +394,7 @@ class Body : public AstroObject float density{ 0.0f }; float geomAlbedo{ 0.5f }; float bondAlbedo{ 0.5f }; + float reflectivity{ 0.5f }; float temperature{ 0.0f }; float tempDiscrepancy{ 0.0f }; diff --git a/src/celengine/render.cpp b/src/celengine/render.cpp index 17a67ae75..66595ce0d 100644 --- a/src/celengine/render.cpp +++ b/src/celengine/render.cpp @@ -1513,7 +1513,7 @@ setupSecondaryLightSources(vector& secondaryIlluminators, i.reflectedIrradiance += j.luminosity / ((float) (i.position_v - j.position).squaredNorm() * au2); } - i.reflectedIrradiance *= i.body->getAlbedo(); + i.reflectedIrradiance *= i.body->getReflectivity(); } } diff --git a/src/celengine/solarsys.cpp b/src/celengine/solarsys.cpp index 1b2e0bdba..3090d1759 100644 --- a/src/celengine/solarsys.cpp +++ b/src/celengine/solarsys.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include #include @@ -796,7 +798,7 @@ static Body* CreateBody(const string& name, { // Relative URL, the base directory is the current one, // not the main installation directory - const string p = path.string(); + const string &p = path.string(); if (p[1] == ':') // Absolute Windows path, file:/// is required infoURL = "file:///" + p + "/" + infoURL; @@ -814,14 +816,36 @@ static Body* CreateBody(const string& name, } if (planetData->getNumber("GeomAlbedo", t)) - body->setGeomAlbedo((float) t); + { + if (t > 0.0) + { + body->setGeomAlbedo((float) t); + // Set the BondAlbedo and Reflectivity values if it is <1, otherwise as 1. + if (t > 1.0) + t = 1.0; + body->setBondAlbedo((float) t); + body->setReflectivity((float) t); + } + else + { + fmt::print(cerr, _("Incorrect GeomAlbedo value: {}\n"), t); + } + } + + if (planetData->getNumber("Reflectivity", t)) + { + if (t >= 0.0 && t <= 1.0) + body->setReflectivity((float) t); + else + fmt::print(cerr, _("Incorrect Reflectivity value: {}\n"), t); + } if (planetData->getNumber("BondAlbedo", t)) { if (t >= 0.0 && t <= 1.0) body->setBondAlbedo((float) t); else - fmt::fprintf(cerr, "Incorrect BondAlbedo value: %lf\n", t); + fmt::print(cerr, _("Incorrect BondAlbedo value: {}\n"), t); } if (planetData->getNumber("Temperature", t)) diff --git a/src/celscript/lua/celx_object.cpp b/src/celscript/lua/celx_object.cpp index c9f537f8a..8b61b4d47 100644 --- a/src/celscript/lua/celx_object.cpp +++ b/src/celscript/lua/celx_object.cpp @@ -626,6 +626,9 @@ static int object_getinfo(lua_State* l) celx.setTable("name", body->getName().c_str()); celx.setTable("mass", (lua_Number)body->getMass()); celx.setTable("albedo", (lua_Number)body->getAlbedo()); + celx.setTable("geomAlbedo", (lua_Number)body->getGeomAlbedo()); + celx.setTable("bondAlbedo", (lua_Number)body->getBondAlbedo()); + celx.setTable("reflectivity", (lua_Number)body->getReflectivity()); celx.setTable("infoURL", body->getInfoURL().c_str()); celx.setTable("radius", (lua_Number)body->getRadius());