diff --git a/autobuild.xml b/autobuild.xml
index b5e336948aafadaa1a918a025dac6888c277308d..bd1b88b2ebfa7d5d9dc7eac631540c1577e126d6 100644
--- a/autobuild.xml
+++ b/autobuild.xml
@@ -64,9 +64,9 @@
           <key>archive</key>
           <map>
             <key>hash</key>
-            <string>722693009586e18aa4d611218c26c5e3</string>
+            <string>bca20bcdf1a2c26b16e71fb2c1316cbe</string>
             <key>url</key>
-            <string>http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/23969/184338/libatmosphere-1.0.0.100-darwin-519274.tar.bz2</string>
+            <string>http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/24187/188163/libatmosphere-1.0.0.100-darwin-519422.tar.bz2</string>
           </map>
           <key>name</key>
           <string>darwin</string>
@@ -76,9 +76,9 @@
             <key>archive</key>
             <map>
               <key>hash</key>
-              <string>9ecdbb77a18a5dea905ebd3d7faf1f8f</string>
+              <string>9ce4c97f1eda8caa556573abd6e1ebd0</string>
               <key>url</key>
-              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/23968/184333/libatmosphere-1.0.0.100-darwin64-519274.tar.bz2</string>
+              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/24188/188166/libatmosphere-1.0.0.100-darwin64-519422.tar.bz2</string>
             </map>
             <key>name</key>
             <string>darwin64</string>
@@ -88,9 +88,9 @@
             <key>archive</key>
             <map>
               <key>hash</key>
-              <string>05e113c2988bf77dcde7df0216c26481</string>
+              <string>6a61502ab1cca316f85310ded8bf9b9a</string>
               <key>url</key>
-              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/23971/184350/libatmosphere-1.0.0.100-windows-519274.tar.bz2</string>
+              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/24190/188181/libatmosphere-1.0.0.100-windows-519422.tar.bz2</string>
             </map>
             <key>name</key>
             <string>windows</string>
@@ -100,9 +100,9 @@
             <key>archive</key>
             <map>
               <key>hash</key>
-	            <string>1b5fcfbc0123263d68843ac4570c8204</string>
+	            <string>496410cb43e03ddf1777cd295c2d5dba</string>
               <key>url</key>
-	            <string>http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/23970/184345/libatmosphere-1.0.0.100-windows64-519274.tar.bz2</string>
+	            <string>http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/24189/188175/libatmosphere-1.0.0.100-windows64-519422.tar.bz2</string>
             </map>
             <key>name</key>
             <string>windows64</string>
