local transforms = asset.require("./earth")



-- local earthEllipsoid = { 6378137.0, 6378137.0, 6356752.314245 }
local earthEllipsoid = { 6378137.0, 6378137.0, 6378137.0 }
local Atmosphere = {
  Identifier = "EarthAtmosphere",
  Parent = transforms.Earth.Identifier,
  Renderable = {
    Type = "RenderableAtmosphere",
    -- Atmosphere radius in Km
    AtmosphereHeight = 6447.0 - 6377.0,
    PlanetRadius = 6377.0,
    PlanetAverageGroundReflectance = 0.1,
    GroundRadianceEmission = 0.6,
    SunIntensity = 6.9,
    Rayleigh = {
      Coefficients = {
        -- Wavelengths are given in 10^-9m
        Wavelengths = { 680, 550, 440 },
        -- Reflection coefficients are given in km^-1
        Scattering = { 5.8E-3, 13.5E-3, 33.1E-3 },
        -- In Rayleigh scattering, the coefficients of absorption and scattering are the same.
      },
      -- Thickness of atmosphere if its density were uniform, in Km
      H_R = 8.0
    },
    --[[
      Ozone = {
      Coefficients = {
        -- Extinction coefficients 
        Extinction = {3.426, 8.298, 0.356}
      },
      H_O = 8.0,
    },
    ]]
    -- Default
    Mie = {
      Coefficients = {
        -- Reflection coefficients are given in km^-1
        Scattering = { 4.0e-3, 4.0e-3, 4.0e-3 },
        -- Extinction coefficients are a fraction of the Mie coefficients
        Extinction = { 4.0e-3/0.9, 4.0e-3/0.9, 4.0e-3/0.9 }
      },
      -- Height scale (atmosphere thickness for constant density) in Km
      H_M = 1.2,
      -- Mie Phase Function Value (G e [-1.0, 1.0]. If G = 1.0, Mie phase function = Rayleigh Phase Function)
      G = 0.85
    },
    -- Clear Sky
    -- Mie = {
    --     Coefficients = {
    --         Scattering = {20e-3, 20e-3, 20e-3},
    --         Extinction = 1.0/0.9,
    --      }
    --     H_M = 1.2,
    --     G = 0.76,
    -- },
    -- Cloudy
    -- Mie = {
    --     Coefficients = {
    --         Scattering = {3e-3, 3e-3, 3e-3},
    --         Extinction = 1.0/0.9,
    --      }
    --     H_M = 3.0,
    --     G = 0.65,
    -- },
    Debug = {
      PreCalculatedTextureScale = 1.0,
      SaveCalculatedTextures = false
    },
    ShadowGroup = {
      Sources = {
        { Name = "Sun", Radius = 696.3E6 },
        -- { Name = "Monolith", Radius = 0.01E6 }
      },
      Casters = {
        { Name = "Moon", Radius = 1.737E6 },
        -- { Name = "Independence Day Ship", Radius = 0.0 }
      }
    }
  },
  GUI = {
    Name = "Earth Atmosphere",
    Path = "/Solar System/Planets/Earth",
    Description = "Atmosphere of Earth"
  }
}

asset.onInitialize(function()
  openspace.addSceneGraphNode(Atmosphere)
end)
  
asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(Atmosphere)
end)
  
asset.export(Atmosphere)



asset.meta = {
  Name = "Earth Atmosphere",
  Version = "1.1",
  Description = "RenderableAtmosphere for Earth",
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT license"
}
