diff --git a/indra/llinventory/llsettingssky.cpp b/indra/llinventory/llsettingssky.cpp
index 41e888218157fefb8c2b38950e50412916f3c4d9..c41944bdbba22ee2efb8b8debd317b39180f6dc8 100644
--- a/indra/llinventory/llsettingssky.cpp
+++ b/indra/llinventory/llsettingssky.cpp
@@ -33,9 +33,8 @@
 #include "v3colorutil.h"
 
 //=========================================================================
-namespace {
-    const F32 NIGHTTIME_ELEVATION = 8.0f; // degrees
-    const F32 NIGHTTIME_ELEVATION_SIN = (F32)sinf(NIGHTTIME_ELEVATION * DEG_TO_RAD);
+namespace
+{
     const LLUUID IMG_BLOOM1("3c59f7fe-9dc8-47f9-8aaf-a9dd1fbc3bef");
     const LLUUID IMG_RAINBOW("11b4c57c-56b3-04ed-1f82-2004363882e4");
     const LLUUID IMG_HALO("12149143-f599-91a7-77ac-b52a3c0f59cd");
@@ -958,15 +957,15 @@ F32 LLSettingsSky::getSunMoonGlowFactor() const
     LLVector3 moonDir = getMoonDirection();
 
     // sun glow at full iff moon is not up
-    if (sunDir.mV[VZ] > -NIGHTTIME_ELEVATION_SIN)
+    if (getIsSunUp())
     {
-        if (moonDir.mV[2] <= 0.0f)
+        if (!getIsMoonUp())
         {
             return 1.0f;
         }
     }
 
-    if (moonDir.mV[2] > 0.0f)
+    if (getIsMoonUp())
     {
         return 0.25f;
     }
@@ -977,13 +976,13 @@ F32 LLSettingsSky::getSunMoonGlowFactor() const
 bool LLSettingsSky::getIsSunUp() const
 {
     LLVector3 sunDir = getSunDirection();
-    return (sunDir.mV[2] >= 0.0f) || ((sunDir.mV[2] > -NIGHTTIME_ELEVATION_SIN) && !getIsMoonUp());
+    return sunDir.mV[2] >= 0.0f || !getIsMoonUp();
 }
 
 bool LLSettingsSky::getIsMoonUp() const
 {
     LLVector3 moonDir = getMoonDirection();
-    return moonDir.mV[2] > 0.0f;
+    return moonDir.mV[2] >= 0.0f;
 }
 
 void LLSettingsSky::calculateHeavenlyBodyPositions()  const
@@ -997,10 +996,19 @@ void LLSettingsSky::calculateHeavenlyBodyPositions()  const
     mSunDirection.normalize();
     mMoonDirection.normalize();
 
-    if (mSunDirection.lengthSquared() < 0.01f)
-        LL_WARNS("SETTINGS") << "Zero length sun direction. Wailing and gnashing of teeth may follow... or not." << LL_ENDL;
-    if (mMoonDirection.lengthSquared() < 0.01f)
-        LL_WARNS("SETTINGS") << "Zero length moon direction. Wailing and gnashing of teeth may follow... or not." << LL_ENDL;
+    // find out about degen math earlier rather than later
+    llassert(mSunDirection.length()  >= 0.9f);
+    llassert(mMoonDirection.length() >= 0.9f);
+
+    if (mSunDirection.lengthSquared() < 0.9f)
+    {
+        LL_WARNS("SETTINGS") << "Invalid sun direction." << LL_ENDL;
+    }
+
+    if (mMoonDirection.lengthSquared() < 0.9f)
+    {
+        LL_WARNS("SETTINGS") << "Invalid moon direction." << LL_ENDL;
+    }
 }
 
 LLVector3 LLSettingsSky::getLightDirection() const
@@ -1280,9 +1288,9 @@ void LLSettingsSky::calculateLightSettings() const
 
     // and vary_sunlight will work properly with moon light
     F32 lighty = lightnorm[2];
-    if(lighty > 0.001f)
+    if(fabs(lighty) > 0.001f)
     {
-        lighty = 1.f / lighty;
+        lighty = 1.f / fabs(lighty);
     }
     lighty = llmax(0.001f, lighty);
     componentMultBy(sunlight, componentExp((light_atten * -1.f) * lighty));
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
index e8400ba66da4922ba749f440b1313ee6a2cb96f4..8709053ac61302abed7096a3928af33db833311f 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
@@ -201,7 +201,6 @@ void main()
  
     float final_da = da;
           final_da = clamp(final_da, 0.0f, 1.0f);
-		  final_da = pow(final_da, 1.0/1.3);
 
     vec4 color = vec4(0,0,0,0);
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
index f1dbf4af46d6c110a17fd946af0296484d5ad84b..5926236fd71a4bb92463601553fdd75341cde603 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
@@ -302,7 +302,6 @@ void main()
 
     float final_da = da;
           final_da = clamp(final_da, 0.0, 1.0);
-          final_da = pow(final_da, 1.0 / 1.3);
 
     float ambient = da;
     ambient *= 0.5;
@@ -372,6 +371,8 @@ vec3 post_spec = col.rgb;
         glare += cur_glare;
     }
 
