diff --git a/background.html b/background.html
index 863df58..96aabf9 100644
--- a/background.html
+++ b/background.html
@@ -1891,6 +1891,7 @@ window.weatherThemes = {
var _sunNow = sceneNow();
var _sunPos = SunCalc.getPosition(_sunNow, SITE_LAT, SITE_LON);
window.__currentSunAlt = _sunPos.altitude;
+ window.__currentSceneDate = _sunNow;
window.__flightDow = _sunNow.getDay();
// Unit vector towards the sun in world space. SunCalc azimuth
// is measured from the south, positive towards the west, so the
diff --git a/vendor/clouds3d.js b/vendor/clouds3d.js
index 56997c0..bfd5e39 100644
--- a/vendor/clouds3d.js
+++ b/vendor/clouds3d.js
@@ -2484,6 +2484,18 @@ function beamLuma(altRad) {
var c = beamColor(altRad);
return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
}
+// Earth-Sun distance from the simulated scene date. This is not a scene
+// light source: it only scales the solar irradiance entering the top of
+// the atmosphere (perihelion ~+3.4 %, aphelion ~-3.3 %).
+function sunDistanceFactor(date) {
+ var d = date || new Date();
+ var year = d.getUTCFullYear();
+ var start = Date.UTC(year, 0, 0);
+ var day = Math.floor((d.getTime() - start) / 86400000);
+ var g = 2 * Math.PI * (day - 3) / 365.24;
+ var au = 1.0 - 0.0167 * Math.cos(g);
+ return 1.0 / (au * au);
+}
// Diffuse skylight: grows with sun altitude, then decays through civil
// twilight (-6 deg) toward the night floor (airglow + starlight).
function skyAmbient(altRad) {
@@ -5418,6 +5430,8 @@ window.clouds3dRender = function(target) {
? window.__currentMoonDir[1] : 0)));
var _moonFrac = (typeof window.__currentMoonFrac === 'number') ? window.__currentMoonFrac : 0.6;
var _beam = beamColor(sunAlt), _beamL = beamLuma(sunAlt);
+ var _sunDist = sunDistanceFactor(window.__currentSceneDate);
+ _beamL *= _sunDist;
var _star = starAmbient(sunAlt);
var _mBeam = beamColor(_moonAlt), _mL = beamLuma(_moonAlt);
var _moonUp = Math.max(0, Math.sin(_moonAlt));