From b469511ce3333d9fa7c2f394222f419b1e263683 Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Sat, 14 Sep 2019 00:58:01 +0300 Subject: [PATCH] Use bolometric luminosity to calculate comet's tail fading Closes: #405 --- src/celengine/render.cpp | 30 ++++++++++++++++++------------ src/celengine/render.h | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/celengine/render.cpp b/src/celengine/render.cpp index 2e42b566..4ca1f2b5 100644 --- a/src/celengine/render.cpp +++ b/src/celengine/render.cpp @@ -1963,7 +1963,7 @@ void Renderer::renderItem(const RenderListEntry& rle, case RenderListEntry::RenderableCometTail: renderCometTail(*rle.body, rle.position, - observer.getTime(), + observer, rle.discSizeInPixels); break; @@ -5541,9 +5541,11 @@ static float cometDustTailLength(float distanceToSun, // TODO: Remove unused parameters?? void Renderer::renderCometTail(const Body& body, const Vector3f& pos, - double now, + const Observer& observer, float discSizeInPixels) { + double now = observer.getTime(); + Vector3f cometPoints[MaxCometTailPoints]; Vector3d pos0 = body.getOrbit(now)->positionAtTime(now); #if 0 @@ -5553,8 +5555,6 @@ void Renderer::renderCometTail(const Body& body, double t = now; float distanceFromSun, irradiance_max = 0.0f; - unsigned int li_eff = 0; // Select the first sun as default to - // shut up compiler warnings // Adjust the amount of triangles used for the comet tail based on // the screen size of the comet. @@ -5565,21 +5565,27 @@ void Renderer::renderCometTail(const Body& body, // Find the sun with the largest irrradiance of light onto the comet // as function of the comet's position; // irradiance = sun's luminosity / square(distanceFromSun); - - for (unsigned int li = 0; li < lightSourceList.size(); li++) + Vector3d sunPos(Vector3d::Zero()); + for (const auto star : nearStars) { - distanceFromSun = (float) (pos.cast() - lightSourceList[li].position).norm(); - float irradiance = lightSourceList[li].luminosity / square(distanceFromSun); - if (irradiance > irradiance_max) + if (star->getVisibility()) { - li_eff = li; - irradiance_max = irradiance; + Vector3d p = star->getPosition(t).offsetFromKm(observer.getPosition()); + distanceFromSun = (float) (pos.cast() - p).norm(); + float irradiance = star->getBolometricLuminosity() / square(distanceFromSun); + + if (irradiance > irradiance_max) + { + irradiance_max = irradiance; + sunPos = p; + } } } + float fadeDistance = 1.0f / (float) (COMET_TAIL_ATTEN_DIST_SOL * sqrt(irradiance_max)); // direction to sun with dominant light irradiance: - Vector3f sunDir = (pos.cast() - lightSourceList[li_eff].position).cast().normalized(); + Vector3f sunDir = (pos.cast() - sunPos).cast().normalized(); float dustTailLength = cometDustTailLength((float) pos0.norm(), body.getRadius()); float dustTailRadius = dustTailLength * 0.1f; diff --git a/src/celengine/render.h b/src/celengine/render.h index fcc24731..40f811df 100644 --- a/src/celengine/render.h +++ b/src/celengine/render.h @@ -527,7 +527,7 @@ class Renderer void renderCometTail(const Body& body, const Eigen::Vector3f& pos, - double now, + const Observer& observer, float discSizeInPixels); void renderObjectAsPoint_nosprite(const Eigen::Vector3f& center,