diff --git a/indra/llinventory/llsettingssky.cpp b/indra/llinventory/llsettingssky.cpp
index e02ecc8a332970dcc3e5a4b20c64d91e124961aa..fecca129053eb65b5fd83232440621f53324e3b4 100644
--- a/indra/llinventory/llsettingssky.cpp
+++ b/indra/llinventory/llsettingssky.cpp
@@ -1246,6 +1246,17 @@ LLColor4 LLSettingsSky::getTotalAmbient() const
     return mTotalAmbient;
 }
 
+LLColor3 LLSettingsSky::getMoonlightColor() const
+{
+    F32 moon_brightness = getIsMoonUp() ? getMoonBrightness() : 0.001f;
+
+    LLColor3 moonlight_a(0.45, 0.45, 0.66);
+    LLColor3 moonlight_b(0.33, 0.33, 1.0);
+
+    LLColor3 moonlight = lerp(moonlight_b, moonlight_a, moon_brightness);    
+    return moonlight;
+}
+
 void LLSettingsSky::calculateLightSettings() const
 {
     // Initialize temp variables
@@ -1278,19 +1289,24 @@ void LLSettingsSky::calculateLightSettings() const
     //brightness of surface both sunlight and ambient
     // reduce range to 0 - 1 before gamma correct to prevent clipping
     // then restore to full 0 - 3 range before storage
-    mSunDiffuse = gammaCorrect(componentMult(sunlight * 0.33333f,   light_transmittance)) * 3.0f;
-    mSunAmbient = gammaCorrect(componentMult(tmpAmbient * 0.33333f, light_transmittance)) * 3.0f;
+    //mSunDiffuse = gammaCorrect(componentMult(sunlight,   light_transmittance));
+    //mSunAmbient = gammaCorrect(componentMult(tmpAmbient, light_transmittance));
+
+    mSunDiffuse = componentMult(sunlight,   light_transmittance);
+    mSunAmbient = componentMult(tmpAmbient, light_transmittance);
 
     F32 moon_brightness = getIsMoonUp() ? getMoonBrightness() : 0.001f;
 
-    LLColor3 moonlight_a(0.45, 0.45, 0.66);
-    LLColor3 moonlight_b(0.33, 0.33, 1.0);
+    LLColor3 moonlight = getMoonlightColor();
+    LLColor3 moonlight_b(0.33, 0.33, 1.0); // scotopic ambient value
 
-    LLColor3 moonlight = lerp(moonlight_b, moonlight_a, moon_brightness);    
     componentMultBy(moonlight, componentExp((light_atten * -1.f) * lighty));
 
-    mMoonDiffuse  = gammaCorrect(componentMult(moonlight, light_transmittance) * moon_brightness);
-    mMoonAmbient  = gammaCorrect(componentMult(moonlight_b, light_transmittance) * 0.0125f);
+    //mMoonDiffuse  = gammaCorrect(componentMult(moonlight, light_transmittance) * moon_brightness);
+    //mMoonAmbient  = gammaCorrect(componentMult(moonlight_b, light_transmittance) * 0.0125f);
+    mMoonDiffuse  = componentMult(moonlight, light_transmittance) * moon_brightness;
+    mMoonAmbient  = componentMult(moonlight_b, light_transmittance) * 0.0125f;
+
     mTotalAmbient = mSunAmbient;
 }
 
diff --git a/indra/llinventory/llsettingssky.h b/indra/llinventory/llsettingssky.h
index ef2a6740f0776948f34b62247a86938c054999e2..92b8a8bd5a19e72dbe7238ce759fb9d22471f9c2 100644
--- a/indra/llinventory/llsettingssky.h
+++ b/indra/llinventory/llsettingssky.h
@@ -282,6 +282,9 @@ class LLSettingsSky: public LLSettingsBase
     LLVector3 getSunDirection() const;
     LLVector3 getMoonDirection() const;
 
+    // color based on brightness
+    LLColor3  getMoonlightColor() const;
+    
     LLColor4  getMoonAmbient() const;
     LLColor3  getMoonDiffuse() const;
     LLColor4  getSunAmbient() const;
diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp
index c536b403efc216406b80f1907b1883480657d171..f4b5d8852919c3a2d4c31a7ffd03b55c58f48fd1 100644
--- a/indra/llrender/llrender.cpp
+++ b/indra/llrender/llrender.cpp
@@ -1228,6 +1228,7 @@ void LLRender::syncLightState()
 		shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV);
 		shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV);
         shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_primary[0] ? 1 : 0);