diff --git a/indra/llinventory/llsettingssky.cpp b/indra/llinventory/llsettingssky.cpp
index ba92a821744de5baf902b9e0e56ea90156695a2c..ed8baee2044ebb9515a22d2b49153d8386920d5a 100644
--- a/indra/llinventory/llsettingssky.cpp
+++ b/indra/llinventory/llsettingssky.cpp
@@ -573,11 +573,11 @@ LLSD LLSettingsSky::createDensityProfileLayer(
     F32 aniso_factor)
 {
     LLSD dflt_layer;
-    dflt_layer[SETTING_DENSITY_PROFILE_WIDTH]            = 0.0f; // 0 -> the entire atmosphere
-    dflt_layer[SETTING_DENSITY_PROFILE_EXP_TERM]         = 1.0f;
-    dflt_layer[SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR] = -1.0f / 8000.0f;
-    dflt_layer[SETTING_DENSITY_PROFILE_LINEAR_TERM]      = 0.0f;
-    dflt_layer[SETTING_DENSITY_PROFILE_CONSTANT_TERM]    = 0.0f;
+    dflt_layer[SETTING_DENSITY_PROFILE_WIDTH]            = width; // 0 -> the entire atmosphere
+    dflt_layer[SETTING_DENSITY_PROFILE_EXP_TERM]         = exponential_term;
+    dflt_layer[SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR] = exponential_scale_factor;
+    dflt_layer[SETTING_DENSITY_PROFILE_LINEAR_TERM]      = linear_term;
+    dflt_layer[SETTING_DENSITY_PROFILE_CONSTANT_TERM]    = constant_term;
 
     if (aniso_factor != 0.0f)
     {
@@ -670,7 +670,7 @@ LLSD LLSettingsSky::defaults(const LLSettingsBase::TrackPosition& position)
         dfltsetting[SETTING_PLANET_RADIUS]      = 6360.0f;
         dfltsetting[SETTING_SKY_BOTTOM_RADIUS]  = 6360.0f;
         dfltsetting[SETTING_SKY_TOP_RADIUS]     = 6420.0f;
-        dfltsetting[SETTING_SUN_ARC_RADIANS]    = 0.00935f / 2.0f;    
+        dfltsetting[SETTING_SUN_ARC_RADIANS]    = 0.00045f;
 
         dfltsetting[SETTING_RAYLEIGH_CONFIG]    = rayleighConfigDefault();
         dfltsetting[SETTING_MIE_CONFIG]         = mieConfigDefault();
@@ -1160,7 +1160,7 @@ F32 LLSettingsSky::getSunArcRadians() const
 
 F32 LLSettingsSky::getMieAnisotropy() const
 {
-    return mSettings[SETTING_MIE_ANISOTROPY_FACTOR].asReal();
+    return getMieConfig()[SETTING_MIE_ANISOTROPY_FACTOR].asReal();
 }
  
 LLSD LLSettingsSky::getRayleighConfig() const
@@ -1183,20 +1183,17 @@ LLSD LLSettingsSky::getAbsorptionConfig() const
    
 LLSD LLSettingsSky::getRayleighConfigs() const
 {
-    LLSD copy = *(mSettings[SETTING_RAYLEIGH_CONFIG].beginArray());
-    return copy;
+    return mSettings[SETTING_RAYLEIGH_CONFIG];
 }
 
 LLSD LLSettingsSky::getMieConfigs() const
 {
-    LLSD copy = *(mSettings[SETTING_MIE_CONFIG].beginArray());
-    return copy;
+    return mSettings[SETTING_MIE_CONFIG];
 }
 
 LLSD LLSettingsSky::getAbsorptionConfigs() const
 {
-    LLSD copy = *(mSettings[SETTING_ABSORPTION_CONFIG].beginArray());
-    return copy;
+    return mSettings[SETTING_ABSORPTION_CONFIG];
 }
 
 void LLSettingsSky::setRayleighConfigs(const LLSD& rayleighConfig)
diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp
index aaa1ff65e177b2d01f815fcaf0e6d1ea6974984b..12c66853545f923c97667cb13facb4f2f05bfa14 100644
--- a/indra/llrender/llatmosphere.cpp
+++ b/indra/llrender/llatmosphere.cpp
@@ -232,26 +232,6 @@ LLAtmosphere::~LLAtmosphere()
     m_model = nullptr;
 }
 
-#if DEBUG_ATMO_TEX_GEN
-uint8_t* GetTexture2d(int width, int height, int components, GLuint texture)
-{
-    glActiveTextureARB(GL_TEXTURE0);
-    glBindTexture(GL_TEXTURE_2D, texture);
-    uint8_t* storage = (uint8_t*)malloc(width * height * components * sizeof(float));
-    glGetTexImage(GL_TEXTURE_2D, 0, components == 3 ? GL_RGB : GL_RGBA, GL_FLOAT, storage);
-    return storage;
-}
-
-uint8_t* GetTexture3d(int width, int height, int depth, int components, GLuint texture)
-{
-    glActiveTextureARB(GL_TEXTURE0);
-    glBindTexture(GL_TEXTURE_3D, texture);
-    uint8_t* storage = (uint8_t*)malloc(width * height * depth * components * sizeof(float));
-    glGetTexImage(GL_TEXTURE_3D, 0, components == 3 ? GL_RGB : GL_RGBA, GL_FLOAT, storage);
-    return storage;
-}
-#endif
-
 bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings)
 {
     if ((m_model != nullptr) && (settings == m_settings))
@@ -271,8 +251,6 @@ bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings)
     getIlluminance()->setTexName(0);
 
     // Init libatmosphere model
