/***********************************************/
/*           Copyright (c) 2025 Belmu          */
/*             All Rights Reserved             */
/***********************************************/

/* ATMOSPHERIC CONSTANTS */

const float kilo = 1e3;

const float planetRadius          = 6371e3;
const float atmosphereLowerRadius = planetRadius;
const float atmosphereUpperRadius = planetRadius + 110e3;

const vec2 scaleHeights = vec2(8.40, 1.25) * kilo;

const float mieScatteringAlbedo = 0.9;
const float mieAnisotropyFactor = 2800.0; // e asymmetry term

const float turbidity             = 1.1;
const float airNumberDensity      = 2.5035422e25;
const float atmosphereTemperature = 293.15; // Kelvins
const float ozonePeakDensity      = 5e-6;
const float ozonePeakAltitude     = 35e3;
const float ozoneNumberDensity    = airNumberDensity * exp(-ozonePeakAltitude / 8e3) * (134.628 / 48.0) * ozonePeakDensity;
const float ozoneUnitConversion   = 1e-4; // Converts from cm² to m²

vec3 atmosphereRayPosition = vec3(0.0, planetRadius, 0.0) + cameraPosition;

/* CELESTIAL CONSTANTS */

const float sunTemperature = 5778.0; // Kelvins
const float sunRadius      = 6.9634e8;
const float sunDistance    = 1.496e11;

const float moonRadius    = 1.7374e6;
const float moonDistance  = 3.8440e8;
const float moonAlbedo    = 0.14; // The moon reflects approximately 7-14% of the sun's emitted light 
const float moonRoughness = 0.40;

const float sunAngularRadius  = CELESTIAL_SIZE_MULTIPLIER * sunRadius  / sunDistance;
      float moonAngularRadius = CELESTIAL_SIZE_MULTIPLIER * moonRadius / moonDistance;

const vec3 sunIrradiance = vec3(1.0, 0.949, 0.937) * 126e3; // Brightness of light reaching the earth (~126'000 lux)
      vec3 sunRadiance   = sunIrradiance / coneAngleToSolidAngle(sunAngularRadius);

vec3 moonRadiance   = moonAlbedo   * sunIrradiance;
vec3 moonIrradiance = moonRadiance * coneAngleToSolidAngle(moonAngularRadius); // The rough amount of light the moon emits that reaches the earth

float shadowLightAngularRadius = sunAngle < 0.5 ? sunAngularRadius : moonAngularRadius;