+        shader->uniform4fv(LLShaderMgr::AMBIENT, 1, mAmbientLightColor.mV);
         shader->uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, diffuse[0].mV);
         shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuse_b[0].mV);
 	}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
index b439fbbff6c690a764f7087765aa781c02e367db..e0bf58a5c2c00699dadffe0dc846c732cf914b0d 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
@@ -223,7 +223,9 @@ void main()
     float ambient = da;
     ambient *= 0.5;
     ambient *= ambient;
-    ambient = min(getAmbientClamp(), 1.0 - ambient);
+
+    float ambient_clamp = getAmbientClamp() + 0.2;
+    ambient = (1.0 - ambient) * ambient_clamp;
 
     vec3 sun_contrib = min(final_da, shadow) * sunlit;
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
index 0880a73b26ba6bc3fcfd44d47f1c6fb863d7fcea..b9c16bfa11bfcda87eaab47fd33ff3ded3b56a2c 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
@@ -320,7 +320,9 @@ void main()
     float ambient = da;
     ambient *= 0.5;
     ambient *= ambient;
-    ambient = min(getAmbientClamp(), 1.0 - ambient);
+ 
+    float ambient_clamp = getAmbientClamp() + 0.2;
+    ambient = (1.0 - ambient) * ambient_clamp;
 
     vec3 sun_contrib = min(final_da, shadow) * sunlit;
    
diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
index c81d0f97da8c0430365aaa74f7992faf7c44a5f5..40bb705326f9082e58ac8aa3f7975f3f1ee4ce84 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
@@ -106,7 +106,10 @@ void main()
         float ambient = da;
         ambient *= 0.5;
         ambient *= ambient;
-        ambient = min(getAmbientClamp(), 1.0 - ambient);
+
+        ambient = (1.0 - ambient);
+        float ambient_clamp = getAmbientClamp() + 0.1;
+        ambient *= ambient_clamp;
 
         vec3 sun_contrib = final_da * sunlit;
 
@@ -179,11 +182,10 @@ vec3 post_atmo = color.rgb;
             bloom = fogged.a;
         #endif
 
+// srgb colorspace debuggables
 //color.rgb = amblit;
-//color.rgb = vec3(ambient);
 //color.rgb = sunlit;
 //color.rgb = post_ambient;
-//color.rgb = vec3(final_da);
 //color.rgb = sun_contrib;
 //color.rgb = post_sunlight;
 //color.rgb = diffuse_srgb.rgb;
@@ -197,6 +199,11 @@ vec3 post_atmo = color.rgb;
         color.rgb = srgb_to_linear(color.rgb);
     }
 
+// linear debuggables
+//color.rgb = vec3(final_da);
+//color.rgb = vec3(ambient);
+//color.rgb = vec3(scol);
+
     frag_color.rgb = color.rgb;
     frag_color.a = bloom;
 }
diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl
index 38230836ebfe083a72c824473814b2fa24424ca7..cf635ffa3f3303136d991abcad656c30f0b1637f 100644
--- a/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl
+++ b/indra/newview/app_settings/shaders/class1/lighting/lightV.glsl
@@ -28,11 +28,12 @@
 // All lights, no specular highlights
 vec3 atmosAmbient();
 vec4 sumLights(vec3 pos, vec3 norm, vec4 color);
+float getAmbientClamp();
 
 vec4 calcLighting(vec3 pos, vec3 norm, vec4 color)
 {
 	vec4 c = sumLights(pos, norm, color);
-    c.rgb += atmosAmbient() * color.rgb * 0.5;
+    c.rgb += atmosAmbient() * color.rgb * 0.5 * getAmbientClamp();
     return c;
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl
index 68eb671e7c4af4218bc678c461f7515d9bb4a05b..55ffbdcc46191ea585c7671294039b98c0df26a8 100644
--- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl
+++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl
@@ -44,7 +44,7 @@ uniform float sun_moon_glow_factor;
 
 float getAmbientClamp()
 {
-    return 0.45f;
+    return 0.9;
 }
 
 void calcAtmosphericVars(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) {
diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl
index eb95890e08f91d301fdf9021cf3ac330a6d65ea7..dca2862b5ac47d3ec1616447fd11c0a38a890a25 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl
@@ -88,6 +88,7 @@ vec3 halo22(float d)
 
 /// Soft clips the light with a gamma correction
 vec3 scaleSoftClip(vec3 light);
+vec3 srgb_to_linear(vec3 c);
 
 void main()
 {
@@ -194,10 +195,12 @@ void main()
 
     color.rgb += halo_22;
 
-    color *= 2.;
+    color.rgb *= 2.;
+    color.rgb = scaleSoftClip(color.rgb);
+    color.rgb = srgb_to_linear(color.rgb);
 
     /// Gamma correct for WL (soft clip effect).
-    frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0);
+    frag_data[0] = vec4(color.rgb, 1.0);
     frag_data[1] = vec4(0.0,0.0,0.0,0.0);
     frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog
 }
diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
index 1b2b835ad155b3b805a95739f25a59821b0a399d..94abcf08ed7e64ba02b6e5a44704e44040ec8782 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
@@ -24,6 +24,7 @@
  */
  
 #extension GL_ARB_texture_rectangle : enable
+#extension GL_ARB_shader_texture_lod : enable
 
 /*[EXTRA_CODE_HERE]*/
 
@@ -87,14 +88,11 @@ void main()
     float da = dot(normalize(norm.xyz), light_dir.xyz);
           da = clamp(da, -1.0, 1.0);
 
-    
-
     float final_da = da;
           final_da = clamp(final_da, 0.0, 1.0);
 
-    vec4 diffuse_srgb   = texture2DRect(diffuseRect, tc);
-    vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a);
- 
+    vec4 diffuse_linear = texture2DRect(diffuseRect, tc);
+    vec4 diffuse_srgb   = vec4(linear_to_srgb(diffuse_linear.rgb), diffuse_linear.a);
 
     // clamping to alpha value kills underwater shadows...
     //scol = max(scol_ambocc.r, diffuse_linear.a);