-    m_config.num_scattering_orders = 4;
-
     m_model = new atmosphere::Model(
                                 m_config,
                                 m_wavelengths,
@@ -303,19 +281,7 @@ bool LLAtmosphere::configureAtmosphericModel(AtmosphericModelSettings& settings)
         getScattering()->setTexName(m_textures.scattering_texture);   
         getMieScattering()->setTexName(m_textures.single_mie_scattering_texture);
         getIlluminance()->setTexName(m_textures.illuminance_texture);
-
-#if DEBUG_ATMO_TEX_GEN
-        // for debug only...
-        U8* transmittance         = GetTexture2d(m_config.transmittanceTextureWidth, m_config.transmittanceTextureHeight, 3, m_textures.transmittance_texture);
-        U8* scattering            = GetTexture3d(m_config.scatteringTextureWidth, m_config.scatteringTextureHeight, m_config.scatteringTextureDepth, 3, m_textures.scattering_texture);
-        U8* single_mie_scattering = GetTexture3d(m_config.scatteringTextureWidth, m_config.scatteringTextureHeight, m_config.scatteringTextureDepth, 3, m_textures.single_mie_scattering_texture);
-        U8* illuminance           = GetTexture2d(m_config.illuminanceTextureWidth, m_config.illuminanceTextureHeight, 3, m_textures.illuminance_texture);
-        free(transmittance);
-        free(scattering);
-        free(single_mie_scattering);
-        free(illuminance);
-#endif
-
+        m_settings = settings;
     }
 
     return m_model != nullptr;
diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl
index 90217aed02fae6b41aac78fe72dd4161e9409bbf..89873e83ca0dad22cab03f0b824de7d613b1086b 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl
@@ -36,8 +36,8 @@ VARYING vec2 vary_frag;
 
 void main()
 {
-    // pass through untransformed fullscreen pos (clipspace)
-	gl_Position = vec4(position.xyz, 1.0);
+    // pass through untransformed fullscreen pos at back of frustum for proper sky depth testing
+	gl_Position = vec4(position.xy, 0.99f, 1.0);
     vary_frag = texcoord0;
 }
 
diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp
index 3b3d67243aeb21ac4b21c6a0384558982331e17d..41bf024942fb2dc1b078791603817e6d0ee9d39a 100644
--- a/indra/newview/lldrawpoolwlsky.cpp
+++ b/indra/newview/lldrawpoolwlsky.cpp
@@ -505,22 +505,19 @@ void LLDrawPoolWLSky::renderDeferred(S32 pass)
 
     if (gPipeline.canUseWindLightShaders())
     {
+        if (gPipeline.useAdvancedAtmospherics())
+        {
+	        renderSkyHazeDeferred(origin, camHeightLocal);
+            renderHeavenlyBodies();
+        }
+        else
         {
             // Disable depth-test for sky, but re-enable depth writes for the cloud
             // rendering below so the cloud shader can write out depth for the stars to test against
             LLGLDepthTest depth(GL_TRUE, GL_FALSE);
-            if (gPipeline.useAdvancedAtmospherics())
-            {
-	            renderSkyHazeDeferred(origin, camHeightLocal);
-            }
-            else
-            {
-                renderSkyHaze(origin, camHeightLocal);   
-		        
-            }
-            renderHeavenlyBodies();
+            renderSkyHaze(origin, camHeightLocal);   
+		    renderHeavenlyBodies();
         }
-
         renderSkyClouds(origin, camHeightLocal);
     }    
     gGL.setColorMask(true, true);
diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp
index e437003520f0853d38f612409f267a5502a5f1b9..4b60ed4e682e2f914287952a31bc5f5f63c02f64 100644
--- a/indra/newview/llenvironment.cpp
+++ b/indra/newview/llenvironment.cpp
@@ -358,6 +358,7 @@ void LLEnvironment::getAtmosphericModelSettings(AtmosphericModelSettings& settin
         layer.width             = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_WIDTH].asReal();
         settingsOut.m_mieProfile.push_back(layer);
     }
+    settingsOut.m_mieAnisotropy = psky->getMieAnisotropy();
 
     LLSD absorption = psky->getAbsorptionConfigs();
     settingsOut.m_absorptionProfile.clear();
@@ -1633,15 +1634,12 @@ void LLEnvironment::DayInstance::setSky(const LLSettingsSky::ptr_t &psky)
     mSky->update();
     mBlenderSky.reset();
 
-#if 0
     if (gAtmosphere)
     {
         AtmosphericModelSettings settings;
         LLEnvironment::getAtmosphericModelSettings(settings, psky);
         gAtmosphere->configureAtmosphericModel(settings);
     }
-#endif
-
 }
 
 void LLEnvironment::DayInstance::setWater(const LLSettingsWater::ptr_t &pwater)
