diff --git a/indra/llinventory/llsettingssky.cpp b/indra/llinventory/llsettingssky.cpp
index be26439cee9390f94c57a7e4a99fa094beb597de..c5dfd765f2d0f167ab286d3eb656c25600fba409 100644
--- a/indra/llinventory/llsettingssky.cpp
+++ b/indra/llinventory/llsettingssky.cpp
@@ -51,9 +51,6 @@ namespace
 const F32 LLSettingsSky::DOME_OFFSET(0.96f);
 const F32 LLSettingsSky::DOME_RADIUS(15000.f);
 
-const F32 LLSettingsSky::NIGHTTIME_ELEVATION(-8.0f); // degrees
-const F32 LLSettingsSky::NIGHTTIME_ELEVATION_COS((F32)sin(NIGHTTIME_ELEVATION*DEG_TO_RAD));
-
 //=========================================================================
 const std::string LLSettingsSky::SETTING_AMBIENT("ambient");
 const std::string LLSettingsSky::SETTING_BLUE_DENSITY("blue_density");
@@ -816,6 +813,7 @@ void LLSettingsSky::calculateHeavnlyBodyPositions()
 {
     mSunDirection = DUE_EAST * getSunRotation();
     mSunDirection.normalize();
+
     mMoonDirection = DUE_EAST * getMoonRotation();
     mMoonDirection.normalize();
 
@@ -824,7 +822,7 @@ void LLSettingsSky::calculateHeavnlyBodyPositions()
     {
         mLightDirection = mSunDirection;
     }
-    else if (mSunDirection.mV[1] < 0.0 && mSunDirection.mV[1] > NIGHTTIME_ELEVATION_COS)
+    else if (mSunDirection.mV[1] < 0.0 && mSunDirection.mV[1] > NIGHTTIME_ELEVATION_SIN)
     {
         // clamp v1 to 0 so sun never points up and causes weirdness on some machines
         LLVector3 vec(mSunDirection);
@@ -834,7 +832,11 @@ void LLSettingsSky::calculateHeavnlyBodyPositions()
     }
     else
     {
-        mLightDirection = mMoonDirection;
+        // clamp v1 to 0 so moon never points up and causes weirdness on some machines
+        LLVector3 vec(mMoonDirection);
+        vec.mV[1] = 0.0;
+        vec.normalize();
+        mLightDirection = vec;
     }
 
     // calculate the clamp lightnorm for sky (to prevent ugly banding in sky
@@ -993,7 +995,7 @@ void LLSettingsSky::calculateLightSettings()
 
         // and vary_sunlight will work properly with moon light
         F32 lighty = lightnorm[1];
-        if (lighty < NIGHTTIME_ELEVATION_COS)
+        if (lighty < NIGHTTIME_ELEVATION_SIN)
         {
             lighty = -lighty;
         }
diff --git a/indra/llinventory/llsettingssky.h b/indra/llinventory/llsettingssky.h
index 63a20e0d489897dcdae048c1e597ba64f40d2adb..8e96735abf5342c6f2f54f0669d67c872a3dee49 100644
--- a/indra/llinventory/llsettingssky.h
+++ b/indra/llinventory/llsettingssky.h
@@ -37,6 +37,9 @@ const F32 SUN_DIST      = 149598.260e6f;
 const F32 MOON_RADIUS   =      1.737e6f;
 const F32 MOON_DIST     =    384.400e6f;
 
+const F32 NIGHTTIME_ELEVATION     = -8.0f; // degrees
+const F32 NIGHTTIME_ELEVATION_SIN = (F32)sinf(NIGHTTIME_ELEVATION * DEG_TO_RAD);
+
 class LLSettingsSky: public LLSettingsBase
 {
 public:
@@ -504,9 +507,6 @@ class LLSettingsSky: public LLSettingsBase
     static LLSD absorptionConfigDefault();
     static LLSD mieConfigDefault();
 
-    static const F32         NIGHTTIME_ELEVATION;
-    static const F32         NIGHTTIME_ELEVATION_COS;
-
     void        calculateHeavnlyBodyPositions();
     void        calculateLightSettings();
 
diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp
index bdf04bd4364c4d58df116a2ca055ff160949e586..2804ad1f4612acdb85dcf17b1d7bb5283cca7da1 100644
--- a/indra/newview/lldrawpoolwater.cpp
+++ b/indra/newview/lldrawpoolwater.cpp
@@ -491,6 +491,8 @@ void LLDrawPoolWater::shade()
     LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater();
 
     light_dir = voskyp->getLightDirection();
+    light_dir.normalize();
+
     if (LLEnvironment::instance().getIsDayTime())
     {
         light_color = voskyp->getSunAmbientColor();
@@ -501,14 +503,14 @@ void LLDrawPoolWater::shade()
     }
     else
     {
-        light_color = voskyp->getMoonAmbientColor();
+        light_color = voskyp->getMoonDiffuseColor();
         light_diffuse = voskyp->getMoonDiffuseColor();
         light_diffuse.normalize();
         light_diffuse *= 0.5f;
         light_exp = light_dir * LLVector3(light_dir.mV[0], light_dir.mV[1], 0.f);
     }
 
-// 	if (gSky.getSunDirection().mV[2] > LLSky::NIGHTTIME_ELEVATION_COS) 	 
+// 	if (gSky.getSunDirection().mV[2] > NIGHTTIME_ELEVATION_COS) 	 
 //     { 	 
 //         light_dir  = gSky.getSunDirection(); 	 
 //         light_dir.normVec(); 	
diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp
index 91bfc3858c71785676deb8cdab86c5fbb0992296..277f1f3d6c996ca3a8e40c3c7f2f0c48f0e20e58 100644
--- a/indra/newview/lldrawpoolwlsky.cpp
+++ b/indra/newview/lldrawpoolwlsky.cpp
@@ -329,15 +329,12 @@ void LLDrawPoolWLSky::renderHeavenlyBodies()
 		gGL.getTexUnit(0)->bind(face->getTexture());
 		LLColor4 color(gSky.mVOSkyp->getMoon().getInterpColor());
 
-#if 0
-		F32 a = gSky.mVOSkyp->getMoon().getDirection().mV[2];
+		/*F32 a = gSky.mVOSkyp->getMoon().getDirection().mV[2];
 		if (a > 0.f)
 		{
 			a = a*a*4.f;
-		}
-			
-		color.mV[3] = llclamp(a, 0.f, 1.f);
-#endif
+		}			
+		color.mV[3] = llclamp(a, 0.f, 1.f);*/
 		
 		if (gPipeline.canUseVertexShaders())
 		{
@@ -431,7 +428,9 @@ void LLDrawPoolWLSky::render(S32 pass)
 
 	renderSkyHaze(origin, camHeightLocal);
 
-    if (!gPipeline.useAdvancedAtmospherics() && gPipeline.canUseWindLightShaders())
+    bool use_advanced = gPipeline.useAdvancedAtmospherics();
+    
+    if (!use_advanced)
     {
 	    gGL.pushMatrix();
 
diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp
index d878bd9abec951f4e82258caec8f8451ae02c992..d37cbfc76d0db095914faf8dff100dce36cd2d4e 100644
--- a/indra/newview/llenvironment.cpp
+++ b/indra/newview/llenvironment.cpp
@@ -190,7 +190,6 @@ const F32Seconds LLEnvironment::TRANSITION_DEFAULT(5.0f);
 const F32Seconds LLEnvironment::TRANSITION_SLOW(10.0f);
 
 const F32 LLEnvironment::SUN_DELTA_YAW(F_PI);   // 180deg 
-const F32 LLEnvironment::NIGHTTIME_ELEVATION_COS(LLSky::NIGHTTIME_ELEVATION_COS);
 
 //-------------------------------------------------------------------------
 LLEnvironment::LLEnvironment():
@@ -380,7 +379,7 @@ F32 LLEnvironment::getWaterHeight() const
 
 bool LLEnvironment::getIsDayTime() const
 {
-    return mCurrentEnvironment->getSky()->getSunDirection().mV[2] > NIGHTTIME_ELEVATION_COS;
+    return mCurrentEnvironment->getSky()->getSunDirection().mV[2] > NIGHTTIME_ELEVATION_SIN;
 }
 
 //-------------------------------------------------------------------------
diff --git a/indra/newview/llenvironment.h b/indra/newview/llenvironment.h
index 30286d54fdf548dc7b816622e4de47d71cf55ad3..e4f891deca6d04a4ab7d8be531690cf1560905fa 100644
--- a/indra/newview/llenvironment.h
+++ b/indra/newview/llenvironment.h
@@ -293,7 +293,6 @@ class LLEnvironment : public LLSingleton<LLEnvironment>
     };
 
     static const F32            SUN_DELTA_YAW;
-    static const F32            NIGHTTIME_ELEVATION_COS;
 
     typedef std::map<LLUUID, LLSettingsBase::ptr_t> AssetSettingMap_t;
 
diff --git a/indra/newview/llsky.cpp b/indra/newview/llsky.cpp
index 15aebda5ad6ea35dc8f9d9bb685ad68ea1b3b61f..a81e74b6ede74cf0cc5060f2db4a7d1aa9452db4 100644
--- a/indra/newview/llsky.cpp
+++ b/indra/newview/llsky.cpp
@@ -51,18 +51,16 @@
 #include "llvosky.h"
 #include "llcubemap.h"
 #include "llviewercontrol.h"
+#include "llenvironment.h"
 
 #include "llvowlsky.h"
 
 F32 azimuth_from_vector(const LLVector3 &v);
 F32 elevation_from_vector(const LLVector3 &v);
 
-LLSky				gSky;
-// ---------------- LLSky ----------------
-
-const F32 LLSky::NIGHTTIME_ELEVATION = -8.0f; // degrees
-const F32 LLSky::NIGHTTIME_ELEVATION_COS = (F32)sin(NIGHTTIME_ELEVATION*DEG_TO_RAD);
+LLSky gSky;
 
+// ---------------- LLSky ----------------
 //////////////////////////////////////////////////////////////////////
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
diff --git a/indra/newview/llsky.h b/indra/newview/llsky.h
index 010cc30d55ea7f7f52483018e4b94c6c43d7cb9b..27029b254b7dd614140a266d3dca64de200572c7 100644
--- a/indra/newview/llsky.h
+++ b/indra/newview/llsky.h
@@ -97,9 +97,6 @@ class LLSky
 	// Legacy stuff
 	LLVector3 mSunDefaultPosition;
 
-	static const F32 NIGHTTIME_ELEVATION;	// degrees
-	static const F32 NIGHTTIME_ELEVATION_COS;
-
 protected:
 	F32				mSunPhase;
 	LLColor4		mFogColor;				// Color to use for fog and haze
diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp
index 95e4f27a3943987bc095766a34f200c1f6bb4176..40cf4c82e61054205adfa1fa5da2b403575f8896 100644
--- a/indra/newview/llviewershadermgr.cpp
+++ b/indra/newview/llviewershadermgr.cpp
@@ -46,6 +46,8 @@
 #include "llenvironment.h"
 #include "llatmosphere.h"
 
+#pragma optimize("", off)
+
 #ifdef LL_RELEASE_FOR_DOWNLOAD
 #define UNIFORM_ERRS LL_WARNS_ONCE("Shader")
 #else
@@ -509,8 +511,9 @@ void LLViewerShaderMgr::setShaders()
             wl_class = llmin(wl_class, 2);
         }
 
-		if (!(LLFeatureManager::getInstance()->isFeatureAvailable("WindLightUseAtmosShaders")
-			  && gSavedSettings.getBOOL("WindLightUseAtmosShaders")))
+        bool hasWindLightShaders = LLFeatureManager::getInstance()->isFeatureAvailable("WindLightUseAtmosShaders");
+        bool useWindLightShaders = gSavedSettings.getBOOL("WindLightUseAtmosShaders");
+		if (!hasWindLightShaders || !useWindLightShaders)
 		{
 			// user has disabled WindLight in their settings, downgrade
 			// windlight shaders to stub versions.
@@ -544,7 +547,6 @@ void LLViewerShaderMgr::setShaders()
 
 			// Load all shaders to set max levels
 			loaded = loadShadersEnvironment();
-			llassert(loaded);
 
 			if (loaded)
 			{
diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp
index 5f55f6c31038bf5e8eb3bfb0db901c40cb61a25b..1e99c77da9e430cb96734fb2e1a4ba3128d5b4dc 100644
--- a/indra/newview/llvosky.cpp
+++ b/indra/newview/llvosky.cpp
@@ -700,6 +700,12 @@ BOOL LLVOSky::updateGeometry(LLDrawable *drawable)
     bool draw_sun  = updateHeavenlyBodyGeometry(drawable, FACE_SUN, mSun, up, right);
     bool draw_moon = updateHeavenlyBodyGeometry(drawable, FACE_MOON, mMoon, up, right);
 
+    bool daytime = LLEnvironment::getInstance()->getIsDayTime();
+
+    // makeshift check until we properly handle moon in daytime
+    draw_sun  &=  daytime;
+    draw_moon &= !daytime;
+
 	mSun.setDraw(draw_sun);
 	mMoon.setDraw(draw_moon);
 
@@ -763,16 +769,7 @@ BOOL LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 f, LLHe
 	S32 index_offset;
 	LLFace *facep;
 
-	LLVector3 to_dir = hb.getDirection();
-
-    /*F32 rad = hb.getDiskRadius();
-    F32 d = to_dir * LLVector3::z_axis;
-    if (d < -(rad * 0.5f))
-    {
-        hb.setVisible(FALSE);
-        return FALSE;
-    }*/
-
+	LLVector3 to_dir   = hb.getDirection();
 	LLVector3 draw_pos = to_dir * HEAVENLY_BODY_DIST;
 
 	LLVector3 hb_right = to_dir % LLVector3::z_axis;
@@ -780,8 +777,12 @@ BOOL LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 f, LLHe
 	hb_right.normalize();
 	hb_up.normalize();
 
-	const LLVector3 scaled_right = HEAVENLY_BODY_DIST * hb.getDiskRadius() * hb_right;
-	const LLVector3 scaled_up    = HEAVENLY_BODY_DIST * hb.getDiskRadius() * hb_up;
+    const F32 enlargm_factor = ( 1 - to_dir.mV[2] );
+	F32 horiz_enlargement = 1 + enlargm_factor * 0.3f;
+	F32 vert_enlargement = 1 + enlargm_factor * 0.2f;
+
+	const LLVector3 scaled_right = horiz_enlargement * HEAVENLY_BODY_DIST * HEAVENLY_BODY_FACTOR * hb.getDiskRadius() * hb_right;
+	const LLVector3 scaled_up    = vert_enlargement  * HEAVENLY_BODY_DIST * HEAVENLY_BODY_FACTOR * hb.getDiskRadius() * hb_up;
 
 	LLVector3 v_clipped[4];
 
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 6ad47386c77f76ae09531689ad01abd82e73870b..b2ec9a6a668f836dbce6a47a08762a1a16f6682a 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -927,7 +927,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
 			for (U32 i = 0; i < 4; i++)
 			{
 				if (!mShadow[i].allocate(sun_shadow_map_width,U32(resY*scale), 0, TRUE, FALSE, LLTexUnit::TT_TEXTURE)) return false;
-				if (!mShadowOcclusion[i].allocate(mShadow[i].getWidth()/occlusion_divisor, mShadow[i].getHeight()/occlusion_divisor, 0, TRUE, FALSE, LLTexUnit::TT_TEXTURE)) return false;                
+				if (!mShadowOcclusion[i].allocate(mShadow[i].getWidth()/occlusion_divisor, mShadow[i].getHeight()/occlusion_divisor, 0, TRUE, FALSE, LLTexUnit::TT_TEXTURE)) return false;
 			}
 		}
 		else
@@ -6034,7 +6034,7 @@ void LLPipeline::setupAvatarLights(bool for_edit)
 			}
 		}
 		F32 backlight_mag;
-		if (gSky.getSunDirection().mV[2] >= LLSky::NIGHTTIME_ELEVATION_COS)
+		if (gSky.getSunDirection().mV[2] >= NIGHTTIME_ELEVATION_SIN)
 		{
 			backlight_mag = BACKLIGHT_DAY_MAGNITUDE_OBJECT;
 		}
@@ -6253,7 +6253,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
 
 	// Light 0 = Sun or Moon (All objects)
 	{
-		if (gSky.getSunDirection().mV[2] >= LLSky::NIGHTTIME_ELEVATION_COS)
+		if (gSky.getSunDirection().mV[2] >= NIGHTTIME_ELEVATION_SIN)
 		{
 			mSunDir.setVec(gSky.getSunDirection());
 			mSunDiffuse.setVec(gSky.getSunDiffuseColor());
@@ -9124,7 +9124,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target)
 					}
 				}
 
-// pretty sure this doesn't work as expected since the shaders using 'shadow_ofset' all declare it as a single uniform float, no array or vec
+// pretty sure this doesn't work as expected since the shaders using 'shadow_offset' all declare it as a single uniform float, no array or vec
 				gDeferredSunProgram.uniform3fv(LLShaderMgr::DEFERRED_SHADOW_OFFSET, slice, offset);
 				gDeferredSunProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, mDeferredLight.getWidth(), mDeferredLight.getHeight());