fix: align sun altitude with sunrise sunset

This commit is contained in:
Richard Zink committed 2026-10-14 07:48:52 +02:00
1 parent e1343fdf11
commit 8a4884a377
1 file changed
+13 -6
+13 -6
View File
@@ -684,6 +684,11 @@ window.addEventListener('resize', scheduleFitInfoPanel);
var SITE_LAT = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lat) || 51.5074; var SITE_LAT = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lat) || 51.5074;
var SITE_LON = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lon) || -0.1278; var SITE_LON = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lon) || -0.1278;
// SunCalc.getPosition returns the geometric centre altitude. The
// scene's sunrise/sunset times use the standard apparent upper-limb
// altitude (-0.833 deg: refraction + solar semidiameter), so the
// lighting altitude is shifted by the same amount.
var SUN_HORIZON_CORR_RAD = 0.833 * Math.PI / 180;
var realDayProgress = 0; var realDayProgress = 0;
@@ -923,14 +928,15 @@ window.sunPalettes = [
function getColor(t) { function getColor(t) {
var now = sceneNow(); var now = sceneNow();
var sunPos = SunCalc.getPosition(now, SITE_LAT, SITE_LON); var sunPos = SunCalc.getPosition(now, SITE_LAT, SITE_LON);
var sunAlt = sunPos.altitude + SUN_HORIZON_CORR_RAD;
var moonIllum = SunCalc.getMoonIllumination(now); var moonIllum = SunCalc.getMoonIllumination(now);
// The day palette covers sunAlt down to sunPalettes[0].alt // The day palette covers sunAlt down to sunPalettes[0].alt
// (-pi/2, deep below horizon). Only below that do we hand off // (-pi/2, deep below horizon). Only below that do we hand off
// to the moon-based night palette. This makes twilight a // to the moon-based night palette. This makes twilight a
// smooth transition through the day palette entries. // smooth transition through the day palette entries.
if (sunPos.altitude > window.sunPalettes[0].alt) { if (sunAlt > window.sunPalettes[0].alt) {
return getDayColor(sunPos.altitude); return getDayColor(sunAlt);
} else { } else {
return getNightColor(moonIllum); return getNightColor(moonIllum);
} }
@@ -1986,7 +1992,8 @@ window.weatherThemes = {
// Sun altitude in radians. Negative = below horizon (night). // Sun altitude in radians. Negative = below horizon (night).
var _sunNow = sceneNow(); var _sunNow = sceneNow();
var _sunPos = SunCalc.getPosition(_sunNow, SITE_LAT, SITE_LON); var _sunPos = SunCalc.getPosition(_sunNow, SITE_LAT, SITE_LON);
window.__currentSunAlt = _sunPos.altitude; var _sunAlt = _sunPos.altitude + SUN_HORIZON_CORR_RAD;
window.__currentSunAlt = _sunAlt;
window.__currentSceneDate = _sunNow; window.__currentSceneDate = _sunNow;
window.__flightDow = _sunNow.getDay(); window.__flightDow = _sunNow.getDay();
// Unit vector towards the sun in world space. SunCalc azimuth // Unit vector towards the sun in world space. SunCalc azimuth
@@ -1995,9 +2002,9 @@ window.weatherThemes = {
// World frame: +X = west, +Z = north, +Y = up -> east is -X. // World frame: +X = west, +Z = north, +Y = up -> east is -X.
var _sunBearingR = _sunPos.azimuth + Math.PI; var _sunBearingR = _sunPos.azimuth + Math.PI;
window.__currentSunDir = [ window.__currentSunDir = [
-Math.cos(_sunPos.altitude) * Math.sin(_sunBearingR), -Math.cos(_sunAlt) * Math.sin(_sunBearingR),
Math.sin(_sunPos.altitude), Math.sin(_sunAlt),
Math.cos(_sunPos.altitude) * Math.cos(_sunBearingR) Math.cos(_sunAlt) * Math.cos(_sunBearingR)
]; ];
// ---- Local sidereal time ------------------------------------- // ---- Local sidereal time -------------------------------------
// Same formula SunCalc uses internally (Meeus): GMST in degrees // Same formula SunCalc uses internally (Meeus): GMST in degrees