diff --git a/indra/newview/llpaneleditsky.cpp b/indra/newview/llpaneleditsky.cpp
index a13efbc54b83370075967f28dc3d1317ee1814d6..1b41529795f4357dc76f587bcd5d74aba9098afc 100644
--- a/indra/newview/llpaneleditsky.cpp
+++ b/indra/newview/llpaneleditsky.cpp
@@ -662,15 +662,12 @@ void LLPanelSettingsSkyDensityTab::updateProfile()
     mSkySettings->update();
     setIsDirty();
 
-/*
     if (gAtmosphere)
     {
         AtmosphericModelSettings atmospheric_settings;
         LLEnvironment::getAtmosphericModelSettings(atmospheric_settings, mSkySettings);
         gAtmosphere->configureAtmosphericModel(atmospheric_settings);
     }
-*/
-
 }
 
 void LLPanelSettingsSkyDensityTab::onRayleighExponentialChanged()
diff --git a/indra/newview/skins/default/xui/en/panel_settings_sky_density.xml b/indra/newview/skins/default/xui/en/panel_settings_sky_density.xml
index 50663e94f6d2c80404225b7c81c564be0226e71d..e071b30c80739d1644048d1fa436758c378c0b26 100644
--- a/indra/newview/skins/default/xui/en/panel_settings_sky_density.xml
+++ b/indra/newview/skins/default/xui/en/panel_settings_sky_density.xml
@@ -24,10 +24,10 @@
                 visible="true"
                 height="14">
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.0000001"
                     initial_value="0"
                     layout="topleft"
                     left_delta="5"
@@ -40,38 +40,38 @@
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.000001"
                     initial_value="0"
                     layout="topleft"
-                    min_val="-1"
-                    max_val="1"
+                    min_val="-0.01"
+                    max_val="0.01"
                     name="rayleigh_exponential_scale"
                     label="Rayleigh Exponential Scale:"
                     width="400"
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.000001"
                     initial_value="0"
                     layout="topleft"
                     min_val="0"
-                    max_val="1"
+                    max_val="0.00001"
                     name="rayleigh_linear"
                     label="Rayleigh Linear Term:"
                     width="400"
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.0000001"
                     initial_value="0"
                     layout="topleft"
                     min_val="0"
@@ -82,10 +82,9 @@
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="1"
                     follows="left|top"
                     height="14"
-                    increment="1"
                     initial_value="0"
                     layout="topleft"
                     min_val="1000"
@@ -104,10 +103,10 @@
                 visible="true"
                 height="16">
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.0000001"
                     initial_value="0"
                     layout="topleft"
                     left_delta="5"
@@ -120,42 +119,42 @@
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.0000001"
                     initial_value="0"
                     layout="topleft"
-                    min_val="-1"
-                    max_val="1"
+                    min_val="-0.01"
+                    max_val="0.01"
                     name="mie_exponential_scale"
                     label="Mie Exponential Scale:"
                     width="400"
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.000001"
                     initial_value="0"
                     layout="topleft"
                     min_val="0"
-                    max_val="3.0"
+                    max_val="0.000004"
                     name="mie_linear"
                     label="Mie Linear Term:"
                     width="400"
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.0000001"
                     initial_value="0"
                     layout="topleft"
                     min_val="0"
-                    max_val="10"
+                    max_val="1"
                     name="mie_constant"
                     label="Mie Constant Term:"
                     width="400"
@@ -176,10 +175,10 @@
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="1"
                     follows="left|top"
                     height="14"
-                    increment="1"
+                    increment="0.1"
                     initial_value="0"
                     layout="topleft"
                     min_val="1000"
@@ -198,10 +197,10 @@
                 visible="true"
                 height="14">
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.0000001"
                     initial_value="0"
                     layout="topleft"
                     left_delta="5"
@@ -214,10 +213,10 @@
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.0000001"
                     initial_value="0"
                     layout="topleft"
                     min_val="-1"
@@ -228,10 +227,10 @@
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.0000001"
                     initial_value="0"
                     layout="topleft"
                     min_val="0"
@@ -242,10 +241,10 @@
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="6"
                     follows="left|top"
                     height="14"
-                    increment="0.01"
+                    increment="0.0000001"
                     initial_value="0"
                     layout="topleft"
                     min_val="0"
@@ -256,10 +255,10 @@
                     label_width="160"
                     can_edit_text="true"/>
             <slider
-                    decimal_digits="2"
+                    decimal_digits="1"
                     follows="left|top"
                     height="14"
-                    increment="1"
+                    increment="0.1"
                     initial_value="0"
                     layout="topleft"
                     min_val="1000"