@@ -116,7 +114,10 @@ void main()
         float ambient = da;
         ambient *= 0.5;
         ambient *= ambient;
-        ambient = min(getAmbientClamp(), 1.0 - ambient);
+
+        float ambient_clamp = getAmbientClamp() + 0.1;
+        ambient = (1.0 - ambient);
+        ambient *= ambient_clamp;
 
         vec3 sun_contrib = min(scol, final_da) * sunlit;
 
@@ -129,7 +130,7 @@ vec3 post_ambient = color.rgb;
 
 vec3 post_sunlight = color.rgb;
 
-        color.rgb *= diffuse_srgb.rgb;
+        color.rgb *= diffuse_linear.rgb;
 
 vec3 post_diffuse = color.rgb;
 
@@ -155,7 +156,7 @@ vec3 post_diffuse = color.rgb;
                 float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
                 vec3 sp = sun_contrib*scontrib / 16.0;
                 sp = clamp(sp, vec3(0), vec3(1));
-                bloom += dot (sp, sp) / 6.0;
+                bloom += dot(sp, sp) / 6.0;
                 color += sp * spec.rgb;
             }
         }
@@ -163,7 +164,7 @@ vec3 post_diffuse = color.rgb;
  vec3 post_spec = color.rgb;
  
 #ifndef WATER_FOG
-        color.rgb += diffuse_srgb.a * diffuse_srgb.rgb;
+        color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a);
 #endif
 
         if (envIntensity > 0.0)
diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl
index a23a5d40760defc98995ddbc95c894de5d51e988..5b1eb55e0ccc881cd334797373e7615ded5e70ad 100644
--- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl
+++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl
@@ -88,7 +88,7 @@ void main()
 	vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color;
 	vec4 light_atten;
 
-    float dens_mul = density_multiplier * 0.45;
+    float dens_mul = density_multiplier;
 
 	// Sunlight attenuation effect (hue and brightness) due to atmosphere
 	// this is used later for sunlight modulation at various altitudes
diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl
index 48c883d98acc8fd54325d5712ff4e3c5a7b82b45..effe4c59719d21071ca8c77a33aea9c147f0a02a 100644
--- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl
+++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl
@@ -28,11 +28,12 @@
 // All lights, no specular highlights
 vec3 atmosAmbient();
 vec4 sumLights(vec3 pos, vec3 norm, vec4 color);
+float getAmbientClamp();
 
 vec4 calcLighting(vec3 pos, vec3 norm, vec4 color)
 {
 	vec4 c = sumLights(pos, norm, color);
-    c.rgb += atmosAmbient() * color.rgb;
+    c.rgb += atmosAmbient() * color.rgb * getAmbientClamp();
     return c; 
 }
 