+vec3 post_env = col.rgb;
+
     col = atmosFragLighting(col, additive, atten);
     col = scaleSoftClipFrag(col);
 
@@ -379,7 +380,7 @@ vec3 post_spec = col.rgb;
             
     vec3 light = vec3(0,0,0);
 
-    vec3 prelight_linearish_maybe = srgb_to_linear(col.rgb);
+vec3 post_atmo = col.rgb;
 
  #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w * 0.5);
 
@@ -393,7 +394,7 @@ vec3 post_spec = col.rgb;
 
 vec3 light_linear = light.rgb;
 
-    col.rgb += light.rgb;
+    col.rgb += light_linear;
 
 vec3 postlight_linear = col.rgb;
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
index 68deedd0d0296b7613c0bdbca4d2daf1b50ea8e7..83006c891698f8382c951c49f5bd734e48828a7c 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
@@ -108,7 +108,7 @@ void main()
         vec3 atten;
 
         calcAtmosphericVars(pos.xyz, 1.0, sunlit, amblit, additive, atten);
-        sunlit *= 0.5;
+
         float ambient = da;
         ambient *= 0.5;
         ambient *= ambient;
diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
index dd70790fc30ae6bde543553960182852c85f49b8..2d5d1c1b50900f9690c59734271e8cccbedf2854 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
@@ -120,7 +120,7 @@ void main()
         vec3 atten;
     
         calcAtmosphericVars(pos.xyz, ambocc, sunlit, amblit, additive, atten);
-        sunlit *= 0.5;
+
         float ambient = da;
         ambient *= 0.5;
         ambient *= ambient;
diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl
index b19f4e96ca3839fe92df1b8b06ce552bb2715c90..efe7f69f21349ddd69f505f4b053892251ff2ce9 100644
--- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl
+++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl
@@ -28,10 +28,9 @@
 // All lights, no specular highlights
 
 vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight);
-vec3 atmosAmbient(vec3 c);
+
 vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseLight)
 {
- 	vec4 l = sumLights(pos, norm, color, baseLight);
-    return l;
+	return sumLights(pos, norm, color, baseLight) * 2.0f;
 }
 
diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp
index ebfdc38d507cc5ec50c6519532693339d5a68341..0bd4a5eae076f4ecef0e2620ed43420fad0be8e1 100644
--- a/indra/newview/llviewershadermgr.cpp
+++ b/indra/newview/llviewershadermgr.cpp
@@ -478,7 +478,8 @@ void LLViewerShaderMgr::setShaders()
 		//using shaders, disable fixed function
 		LLGLSLShader::sNoFixedFunction = true;
 
-		S32 light_class = 2;
+		S32 light_class = 3;
+        S32 interface_class = 2;
 		S32 env_class = 2;
 		S32 obj_class = 2;
 		S32 effect_class = 2;
@@ -519,6 +520,10 @@ void LLViewerShaderMgr::setShaders()
             // windlight shaders to stub versions.
             wl_class = 2;
         }
+        else
+        {
+            light_class = 2;
+        }
 
 		// Trigger a full rebuild of the fallback skybox / cubemap if we've toggled windlight shaders
 		if (mShaderLevel[SHADER_WINDLIGHT] != wl_class && gSky.mVOSkyp.notNull())
@@ -528,7 +533,7 @@ void LLViewerShaderMgr::setShaders()
 
 		// Load lighting shaders
 		mShaderLevel[SHADER_LIGHTING] = light_class;
-		mShaderLevel[SHADER_INTERFACE] = light_class;
+		mShaderLevel[SHADER_INTERFACE] = interface_class;
 		mShaderLevel[SHADER_ENVIRONMENT] = env_class;
 		mShaderLevel[SHADER_WATER] = water_class;
 		mShaderLevel[SHADER_OBJECT] = obj_class;