diff --git a/indra/newview/llmachineid.cpp b/indra/newview/llmachineid.cpp
index b0ee8e7fcb628e26cac3eef2e550f19ec52fb81c..46411ac13d5a65aac0e5ac1259039b46f7c9bccf 100644
--- a/indra/newview/llmachineid.cpp
+++ b/indra/newview/llmachineid.cpp
@@ -263,6 +263,7 @@ S32 LLMachineID::getUniqueID(unsigned char *unique_id, size_t len)
     if (has_static_unique_id)
     {
         memcpy ( unique_id, &static_unique_id, len);
+#if LL_LOG_MACHINE_ID
         LL_INFOS_ONCE("AppInit") << "UniqueID: 0x";
         // Code between here and LL_ENDL is not executed unless the LL_DEBUGS
         // actually produces output
@@ -276,6 +277,7 @@ S32 LLMachineID::getUniqueID(unsigned char *unique_id, size_t len)
         }
         // Reset default output formatting to avoid nasty surprises!
         LL_CONT << std::dec << std::setw(0) << std::setfill(' ') << LL_ENDL;
+#endif
         return 1;
     }
     return 0;
diff --git a/indra/newview/llsettingsvo.cpp b/indra/newview/llsettingsvo.cpp
index 387644fa575ce03db11e6c4a88c9e3a41ea9cc09..11d7eb1c35554e957a310b40963a8f5ead680945 100644
--- a/indra/newview/llsettingsvo.cpp
+++ b/indra/newview/llsettingsvo.cpp
@@ -682,8 +682,8 @@ void LLSettingsVOSky::applySpecial(void *ptarget)
 
         LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
 
-        LLColor4 sunDiffuse = psky->getSunDiffuse();
-        LLColor4 moonDiffuse = psky->getMoonDiffuse();
+        LLColor4 sunDiffuse = psky->getSunlightColor();
+        LLColor4 moonDiffuse = psky->getMoonlightColor();
 
         F32 max_color = llmax(sunDiffuse.mV[0], sunDiffuse.mV[1], sunDiffuse.mV[2]);
         if (max_color > 1.f)
diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp
index e0253c8a5cfb9465bf4925a81b0947a1a9c01f41..33572deebc50e66afb9e83aff3f78d3542d8bea3 100644
--- a/indra/newview/llviewershadermgr.cpp
+++ b/indra/newview/llviewershadermgr.cpp
@@ -3910,6 +3910,7 @@ BOOL LLViewerShaderMgr::loadShadersWindLight()
         gWLCloudProgram.mFeatures.calculatesAtmospherics = true;
         gWLCloudProgram.mFeatures.hasTransport = true;
         gWLCloudProgram.mFeatures.hasGamma = true;
+        gWLCloudProgram.mFeatures.hasSrgb = true;
         gWLCloudProgram.mShaderFiles.push_back(make_pair("windlight/cloudsV.glsl", GL_VERTEX_SHADER_ARB));
         gWLCloudProgram.mShaderFiles.push_back(make_pair("windlight/cloudsF.glsl", GL_FRAGMENT_SHADER_ARB));
         gWLCloudProgram.mShaderLevel = mShaderLevel[SHADER_WINDLIGHT];
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index cd0a50113b0b6f1e0bfe4009869309c4d9a40eb3..8463730552a12125acb010a91a7a9c3bfa42063a 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -6219,18 +6219,8 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
         mSunDir.setVec(sun_dir);
         mMoonDir.setVec(moon_dir);
 
-        // calculates diffuse sunlight per-pixel downstream, just provide setting sunlight_color
-        if (canUseWindLightShaders())
-        {
-            mSunDiffuse.setVec(psky->getSunlightColor());
-        }
-        else
-        {
-            // not using atmo shaders, use CPU-generated attenuated sunlight diffuse...
-            mSunDiffuse.setVec(psky->getSunDiffuse());
-        }
-
-        mMoonDiffuse.setVec(psky->getMoonDiffuse());
+        mSunDiffuse.setVec(psky->getSunlightColor());
+        mMoonDiffuse.setVec(psky->getMoonlightColor());
 
         F32 max_color = llmax(mSunDiffuse.mV[0], mSunDiffuse.mV[1], mSunDiffuse.mV[2]);
         if (max_color > 1.f)
@@ -6257,15 +6247,15 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
 
         LLVector4 light_dir = sun_up ? mSunDir : mMoonDir;
 
-        mHWLightColors[0] = mSunDiffuse;
+        mHWLightColors[0] = sun_up ? mSunDiffuse : mMoonDiffuse;
 
         LLLightState* light = gGL.getLight(0);
         light->setPosition(light_dir);
 
         light->setSunPrimary(sun_up);
-        light->setDiffuse(mSunDiffuse);
+        light->setDiffuse(mHWLightColors[0]);
         light->setDiffuseB(mMoonDiffuse);
-        light->setAmbient(LLColor4::black);
+        light->setAmbient(psky->getTotalAmbient());
 		light->setSpecular(LLColor4::black);
 		light->setConstantAttenuation(1.f);
 		light->setLinearAttenuation(0.f);