diff --git a/indra/llinventory/llsettingsbase.cpp b/indra/llinventory/llsettingsbase.cpp
index af3e84fd0fb6c583c7cc9bf55f202aebe3d1326a..61b59e35aacd523ea90f693108896098f5b4f557 100644
--- a/indra/llinventory/llsettingsbase.cpp
+++ b/indra/llinventory/llsettingsbase.cpp
@@ -39,6 +39,7 @@ namespace
 }
 
 const LLSettingsBase::TrackPosition LLSettingsBase::INVALID_TRACKPOS(-1.0);
+const std::string LLSettingsBase::DEFAULT_SETTINGS_NAME("_default_");
 
 //=========================================================================
 std::ostream &operator <<(std::ostream& os, LLSettingsBase &settings)
@@ -67,7 +68,6 @@ const U32 LLSettingsBase::Validator::VALIDATION_PARTIAL(0x01 << 0);
 LLSettingsBase::LLSettingsBase():
     mSettings(LLSD::emptyMap()),
     mDirty(true),
-    mAssetID(),
     mBlendedFactor(0.0)
 {
 }
@@ -75,7 +75,6 @@ LLSettingsBase::LLSettingsBase():
 LLSettingsBase::LLSettingsBase(const LLSD setting) :
     mSettings(setting),
     mDirty(true),
-    mAssetID(),
     mBlendedFactor(0.0)
 {
 }
diff --git a/indra/llinventory/llsettingsbase.h b/indra/llinventory/llsettingsbase.h
index 26e2901968c336c29ea6f0e10ec0274df0f77220..1d118f07899d332d12b936a1f06e756018ed2656 100644
--- a/indra/llinventory/llsettingsbase.h
+++ b/indra/llinventory/llsettingsbase.h
@@ -64,6 +64,7 @@ class LLSettingsBase :
     typedef F64        BlendFactor;
     typedef F32        TrackPosition; // 32-bit as these are stored in LLSD as such
     static const TrackPosition INVALID_TRACKPOS;
+    static const std::string DEFAULT_SETTINGS_NAME;
 
     static const std::string SETTING_ID;
     static const std::string SETTING_NAME;
@@ -359,7 +360,6 @@ class LLSettingsBase :
 
     LLSD        mSettings;
     bool        mIsValid;
-    LLAssetID   mAssetID;
 
     LLSD        cloneSettings() const;
 
diff --git a/indra/llinventory/llsettingsdaycycle.cpp b/indra/llinventory/llsettingsdaycycle.cpp
index 8498425f4e810ee33fed8673b2b494d8406b0838..457e5b747898a2a37644ac3e2be4e995beac5e94 100644
--- a/indra/llinventory/llsettingsdaycycle.cpp
+++ b/indra/llinventory/llsettingsdaycycle.cpp
@@ -408,7 +408,7 @@ LLSD LLSettingsDay::defaults()
 
     if (dfltsetting.size() == 0)
     {
-        dfltsetting[SETTING_NAME] = "_default_";
+        dfltsetting[SETTING_NAME] = DEFAULT_SETTINGS_NAME;
         dfltsetting[SETTING_TYPE] = "daycycle";
 
         LLSD frames(LLSD::emptyMap());
@@ -421,7 +421,7 @@ LLSD LLSettingsDay::defaults()
         F32 time = 0.0f;
         for (U32 i = 0; i < FRAME_COUNT; i++)
         {
-            std::string name("_default_");
+            std::string name(DEFAULT_SETTINGS_NAME);
             name += ('a' + i);
 
             std::string water_frame_name("water:");
diff --git a/indra/llinventory/llsettingsdaycycle.h b/indra/llinventory/llsettingsdaycycle.h
index 8776f6725df35929963f7d0b2ee74788f298d36c..f7f5bb63b667e982b94155bc7a60edf72b1b5849 100644
--- a/indra/llinventory/llsettingsdaycycle.h
+++ b/indra/llinventory/llsettingsdaycycle.h
@@ -146,8 +146,6 @@ class LLSettingsDay : public LLSettingsBase
 
     LLSettingsBase::Seconds     mLastUpdateTime;
 
-    void                        parseFromLLSD(LLSD &data);
-
     static CycleTrack_t::iterator   getEntryAtOrBefore(CycleTrack_t &track, const LLSettingsBase::TrackPosition& keyframe);
     static CycleTrack_t::iterator   getEntryAtOrAfter(CycleTrack_t &track, const LLSettingsBase::TrackPosition& keyframe);
     TrackBound_t                    getBoundingEntries(CycleTrack_t &track, const LLSettingsBase::TrackPosition& keyframe);
diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h
index 57f2489a2d6883c4cbc2f5766a6289342ecffe5f..8f01ad6c1cad3f02a79c14b928327ba62bd43a61 100644
--- a/indra/llmath/llmath.h
+++ b/indra/llmath/llmath.h
@@ -537,9 +537,12 @@ inline void ll_remove_outliers(std::vector<VEC_TYPE>& data, F32 k)
 	}
 }
 
-// This converts from a non-linear sRGB floating point value (0..1) to a linear value.
-// Useful for gamma correction and such.  Note: any values passed through this should not be serialized.  You should also ideally cache the output of this.
-inline float sRGBtoLinear(const float val) {
+// Converts given value from a linear RGB floating point value (0..1) to a gamma corrected (sRGB) value.
+// Some shaders require color values in linear space, while others require color values in gamma corrected (sRGB) space.
+// Note: in our code, values labeled as sRGB are ALWAYS gamma corrected linear values, NOT linear values with monitor gamma applied
+// Note: stored color values should always be gamma corrected linear (i.e. the values returned from an on-screen color swatch)
+// Note: DO NOT cache the conversion.  This leads to error prone synchronization and is actually slower in the typical case due to cache misses
+inline float linearTosRGB(const float val) {
     if (val < 0.0031308f) {
         return val * 12.92f;
     }
@@ -548,7 +551,13 @@ inline float sRGBtoLinear(const float val) {
     }
 }
 
-inline float linearTosRGB(const float val) {
+// Converts given value from a gamma corrected (sRGB) floating point value (0..1) to a linear color value.
+// Some shaders require color values in linear space, while others require color values in gamma corrected (sRGB) space.
+// Note: In our code, values labeled as sRGB are gamma corrected linear values, NOT linear values with monitor gamma applied
+// Note: Stored color values should generally be gamma corrected sRGB.  
+//       If you're serializing the return value of this function, you're probably doing it wrong.
+// Note: DO NOT cache the conversion.  This leads to error prone synchronization and is actually slower in the typical case due to cache misses.
+inline float sRGBtoLinear(const float val) {
     if (val < 0.04045f) {
         return val / 12.92f;
     }
diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h
index ac78197510b110dec502c9baae69419c04e2949c..43a632408c7fc05ddec03bf0ad266c800855a7cb 100644
--- a/indra/llmath/v3color.h
+++ b/indra/llmath/v3color.h
@@ -484,4 +484,13 @@ inline const LLColor3 srgbColor3(const LLColor3 &a) {
 	return srgbColor;
 }
 
+inline const LLColor3 linearColor3(const LLColor3 &a) {
+    LLColor3 linearColor;
+    linearColor.mV[0] = sRGBtoLinear(a.mV[0]);
+    linearColor.mV[1] = sRGBtoLinear(a.mV[1]);
+    linearColor.mV[2] = sRGBtoLinear(a.mV[2]);
+
+    return linearColor;
+}
+
 #endif
diff --git a/indra/llmath/v4color.h b/indra/llmath/v4color.h
index 1b65d4a0035ea61ccb463d68b6b161028ab4f37b..d4f2ca73893bbf770c8d8be8c0ee5effa7009a36 100644
--- a/indra/llmath/v4color.h
+++ b/indra/llmath/v4color.h
@@ -659,6 +659,7 @@ void LLColor4::clamp()
 	}
 }
 
+// Return the given linear space color value in gamma corrected (sRGB) space
 inline const LLColor4 srgbColor4(const LLColor4 &a) {
     LLColor4 srgbColor;
 
@@ -670,5 +671,17 @@ inline const LLColor4 srgbColor4(const LLColor4 &a) {
     return srgbColor;
 }
 
+// Return the given gamma corrected (sRGB) color in linear space
+inline const LLColor4 linearColor4(const LLColor4 &a)
+{
+    LLColor4 linearColor;
+    linearColor.mV[0] = sRGBtoLinear(a.mV[0]);
+    linearColor.mV[1] = sRGBtoLinear(a.mV[1]);
+    linearColor.mV[2] = sRGBtoLinear(a.mV[2]);
+    linearColor.mV[3] = a.mV[3];
+
+    return linearColor;
+}
+
 #endif
 
diff --git a/indra/llprimitive/llprimitive.cpp b/indra/llprimitive/llprimitive.cpp
index bc5dd62f457f69e6c25d8b25fe043aa62e3b5d10..53b83a40d73305d2616fe484dc065ea03ffbf797 100644
--- a/indra/llprimitive/llprimitive.cpp
+++ b/indra/llprimitive/llprimitive.cpp
@@ -1659,7 +1659,7 @@ BOOL LLLightParams::unpack(LLDataPacker &dp)
 {
 	LLColor4U color;
 	dp.unpackColor4U(color, "color");
-	setColor(LLColor4(color));
+	setLinearColor(LLColor4(color));
 
 	F32 radius;
 	dp.unpackF32(radius, "radius");
@@ -1707,7 +1707,7 @@ LLSD LLLightParams::asLLSD() const
 {
 	LLSD sd;
 	
-	sd["color"] = ll_sd_from_color4(getColor());
+	sd["color"] = ll_sd_from_color4(getLinearColor());
 	sd["radius"] = getRadius();
 	sd["falloff"] = getFalloff();
 	sd["cutoff"] = getCutoff();
@@ -1721,7 +1721,7 @@ bool LLLightParams::fromLLSD(LLSD& sd)
 	w = "color";
 	if (sd.has(w))
 	{
-		setColor( ll_color4_from_sd(sd["color"]) );
+		setLinearColor( ll_color4_from_sd(sd["color"]) );
 	} else goto fail;
 	w = "radius";
 	if (sd.has(w))
diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h
index 20b5ad8eff9034a010194140b39944429ba492d2..b1f8112223053cd708261abbe381733e44a9e29c 100644
--- a/indra/llprimitive/llprimitive.h
+++ b/indra/llprimitive/llprimitive.h
@@ -131,9 +131,8 @@ extern const F32 LIGHT_MAX_CUTOFF;
 
 class LLLightParams : public LLNetworkData
 {
-protected:
-	LLColor4 mColor; // alpha = intensity
-    LLColor4 mSRGBColor; // Only used in deferred (for now?)
+private:
+	LLColor4 mColor; // linear color (not gamma corrected), alpha = intensity
 	F32 mRadius;
 	F32 mFalloff;
 	F32 mCutoff;
@@ -150,14 +149,22 @@ class LLLightParams : public LLNetworkData
 	operator LLSD() const { return asLLSD(); }
 	bool fromLLSD(LLSD& sd);
 
+    // set the color by gamma corrected color value
+    //  color - gamma corrected color value (directly taken from an on-screen color swatch)
+    void setSRGBColor(const LLColor4& color) { setLinearColor(linearColor4(color)); }
 
-    void setColor(const LLColor4& color)	{ mColor = color; mColor.clamp(); mSRGBColor = srgbColor4(mColor); }
+    // set the color by linear color value
+    //  color - linear color value (value as it appears in shaders)
+    void setLinearColor(const LLColor4& color)	{ mColor = color; mColor.clamp(); }
 	void setRadius(F32 radius)				{ mRadius = llclamp(radius, LIGHT_MIN_RADIUS, LIGHT_MAX_RADIUS); }
 	void setFalloff(F32 falloff)			{ mFalloff = llclamp(falloff, LIGHT_MIN_FALLOFF, LIGHT_MAX_FALLOFF); }
 	void setCutoff(F32 cutoff)				{ mCutoff = llclamp(cutoff, LIGHT_MIN_CUTOFF, LIGHT_MAX_CUTOFF); }
 
-    LLColor4 getColor() const				{ return mColor; }
-    LLColor4 getSRGBColor() const			{ return mSRGBColor; }
+    // get the linear space color of this light.  This value can be fed directly to shaders
+    LLColor4 getLinearColor() const				{ return mColor; }
+    // get the sRGB (gamma corrected) color of this light, this is the value that should be displayed in the UI
+    LLColor4 getSRGBColor() const			{ return srgbColor4(mColor); }
+    
 	F32 getRadius() const					{ return mRadius; }
 	F32 getFalloff() const					{ return mFalloff; }
 	F32 getCutoff() const					{ return mCutoff; }
diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp
index f4b5d8852919c3a2d4c31a7ffd03b55c58f48fd1..ebc4659bcfbb0a76d6e5d3329238b6806e7fc2ab 100644
--- a/indra/llrender/llrender.cpp
+++ b/indra/llrender/llrender.cpp
@@ -1370,7 +1370,7 @@ void LLRender::syncMatrices()
 		}
 
 
-		if (shader->mFeatures.hasLighting || shader->mFeatures.calculatesLighting)
+		if (shader->mFeatures.hasLighting || shader->mFeatures.calculatesLighting || shader->mFeatures.calculatesAtmospherics)
 		{ //also sync light state
 			syncLightState();
 		}
diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp
index 896dd566c1fc0533b7ab7c3b2703015530a1e241..13830208732d0a97c1821d16a7f290a8aedd01c0 100644
--- a/indra/llrender/llshadermgr.cpp
+++ b/indra/llrender/llshadermgr.cpp
@@ -569,23 +569,18 @@ static std::string get_object_log(GLhandleARB ret)
 
 //dump shader source for debugging
 void LLShaderMgr::dumpShaderSource(U32 shader_code_count, GLcharARB** shader_code_text)
-{	
-	for (U32 i = 0; i < shader_code_count; i++)
-	{
-		GLcharARB *line = shader_code_text[i];
-		size_t     len  = strlen( line );
-		GLcharARB  last = len > 0 ? line[len - 1] : 0;
-
-		// LL_ENDL already outputs a newline so temporarily strip off the end newline to prevent EVERY line outputting an (extra) blank line
-		if (last == '\n')
-		    line[len - 1] = 0;
+{
+	char num_str[16]; // U32 = max 10 digits
 
-		LL_SHADER_LOADING_WARNS() << i << ": " << shader_code_text[i] << LL_ENDL;
+	LL_SHADER_LOADING_WARNS() << "\n";
 
-		if (last == '\n')
-			line[len - 1] = '\n';
+	for (U32 i = 0; i < shader_code_count; i++)
+	{
+		snprintf(num_str, sizeof(num_str), "%4d: ", i+1);
+		std::string line_number(num_str);
+		LL_CONT << line_number << shader_code_text[i];
 	}
-    LL_SHADER_LOADING_WARNS() << LL_ENDL;
+    LL_CONT << LL_ENDL;
 }
 
 void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& filename) 
@@ -599,8 +594,8 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string&
 
 	if (log.length() > 0)
 	{
-        LL_SHADER_LOADING_WARNS() << "Shader loading from " << fname << ":\n" << LL_ENDL;
-        LL_SHADER_LOADING_WARNS() << log << LL_ENDL;
+        LL_SHADER_LOADING_WARNS() << "Shader loading from " << fname << LL_ENDL;
+        LL_SHADER_LOADING_WARNS() << "\n" << log << LL_ENDL;
 	}
  }
 
diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp
index e3035c71942cc1bf071e76d78d503ad1bb8da252..94a04d4ddb52927a95a54e065773b2e65582c789 100644
--- a/indra/llrender/llvertexbuffer.cpp
+++ b/indra/llrender/llvertexbuffer.cpp
@@ -2326,34 +2326,35 @@ void LLVertexBuffer::setBuffer(U32 data_mask)
 			{
 				
 				U32 unsatisfied_mask = (required_mask & ~data_mask);
-				U32 i = 0;
 
-				while (i < TYPE_MAX)
-				{
+                for (U32 i = 0; i < TYPE_MAX; i++)
+                {
                     U32 unsatisfied_flag = unsatisfied_mask & (1 << i);
-					switch (unsatisfied_flag)
-					{
-						case MAP_VERTEX: LL_INFOS() << "Missing vert pos" << LL_ENDL; break;
-						case MAP_NORMAL: LL_INFOS() << "Missing normals" << LL_ENDL; break;
-						case MAP_TEXCOORD0: LL_INFOS() << "Missing TC 0" << LL_ENDL; break;
-						case MAP_TEXCOORD1: LL_INFOS() << "Missing TC 1" << LL_ENDL; break;
-						case MAP_TEXCOORD2: LL_INFOS() << "Missing TC 2" << LL_ENDL; break;
-						case MAP_TEXCOORD3: LL_INFOS() << "Missing TC 3" << LL_ENDL; break;
-						case MAP_COLOR: LL_INFOS() << "Missing vert color" << LL_ENDL; break;
-						case MAP_EMISSIVE: LL_INFOS() << "Missing emissive" << LL_ENDL; break;
-						case MAP_TANGENT: LL_INFOS() << "Missing tangent" << LL_ENDL; break;
-						case MAP_WEIGHT: LL_INFOS() << "Missing weight" << LL_ENDL; break;
-						case MAP_WEIGHT4: LL_INFOS() << "Missing weightx4" << LL_ENDL; break;
-						case MAP_CLOTHWEIGHT: LL_INFOS() << "Missing clothweight" << LL_ENDL; break;
-						case MAP_TEXTURE_INDEX: LL_INFOS() << "Missing tex index" << LL_ENDL; break;
-						default: LL_INFOS() << "Missing who effin knows: " << unsatisfied_flag << LL_ENDL;
-					}					
-				}
-
-            if (unsatisfied_mask & (1 << TYPE_INDEX))
-            {
-               LL_INFOS() << "Missing indices" << LL_ENDL;
-            }
+                    switch (unsatisfied_flag)
+                    {
+                        case 0: break;
+                        case MAP_VERTEX: LL_INFOS() << "Missing vert pos" << LL_ENDL; break;
+                        case MAP_NORMAL: LL_INFOS() << "Missing normals" << LL_ENDL; break;
+                        case MAP_TEXCOORD0: LL_INFOS() << "Missing TC 0" << LL_ENDL; break;
+                        case MAP_TEXCOORD1: LL_INFOS() << "Missing TC 1" << LL_ENDL; break;
+                        case MAP_TEXCOORD2: LL_INFOS() << "Missing TC 2" << LL_ENDL; break;
+                        case MAP_TEXCOORD3: LL_INFOS() << "Missing TC 3" << LL_ENDL; break;
+                        case MAP_COLOR: LL_INFOS() << "Missing vert color" << LL_ENDL; break;
+                        case MAP_EMISSIVE: LL_INFOS() << "Missing emissive" << LL_ENDL; break;
+                        case MAP_TANGENT: LL_INFOS() << "Missing tangent" << LL_ENDL; break;
+                        case MAP_WEIGHT: LL_INFOS() << "Missing weight" << LL_ENDL; break;
+                        case MAP_WEIGHT4: LL_INFOS() << "Missing weightx4" << LL_ENDL; break;
+                        case MAP_CLOTHWEIGHT: LL_INFOS() << "Missing clothweight" << LL_ENDL; break;
+                        case MAP_TEXTURE_INDEX: LL_INFOS() << "Missing tex index" << LL_ENDL; break;
+                        default: LL_INFOS() << "Missing who effin knows: " << unsatisfied_flag << LL_ENDL;
+                    }
+                }
+
+                // TYPE_INDEX is beyond TYPE_MAX, so check for it individually
+                if (unsatisfied_mask & (1 << TYPE_INDEX))
+                {
+                   LL_INFOS() << "Missing indices" << LL_ENDL;
+                }
 
 				LL_ERRS() << "Shader consumption mismatches data provision." << LL_ENDL;
 			}
diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h
index c89d7e39580712809e80f5e56e57c4594277af8a..9867bd16d6394d6982271afdefc2527108cfa83d 100644
--- a/indra/llrender/llvertexbuffer.h
+++ b/indra/llrender/llvertexbuffer.h
@@ -179,8 +179,8 @@ class LLVertexBuffer : public LLRefCount, public LLTrace::MemTrackable<LLVertexB
 		TYPE_WEIGHT4,
 		TYPE_CLOTHWEIGHT,
 		TYPE_TEXTURE_INDEX,
-		TYPE_MAX,
-		TYPE_INDEX,		
+		TYPE_MAX,   // TYPE_MAX is the size/boundary marker for attributes that go in the vertex buffer
+		TYPE_INDEX,	// TYPE_INDEX is beyond _MAX because it lives in a separate (index) buffer	
 	};
 	enum {
 		MAP_VERTEX = (1<<TYPE_VERTEX),
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
index 46ec20c8b09f202b8d31716cc23f974b6788ff29..57420158ca2b21f26ab7c64e82a421803bb6d32a 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
@@ -79,8 +79,6 @@ void main()
 	color.rgb = fogged.rgb;
 	color.a   = fogged.a;
 #else
-    color.rgb = fullbrightAtmosTransport(color.rgb);
-	color.rgb = fullbrightScaleSoftClip(color.rgb);
     color.a   = final_alpha;
 #endif
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl
index 523e7f9e04ac02aa2260086e0aee7c278563bae9..bd0ad3bce80bf49604cb1eccd97b81dc841fccba 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl
@@ -38,12 +38,20 @@ uniform sampler2D diffuseMap;
 VARYING vec4 vertex_color;
 VARYING vec2 vary_texcoord0;
 VARYING vec3 vary_texcoord1;
+VARYING vec4 vary_position;
 
 uniform samplerCube environmentMap;
 
 vec3 fullbrightShinyAtmosTransport(vec3 light);
+vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten);
 vec3 fullbrightScaleSoftClip(vec3 light);
 
+void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao);
+
+vec3 linear_to_srgb(vec3 c);
+vec3 srgb_to_linear(vec3 c);
+
+
 void main()
 {
 #ifdef HAS_DIFFUSE_LOOKUP
@@ -51,21 +59,29 @@ void main()
 #else
 	vec4 color = texture2D(diffuseMap, vary_texcoord0.xy);
 #endif
-
 	
 	color.rgb *= vertex_color.rgb;
+	vec3 pos = vary_position.xyz/vary_position.w;
+
+	vec3 sunlit;
+	vec3 amblit;
+	vec3 additive;
+	vec3 atten;
+
+	calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false);
 	
 	vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb;	
-	color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a*0.75); // MAGIC NUMBER SL-12574; ALM: Off, Quality > Low
+	float env_intensity = vertex_color.a;
+	color.rgb = mix(color.rgb, envColor.rgb, env_intensity);
 
-	color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f));
+	//color.rgb = srgb_to_linear(color.rgb);
 	
-	color.rgb = fullbrightShinyAtmosTransport(color.rgb);
+	color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten);
 	color.rgb = fullbrightScaleSoftClip(color.rgb);
 
 	color.a = 1.0;
 
-	color.rgb = pow(color.rgb, vec3(1.0/2.2));
+	//color.rgb = linear_to_srgb(color.rgb);
 
 	frag_color = color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl
index 34bd8d445a0eb532d77e10ea45897715bc369c65..8f6eb7966821415448a1968d6d5605c7b4e05b75 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl
@@ -45,7 +45,7 @@ ATTRIBUTE vec2 texcoord0;
 VARYING vec4 vertex_color;
 VARYING vec2 vary_texcoord0;
 VARYING vec3 vary_texcoord1;
-
+VARYING vec4 vary_position;
 
 void main()
 {
@@ -53,7 +53,7 @@ void main()
 	vec4 vert = vec4(position.xyz,1.0);
 	passTextureIndex();
 	vec4 pos = (modelview_matrix * vert);
-	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
+	vary_position = gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
 	
 	vec3 norm = normalize(normal_matrix * normal);
 	vec3 ref = reflect(pos.xyz, -norm);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
index 4198053c99ebc073b0a3c418f940ca6969cb991a..0afd1a96720e026652903eeb17057c4173e187d2 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
@@ -1,471 +1,439 @@
-/**
-* @file materialF.glsl
-*
-* $LicenseInfo:firstyear=2007&license=viewerlgpl$
-* Second Life Viewer Source Code
-* Copyright (C) 2007, Linden Research, Inc.
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation;
-* version 2.1 of the License only.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this library; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-*
-* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
-* $/LicenseInfo$
-*/
-
-/*[EXTRA_CODE_HERE]*/
-
-//class1/deferred/materialF.glsl
-
-// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass.
-
-#define DIFFUSE_ALPHA_MODE_NONE     0
-#define DIFFUSE_ALPHA_MODE_BLEND    1
-#define DIFFUSE_ALPHA_MODE_MASK     2
-#define DIFFUSE_ALPHA_MODE_EMISSIVE 3
-
-uniform float emissive_brightness;  // fullbright flag, 1.0 == fullbright, 0.0 otherwise
-uniform int sun_up_factor;
-
-#ifdef WATER_FOG
-vec4 applyWaterFogView(vec3 pos, vec4 color);
-#endif
-
-vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten);
-vec3 scaleSoftClipFrag(vec3 l);
-
-vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten);
-vec3 fullbrightScaleSoftClip(vec3 light);
-
-void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao);
-
-vec3 srgb_to_linear(vec3 cs);
-vec3 linear_to_srgb(vec3 cs);
-
-#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
-
-#ifdef DEFINE_GL_FRAGCOLOR
-out vec4 frag_color;
-#else
-#define frag_color gl_FragColor
-#endif
-
-#ifdef HAS_SUN_SHADOW
-float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);
-#endif
-
-uniform samplerCube environmentMap;
-uniform sampler2D     lightFunc;
-
-// Inputs
-uniform vec4 morphFactor;
-uniform vec3 camPosLocal;
-uniform mat3 env_mat;
-
-uniform vec3 sun_dir;
-uniform vec3 moon_dir;
-VARYING vec2 vary_fragcoord;
-
-VARYING vec3 vary_position;
-
-uniform mat4 proj_mat;
-uniform mat4 inv_proj;
-uniform vec2 screen_res;
-
-uniform vec4 light_position[8];
-uniform vec3 light_direction[8];
-uniform vec4 light_attenuation[8];
-uniform vec3 light_diffuse[8];
-
-float getAmbientClamp();
-
-vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare, float ambiance)
-{
-    vec3 col = vec3(0);
-
-    //get light vector
-    vec3 lv = lp.xyz - v;
-
-    //get distance
-    float dist = length(lv);
-    float da = 1.0;
-
-    dist /= la;
-
-    if (dist > 0.0 && la > 0.0)
-    {
-        //normalize light vector
-        lv = normalize(lv);
-
-        //distance attenuation
-        float dist_atten = clamp(1.0 - (dist - 1.0*(1.0 - fa)) / fa, 0.0, 1.0);
-        dist_atten *= dist_atten;
-        dist_atten *= 2.0f;
-
-        if (dist_atten <= 0.0)
-        {
-            return col;
-        }
-
-        // spotlight coefficient.
-        float spot = max(dot(-ln, lv), is_pointlight);
-        da *= spot*spot; // GL_SPOT_EXPONENT=2
-
-        //angular attenuation
-        da *= dot(n, lv);
-
-        float lit = 0.0f;
-
-        float amb_da = ambiance;
-        if (da >= 0)
-        {
-            lit = max(da * dist_atten, 0.0);
-            col = lit * light_col * diffuse;
-            amb_da += (da*0.5 + 0.5) * ambiance;
-        }
-        amb_da += (da*da*0.5 + 0.5) * ambiance;
-        amb_da *= dist_atten;
-        amb_da = min(amb_da, 1.0f - lit);
-
-        // SL-10969 need to see why these are blown out
-        //col.rgb += amb_da * light_col * diffuse;
-
-        if (spec.a > 0.0)
-        {
-            //vec3 ref = dot(pos+lv, norm);
-            vec3 h = normalize(lv + npos);
-            float nh = dot(n, h);
-            float nv = dot(n, npos);
-            float vh = dot(npos, h);
-            float sa = nh;
-            float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5;
-
-            float gtdenom = 2 * nh;
-            float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
-
-            if (nh > 0.0)
-            {
-                float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da);
-                vec3 speccol = lit*scol*light_col.rgb*spec.rgb;
-                speccol = clamp(speccol, vec3(0), vec3(1));
-                col += speccol;
-
-                float cur_glare = max(speccol.r, speccol.g);
-                cur_glare = max(cur_glare, speccol.b);
-                glare = max(glare, speccol.r);
-                glare += max(cur_glare, 0.0);
-            }
-        }
-    }
-
-    return max(col, vec3(0.0, 0.0, 0.0));
-}
-
-#else
-#ifdef DEFINE_GL_FRAGCOLOR
-out vec4 frag_data[3];
-#else
-#define frag_data gl_FragData
-#endif
-#endif
-
-uniform sampler2D diffuseMap;  //always in sRGB space
-
-#ifdef HAS_NORMAL_MAP
-uniform sampler2D bumpMap;
-#endif
-
-#ifdef HAS_SPECULAR_MAP
-uniform sampler2D specularMap;
-
-VARYING vec2 vary_texcoord2;
-#endif
-
-uniform float env_intensity;
-uniform vec4 specular_color;  // specular color RGB and specular exponent (glossiness) in alpha
-
-#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK)
-uniform float minimum_alpha;
-#endif
-
-#ifdef HAS_NORMAL_MAP
-VARYING vec3 vary_mat0;
-VARYING vec3 vary_mat1;
-VARYING vec3 vary_mat2;
-VARYING vec2 vary_texcoord1;
-#else
-VARYING vec3 vary_normal;
-#endif
-
-VARYING vec4 vertex_color;
-VARYING vec2 vary_texcoord0;
-
-vec2 encode_normal(vec3 n);
-
-void main()
-{
-    vec2 pos_screen = vary_texcoord0.xy;
-
-    vec4 diffuse_srgb = texture2D(diffuseMap, vary_texcoord0.xy);
-    diffuse_srgb.rgb *= vertex_color.rgb;
-    
-    // For some reason the Transparency slider sets vertex_color.a to 0.0 both for
-    // fully opaque and for fully transparent objects. This code assumes the 0 alpha
-    // is always from the opaque end of the scale. TODO: Remove the conditional once
-    // the root cause of the slider ambiguity is fixed.
-    if (vertex_color.a > 0.0)
-    {
-        diffuse_srgb.a *= vertex_color.a;
-    }
-    vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a);
-
-#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK)
-
-    // Comparing floats cast from 8-bit values, produces acne right at the 8-bit transition points
-    float bias = 0.001953125; // 1/512, or half an 8-bit quantization
-    if (diffuse_linear.a < minimum_alpha-bias)
-    {
-        discard;
-    }
-#endif
-
-#ifdef HAS_SPECULAR_MAP
-    vec4 spec = texture2D(specularMap, vary_texcoord2.xy);
-    spec.rgb *= specular_color.rgb;
-#else
-    vec4 spec = vec4(specular_color.rgb, 1.0);
-#endif
-
-    vec3 norm = vec3(0);
-    float bmap_specular = 1.0;
-
-#ifdef HAS_NORMAL_MAP
-    vec4 bump_sample = texture2D(bumpMap, vary_texcoord1.xy);
-    norm = (bump_sample.xyz * 2) - vec3(1);
-    bmap_specular = bump_sample.w;
-
-    // convert sampled normal to tangent space normal
-    norm = vec3(dot(norm, vary_mat0),
-        dot(norm, vary_mat1),
-        dot(norm, vary_mat2));
-#else
-    norm = vary_normal;
-#endif
-
-    norm = normalize(norm);
-
-    vec2 abnormal = encode_normal(norm);
-
-    vec4 final_color = vec4(diffuse_linear.rgb, 0.0);
-
-#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_EMISSIVE)
-    final_color.a = diffuse_linear.a * 0.5; // SL-12171
-#endif
-
-    final_color.a = max(final_color.a, emissive_brightness);
-
-    // Texture
-    //     [x] Full Bright (emissive_brightness >= 1.0)
-    //     Shininess (specular)
-    //       [X] Texture
-    //       Environment Intensity = 1
-    // NOTE: There are two shaders that are used depending on the EI byte value:
-    //     EI = 0        fullbright
-    //     EI > 0 .. 255 material
-    // When it is passed to us it is normalized.
-    // We can either modify the output environment intensity
-    //   OR
-    // adjust the final color via:
-    //     final_color *= 0.666666;
-    // We don't remap the environment intensity but adjust the final color to closely simulate what non-EEP is doing.
-    vec4 final_normal = vec4(abnormal, env_intensity, 0.0);
-
-    vec3 color = vec3(0.0);
-    float al = 0;
-
-#ifdef HAS_SPECULAR_MAP
-    if (emissive_brightness >= 1.0) // ie, if fullbright
-    {
-        float ei = env_intensity*0.5 + 0.5;
-        final_normal = vec4(abnormal, ei, 0.0);
-    }
-#endif
-
-    vec4 final_specular = spec;
-
-    final_specular.a = specular_color.a;
-
-#ifdef HAS_SPECULAR_MAP
-    final_specular.a *= bmap_specular;
-    final_normal.z *= spec.a;
-#endif
-
-
-#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
-
-    //forward rendering, output just lit sRGBA
-    vec3 pos = vary_position;
-
-    float shadow = 1.0f;
-
-#ifdef HAS_SUN_SHADOW
-    shadow = sampleDirectionalShadow(pos.xyz, norm, pos_screen);
-#endif
-
-    spec = final_specular;
-
-    float envIntensity = final_normal.z;
-
-    vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
-
-    float bloom = 0.0;
-    vec3 sunlit;
-    vec3 amblit;
-    vec3 additive;
-    vec3 atten;
-
-    calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false);
-    
-    if (emissive_brightness >= 1.0)	// fullbright, skip lighting calculations
-    {
-        color = fullbrightAtmosTransportFrag(diffuse_srgb.rgb, additive, atten);
-        // This call breaks the Mac GLSL compiler/linker for unknown reasons (17Mar2020)
-        // The call is either a no-op or a pure (pow) gamma adjustment, depending on GPU level
-        // TODO: determine if we want to re-apply the gamma adjustment, and if so understand & fix Mac breakage
-        //color = fullbrightScaleSoftClip(color);
-
-        al = diffuse_srgb.a;
-    }
-    else // not fullbright, calculate lighting
-    {
-        vec3 refnormpersp = normalize(reflect(pos.xyz, norm));
-
-        //we're in sRGB space, so gamma correct this dot product so 
-        // lighting from the sun stays sharp
-        float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0);
-        da = pow(da, 1.0 / 1.3);
-
-        //darken ambient for normals perpendicular to light vector so surfaces in shadow 
-        // and facing away from light still have some definition to them.
-        // do NOT gamma correct this dot product so ambient lighting stays soft
-        float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);
-        ambient *= 0.5;
-        ambient *= ambient;
-        ambient = (1.0 - ambient);
-
-        vec3 sun_contrib = min(da, shadow) * sunlit;
-
-#if !defined(AMBIENT_KILL)
-        color = amblit;
-        color *= ambient;
-#endif
-
-#if !defined(SUNLIGHT_KILL)
-        color += sun_contrib;
-#endif
-        color *= diffuse_srgb.rgb;
-
-        float glare = 0.0;
-
-        if (spec.a > 0.0) // specular reflection
-        {
-            vec3 npos = -normalize(pos.xyz);
-
-            //vec3 ref = dot(pos+lv, norm);
-            vec3 h = normalize(light_dir.xyz + npos);
-            float nh = dot(norm, h);
-            float nv = dot(norm, npos);
-            float vh = dot(npos, h);
-            float sa = nh;
-            float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5;
-
-            float gtdenom = 2 * nh;
-            float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
-
-            if (nh > 0.0)
-            {
-                float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da);
-                vec3 sp = sun_contrib*scol / 6.0f;
-                sp = clamp(sp, vec3(0), vec3(1));
-                bloom = dot(sp, sp) / 4.0;
-#if !defined(SUNLIGHT_KILL)
-                color += sp * spec.rgb;
-#endif
-            }
-        }
-
-        if (envIntensity > 0.0)
-        {
-            //add environmentmap
-            vec3 env_vec = env_mat * refnormpersp;
-
-            vec3 reflected_color = textureCube(environmentMap, env_vec).rgb;
-
-#if !defined(SUNLIGHT_KILL)
-            color = mix(color, reflected_color, envIntensity);
-#endif
-            float cur_glare = max(reflected_color.r, reflected_color.g);
-            cur_glare = max(cur_glare, reflected_color.b);
-            cur_glare *= envIntensity*4.0;
-            glare += cur_glare;
-        }
-
-        color = atmosFragLighting(color, additive, atten);
-        color = scaleSoftClipFrag(color);
-
-        vec3 npos = normalize(-pos.xyz);
-
-        vec3 light = vec3(0, 0, 0);
-
-        //convert to linear before adding local lights
-        color = srgb_to_linear(color);
-
-#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse_linear.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare, light_attenuation[i].w );
-
-        LIGHT_LOOP(1)
-            LIGHT_LOOP(2)
-            LIGHT_LOOP(3)
-            LIGHT_LOOP(4)
-            LIGHT_LOOP(5)
-            LIGHT_LOOP(6)
-            LIGHT_LOOP(7)
-
-            glare = min(glare, 1.0);
-        al = max(diffuse_linear.a, glare)*vertex_color.a;
-
-#if !defined(LOCAL_LIGHT_KILL)
-        color += light;
-#endif
-
-        //convert to srgb as this color is being written post gamma correction
-        color = linear_to_srgb(color);
-    }
-
-#ifdef WATER_FOG
-    vec4 temp = applyWaterFogView(pos, vec4(color, al));
-    color = temp.rgb;
-    al = temp.a;
-#endif
-
-    // Don't allow alpha to exceed input value - SL-12592
-    frag_color = vec4(color, min(al, diffuse_srgb.a));
-
-#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer 
-
-    // deferred path
-    frag_data[0] = vec4(linear_to_srgb(final_color.rgb), final_color.a); //gbuffer is sRGB
-    frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent.
-    frag_data[2] = final_normal; // XY = Normal.  Z = Env. intensity.
-#endif
-}
-
+/**
+* @file materialF.glsl
+*
+* $LicenseInfo:firstyear=2007&license=viewerlgpl$
+* Second Life Viewer Source Code
+* Copyright (C) 2007, Linden Research, Inc.
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation;
+* version 2.1 of the License only.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*
+* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
+* $/LicenseInfo$
+*/
+
+/*[EXTRA_CODE_HERE]*/
+
+//class1/deferred/materialF.glsl
+
+// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass.
+
+#define DIFFUSE_ALPHA_MODE_NONE     0
+#define DIFFUSE_ALPHA_MODE_BLEND    1
+#define DIFFUSE_ALPHA_MODE_MASK     2
+#define DIFFUSE_ALPHA_MODE_EMISSIVE 3
+
+uniform float emissive_brightness;  // fullbright flag, 1.0 == fullbright, 0.0 otherwise
+uniform int sun_up_factor;
+
+#ifdef WATER_FOG
+vec4 applyWaterFogView(vec3 pos, vec4 color);
+#endif
+
+vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten);
+vec3 scaleSoftClipFrag(vec3 l);
+
+vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten);
+vec3 fullbrightScaleSoftClip(vec3 light);
+
+void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao);
+
+vec3 srgb_to_linear(vec3 cs);
+vec3 linear_to_srgb(vec3 cs);
+
+#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
+
+#ifdef DEFINE_GL_FRAGCOLOR
+out vec4 frag_color;
+#else
+#define frag_color gl_FragColor
+#endif
+
+#ifdef HAS_SUN_SHADOW
+float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);
+#endif
+
+uniform samplerCube environmentMap;
+uniform sampler2D     lightFunc;
+
+// Inputs
+uniform vec4 morphFactor;
+uniform vec3 camPosLocal;
+uniform mat3 env_mat;
+
+uniform vec3 sun_dir;
+uniform vec3 moon_dir;
+VARYING vec2 vary_fragcoord;
+
+VARYING vec3 vary_position;
+
+uniform mat4 proj_mat;
+uniform mat4 inv_proj;
+uniform vec2 screen_res;
+
+uniform vec4 light_position[8];
+uniform vec3 light_direction[8];
+uniform vec4 light_attenuation[8];
+uniform vec3 light_diffuse[8];
+
+float getAmbientClamp();
+
+vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare, float ambiance)
+{
+    vec3 col = vec3(0);
+
+    //get light vector
+    vec3 lv = lp.xyz - v;
+
+    //get distance
+    float dist = length(lv);
+    float da = 1.0;
+
+    dist /= la;
+
+    if (dist > 0.0 && la > 0.0)
+    {
+        //normalize light vector
+        lv = normalize(lv);
+
+        //distance attenuation
+        float dist_atten = clamp(1.0 - (dist - 1.0*(1.0 - fa)) / fa, 0.0, 1.0);
+        dist_atten *= dist_atten;
+        dist_atten *= 2.0f;
+
+        if (dist_atten <= 0.0)
+        {
+            return col;
+        }
+
+        // spotlight coefficient.
+        float spot = max(dot(-ln, lv), is_pointlight);
+        da *= spot*spot; // GL_SPOT_EXPONENT=2
+
+        //angular attenuation
+        da *= dot(n, lv);
+
+        float lit = 0.0f;
+
+        float amb_da = ambiance;
+        if (da >= 0)
+        {
+            lit = max(da * dist_atten, 0.0);
+            col = lit * light_col * diffuse;
+            amb_da += (da*0.5 + 0.5) * ambiance;
+        }
+        amb_da += (da*da*0.5 + 0.5) * ambiance;
+        amb_da *= dist_atten;
+        amb_da = min(amb_da, 1.0f - lit);
+
+        // SL-10969 need to see why these are blown out
+        //col.rgb += amb_da * light_col * diffuse;
+
+        if (spec.a > 0.0)
+        {
+            //vec3 ref = dot(pos+lv, norm);
+            vec3 h = normalize(lv + npos);
+            float nh = dot(n, h);
+            float nv = dot(n, npos);
+            float vh = dot(npos, h);
+            float sa = nh;
+            float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5;
+
+            float gtdenom = 2 * nh;
+            float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
+
+            if (nh > 0.0)
+            {
+                float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da);
+                vec3 speccol = lit*scol*light_col.rgb*spec.rgb;
+                speccol = clamp(speccol, vec3(0), vec3(1));
+                col += speccol;
+
+                float cur_glare = max(speccol.r, speccol.g);
+                cur_glare = max(cur_glare, speccol.b);
+                glare = max(glare, speccol.r);
+                glare += max(cur_glare, 0.0);
+            }
+        }
+    }
+
+    return max(col, vec3(0.0, 0.0, 0.0));
+}
+
+#else
+#ifdef DEFINE_GL_FRAGCOLOR
+out vec4 frag_data[3];
+#else
+#define frag_data gl_FragData
+#endif
+#endif
+
+uniform sampler2D diffuseMap;  //always in sRGB space
+
+#ifdef HAS_NORMAL_MAP
+uniform sampler2D bumpMap;
+#endif
+
+#ifdef HAS_SPECULAR_MAP
+uniform sampler2D specularMap;
+
+VARYING vec2 vary_texcoord2;
+#endif
+
+uniform float env_intensity;
+uniform vec4 specular_color;  // specular color RGB and specular exponent (glossiness) in alpha
+
+#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK)
+uniform float minimum_alpha;
+#endif
+
+#ifdef HAS_NORMAL_MAP
+VARYING vec3 vary_mat0;
+VARYING vec3 vary_mat1;
+VARYING vec3 vary_mat2;
+VARYING vec2 vary_texcoord1;
+#else
+VARYING vec3 vary_normal;
+#endif
+
+VARYING vec4 vertex_color;
+VARYING vec2 vary_texcoord0;
+
+vec2 encode_normal(vec3 n);
+
+void main()
+{
+    vec2 pos_screen = vary_texcoord0.xy;
+
+    vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy);
+	diffcol.rgb *= vertex_color.rgb;
+
+#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK)
+
+    // Comparing floats cast from 8-bit values, produces acne right at the 8-bit transition points
+    float bias = 0.001953125; // 1/512, or half an 8-bit quantization
+    if (diffcol.a < minimum_alpha-bias)
+    {
+        discard;
+    }
+#endif
+
+#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
+	vec3 gamma_diff = diffcol.rgb;
+	diffcol.rgb = srgb_to_linear(diffcol.rgb);
+#endif
+
+#ifdef HAS_SPECULAR_MAP
+    vec4 spec = texture2D(specularMap, vary_texcoord2.xy);
+    spec.rgb *= specular_color.rgb;
+#else
+    vec4 spec = vec4(specular_color.rgb, 1.0);
+#endif
+
+#ifdef HAS_NORMAL_MAP
+	vec4 norm = texture2D(bumpMap, vary_texcoord1.xy);
+
+	norm.xyz = norm.xyz * 2 - 1;
+
+	vec3 tnorm = vec3(dot(norm.xyz,vary_mat0),
+			  dot(norm.xyz,vary_mat1),
+			  dot(norm.xyz,vary_mat2));
+#else
+	vec4 norm = vec4(0,0,0,1.0);
+	vec3 tnorm = vary_normal;
+#endif
+
+    norm.xyz = normalize(tnorm.xyz);
+
+    vec2 abnormal = encode_normal(norm.xyz);
+
+    vec4 final_color = diffcol;
+
+#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE)
+	final_color.a = emissive_brightness;
+#else
+	final_color.a = max(final_color.a, emissive_brightness);
+#endif
+
+    vec4 final_specular = spec;
+    
+#ifdef HAS_SPECULAR_MAP
+    vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0);
+	final_specular.a = specular_color.a * norm.a;
+#else
+	vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0);
+	final_specular.a = specular_color.a;
+#endif
+
+#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
+
+    //forward rendering, output just lit sRGBA
+    vec3 pos = vary_position;
+
+    float shadow = 1.0f;
+
+#ifdef HAS_SUN_SHADOW
+    shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen);
+#endif
+
+    spec = final_specular;
+    vec4 diffuse = final_color;
+    float envIntensity = final_normal.z;
+
+    vec3 color = vec3(0,0,0);
+
+    vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
+
+    float bloom = 0.0;
+    vec3 sunlit;
+    vec3 amblit;
+    vec3 additive;
+    vec3 atten;
+
+    calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false);
+    
+        // This call breaks the Mac GLSL compiler/linker for unknown reasons (17Mar2020)
+        // The call is either a no-op or a pure (pow) gamma adjustment, depending on GPU level
+        // TODO: determine if we want to re-apply the gamma adjustment, and if so understand & fix Mac breakage
+        //color = fullbrightScaleSoftClip(color);
+
+    vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
+
+    //we're in sRGB space, so gamma correct this dot product so 
+    // lighting from the sun stays sharp
+    float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0);
+    da = pow(da, 1.0 / 1.3);
+
+    color = amblit;
+
+    //darken ambient for normals perpendicular to light vector so surfaces in shadow 
+    // and facing away from light still have some definition to them.
+    // do NOT gamma correct this dot product so ambient lighting stays soft
+    float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);
+    ambient *= 0.5;
+    ambient *= ambient;
+    ambient = (1.0 - ambient);
+
+    vec3 sun_contrib = min(da, shadow) * sunlit;
+    
+    color *= ambient;
+
+    color += sun_contrib;
+
+    color *= gamma_diff.rgb;
+
+    float glare = 0.0;
+
+    if (spec.a > 0.0) // specular reflection
+    {
+#if 1 //EEP
+
+        vec3 npos = -normalize(pos.xyz);
+
+        //vec3 ref = dot(pos+lv, norm);
+        vec3 h = normalize(light_dir.xyz + npos);
+        float nh = dot(norm.xyz, h);
+        float nv = dot(norm.xyz, npos);
+        float vh = dot(npos, h);
+        float sa = nh;
+        float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5;
+
+        float gtdenom = 2 * nh;
+        float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
+
+        if (nh > 0.0)
+        {
+            float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da);
+            vec3 sp = sun_contrib*scol / 6.0f;
+            sp = clamp(sp, vec3(0), vec3(1));
+            bloom = dot(sp, sp) / 4.0;
+            color += sp * spec.rgb;
+        }
+#else // PRODUCTION
+        float sa = dot(refnormpersp, sun_dir.xyz);
+		vec3 dumbshiny = sunlit*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r);
+							
+		// add the two types of shiny together
+		vec3 spec_contrib = dumbshiny * spec.rgb;
+		bloom = dot(spec_contrib, spec_contrib) / 6;
+
+		glare = max(spec_contrib.r, spec_contrib.g);
+		glare = max(glare, spec_contrib.b);
+
+		color += spec_contrib;
+#endif
+    }
+
+    color = mix(color.rgb, diffcol.rgb, diffuse.a);
+    
+    if (envIntensity > 0.0)
+    {
+        //add environmentmap
+        vec3 env_vec = env_mat * refnormpersp;
+
+        vec3 reflected_color = textureCube(environmentMap, env_vec).rgb;
+
+        color = mix(color, reflected_color, envIntensity);
+
+        float cur_glare = max(reflected_color.r, reflected_color.g);
+        cur_glare = max(cur_glare, reflected_color.b);
+        cur_glare *= envIntensity*4.0;
+        glare += cur_glare;
+    }
+
+    color = atmosFragLighting(color, additive, atten);
+    color = scaleSoftClipFrag(color);
+
+    //convert to linear before adding local lights
+    color = srgb_to_linear(color);
+
+    vec3 npos = normalize(-pos.xyz);
+
+    vec3 light = vec3(0, 0, 0);
+    
+#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 );
+
+    LIGHT_LOOP(1)
+        LIGHT_LOOP(2)
+        LIGHT_LOOP(3)
+        LIGHT_LOOP(4)
+        LIGHT_LOOP(5)
+        LIGHT_LOOP(6)
+        LIGHT_LOOP(7)
+
+    color += light;
+
+    glare = min(glare, 1.0);
+    float al = max(diffcol.a, glare)*vertex_color.a;
+
+    //convert to srgb as this color is being written post gamma correction
+    color = linear_to_srgb(color);
+
+#ifdef WATER_FOG
+    vec4 temp = applyWaterFogView(pos, vec4(color, al));
+    color = temp.rgb;
+    al = temp.a;
+#endif
+
+    frag_color = vec4(color, al);
+
+#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer 
+
+    // deferred path
+    frag_data[0] = final_color; //gbuffer is sRGB
+    frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent.
+    frag_data[2] = final_normal; // XY = Normal.  Z = Env. intensity.
+#endif
+}
+
diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
index 20ac78947be317a66c57158b465218b9c3467880..a5804220bc069a0ac8dca479953699e454e1ad16 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
@@ -63,6 +63,8 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou
 float getAmbientClamp();
 vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten);
 vec3 scaleSoftClipFrag(vec3 l);
+vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten);
+vec3 fullbrightScaleSoftClip(vec3 light);
 
 vec3 linear_to_srgb(vec3 c);
 vec3 srgb_to_linear(vec3 c);
@@ -81,11 +83,14 @@ void main()
     norm.xyz = getNorm(tc);
     
     vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
-    float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0);
-    da = pow(da, 1.0/1.3);
+    float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0);
+    float light_gamma = 1.0/1.3;
+    da = pow(da, light_gamma);
+    
+    vec4 diffuse = texture2DRect(diffuseRect, tc);
 
-    vec4 diffuse_srgb = texture2DRect(diffuseRect, tc);
-    vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a);
+    //convert to gamma space
+    //diffuse.rgb = linear_to_srgb(diffuse.rgb);
 
     vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
     vec3 color = vec3(0);
@@ -100,34 +105,27 @@ void main()
     
         calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, false);
 
+        color.rgb = amblit;
+
         float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);
         ambient *= 0.5;
         ambient *= ambient;
         ambient = (1.0 - ambient);
 
-        vec3 sun_contrib = da * sunlit;
-
-#if !defined(AMBIENT_KILL)
-        color.rgb = amblit;
         color.rgb *= ambient;
-#endif
 
-vec3 post_ambient = color.rgb;
+        vec3 sun_contrib = da * sunlit;
 
-#if !defined(SUNLIGHT_KILL)
         color.rgb += sun_contrib;
-#endif
-
-vec3 post_sunlight = color.rgb;
 
-        color.rgb *= diffuse_srgb.rgb;
-
-vec3 post_diffuse = color.rgb;
+        color.rgb *= diffuse.rgb;
 
         vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
 
         if (spec.a > 0.0) // specular reflection
         {
+
+#if 1 //EEP
             vec3 npos = -normalize(pos.xyz);
 
             //vec3 ref = dot(pos+lv, norm);
@@ -140,71 +138,55 @@ vec3 post_diffuse = color.rgb;
 
             float gtdenom = 2 * nh;
             float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
-                                    
+            
             if (nh > 0.0)
             {
                 float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
                 vec3 sp = sun_contrib*scontrib / 6.0;
                 sp = clamp(sp, vec3(0), vec3(1));
                 bloom += dot(sp, sp) / 4.0;
-#if !defined(SUNLIGHT_KILL)
                 color += sp * spec.rgb;
-#endif
             }
+#else //PRODUCTION
+            float sa = dot(refnormpersp, light_dir.xyz);
+            vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r);
+            
+            // add the two types of shiny together
+            vec3 spec_contrib = dumbshiny * spec.rgb;
+            bloom = dot(spec_contrib, spec_contrib) / 6;
+            color.rgb += spec_contrib;
+#endif
+
         }
        
- vec3 post_spec = color.rgb;
+       color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a);
 
         if (envIntensity > 0.0)
         { //add environmentmap
             vec3 env_vec = env_mat * refnormpersp;
             vec3 reflected_color = textureCube(environmentMap, env_vec).rgb;
-#if !defined(SUNLIGHT_KILL)
-            color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality <= Mid+
-#endif
+            color = mix(color.rgb, reflected_color, envIntensity);
         }
-        else
-        {
-            color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a);
-        }
-
-vec3 post_env = color.rgb;
-
-        if (norm.w < 1)
+       
+        if (norm.w < 0.5)
         {
-#if !defined(SUNLIGHT_KILL)
-            color = atmosFragLighting(color, additive, atten);
-            color = scaleSoftClipFrag(color);
-#endif
+            color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a);
+            color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a);
         }
 
-vec3 post_atmo = color.rgb;
-
         #ifdef WATER_FOG
             vec4 fogged = applyWaterFogView(pos.xyz,vec4(color, bloom));
             color = fogged.rgb;
             bloom = fogged.a;
         #endif
 
-// srgb colorspace debuggables
-//color.rgb = amblit;
-//color.rgb = sunlit;
-//color.rgb = post_ambient;
-//color.rgb = sun_contrib;
-//color.rgb = post_sunlight;
-//color.rgb = diffuse_srgb.rgb;
-//color.rgb = post_diffuse;
-//color.rgb = post_spec;
-//color.rgb = post_env;
-//color.rgb = post_atmo;
-
     }
 
 // linear debuggables
 //color.rgb = vec3(final_da);
 //color.rgb = vec3(ambient);
 //color.rgb = vec3(scol);
-//color.rgb = diffuse_linear.rgb;
+//color.rgb = diffuse_srgb.rgb;
 
     // convert to linear as fullscreen lights need to sum in linear colorspace
     // and will be gamma (re)corrected downstream...
diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl
index b86867c460652b34ee144f3efd3a87bf0fd1f34f..a157e9c017bfd8fdabb4328357eca58f0f77afea 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl
@@ -152,7 +152,7 @@ void main()
 	spec = pow(spec, 128.0);
 
 	//figure out distortion vector (ripply)   
-	vec2 distort2 = distort+wavef.xy*refScale*0.16/max(dmod*df1, 1.0);
+	vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0);
 		
 	vec4 fb = texture2D(screenTex, distort2);
 	
@@ -164,14 +164,21 @@ void main()
 	
 	color.rgb += spec * specular;
 
-	//color.rgb = atmosTransport(color.rgb);
+	color.rgb = atmosTransport(color.rgb);
 	color.rgb = scaleSoftClip(color.rgb);
     
 	color.a   = spec * sunAngle2;
     
 	vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz);
 
-	frag_data[0] = vec4(color.rgb, color); // diffuse
-	frag_data[1] = vec4(0);		// speccolor, spec
-	frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.0, 0);// normalxy, 0, 0
+	//frag_data[0] = color;
+
+    // TODO: The non-obvious assignment below is copied from the pre-EEP WL shader code
+    //       Unfortunately, fixing it causes a mismatch for EEP, and so it remains...  for now
+    //       SL-12975 (unfix pre-EEP broken alpha)
+    frag_data[0] = vec4(color.rgb, color);  // Effectively, color.rgbr
+
+
+    frag_data[1] = vec4(0);		// speccolor, spec
+	frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 0
 }
diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl
index bbfec3b5320ecc5a51d853a72e8552226121abe4..e53bb4617732ea48a4be4087d20abfd0692e1bef 100644
--- a/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl
+++ b/indra/newview/app_settings/shaders/class1/environment/terrainWaterF.glsl
@@ -39,6 +39,8 @@ uniform sampler2D detail_2;
 uniform sampler2D detail_3;
 uniform sampler2D alpha_ramp;
 
+vec3 atmosLighting(vec3 light);
+
 vec4 applyWaterFog(vec4 color);
 
 void main()
@@ -55,10 +57,10 @@ void main()
 	float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a;
 	float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a;
 	vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal );
-
-    outColor.rgb *= vertex_color.rgb;	
+	
+	/// Add WL Components
+	outColor.rgb = atmosLighting(outColor.rgb * vertex_color.rgb);
+	
 	outColor = applyWaterFog(outColor);
-
 	frag_color = outColor;
 }
-
diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl
index b3ae64bd82b8536170ab4dbb660a43bae30d4dba..d37099712354ccb98865ac4b14bf28d7e9fe410a 100644
--- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl
+++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl
@@ -1,5 +1,5 @@
 /** 
- * @file class1/environment/waterF.glsl
+ * @file waterF.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
@@ -32,7 +32,7 @@ out vec4 frag_color;
 vec3 scaleSoftClip(vec3 inColor);
 vec3 atmosTransport(vec3 inColor);
 
-uniform sampler2D bumpMap;   
+uniform sampler2D bumpMap;
 uniform sampler2D bumpMap2;
 uniform float     blend_factor;
 uniform sampler2D screenTex;
@@ -50,7 +50,7 @@ uniform vec3 normScale;
 uniform float fresnelScale;
 uniform float fresnelOffset;
 uniform float blurMultiplier;
-uniform int water_edge;
+
 
 //bigWave is (refCoord.w, view.w);
 VARYING vec4 refCoord;
@@ -59,28 +59,28 @@ VARYING vec4 view;
 
 vec3 BlendNormal(vec3 bump1, vec3 bump2)
 {
-    //vec3 normal   = bump1.xyz * vec3( 2.0,  2.0, 2.0) - vec3(1.0, 1.0,  0.0);
-    //vec3 normal2  = bump2.xyz * vec3(-2.0, -2.0, 2.0) + vec3(1.0, 1.0, -1.0);
-    //vec3 n        = normalize(normal * dot(normal, normal2) - (normal2 * normal.z));
-    vec3 n = normalize(mix(bump1, bump2, blend_factor));
+    vec3 n = mix(bump1, bump2, blend_factor);
     return n;
 }
 
+
 void main() 
 {
-    vec4 color;
-    
-    float dist = length(view.xy);
-    
-    //normalize view vector
-    vec3 viewVec = normalize(view.xyz);
-    
-    //get wave normals
-    vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
+	vec4 color;
+	
+	float dist = length(view.xy);
+	
+	//normalize view vector
+	vec3 viewVec = normalize(view.xyz);
+	
+	//get wave normals
+    vec2 bigwave = vec2(refCoord.w, view.w);
+    vec3 wave1_a = texture2D(bumpMap, bigwave      ).xyz*2.0-1.0;
     vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0;
     vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0;
 
-    vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
+
+    vec3 wave1_b = texture2D(bumpMap2, bigwave      ).xyz*2.0-1.0;
     vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0;
     vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0;
 
@@ -88,80 +88,81 @@ void main()
     vec3 wave2 = BlendNormal(wave2_a, wave2_b);
     vec3 wave3 = BlendNormal(wave3_a, wave3_b);
 
-    //get base fresnel components   
-    
-    vec3 df = vec3(
-                    dot(viewVec, wave1),
-                    dot(viewVec, (wave2 + wave3) * 0.5),
-                    dot(viewVec, wave3)
-                 ) * fresnelScale + fresnelOffset;
-    df *= df;
-            
-    vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
-    
-    float dist2 = dist;
-    dist = max(dist, 5.0);
-    
-    float dmod = sqrt(dist);
-    
-    vec2 dmod_scale = vec2(dmod*dmod, dmod);
-    
-    //get reflected color
-    vec2 refdistort1 = wave1.xy*normScale.x;
-    vec2 refvec1 = distort+refdistort1/dmod_scale;
-    vec4 refcol1 = texture2D(refTex, refvec1);
-    
-    vec2 refdistort2 = wave2.xy*normScale.y;
-    vec2 refvec2 = distort+refdistort2/dmod_scale;
-    vec4 refcol2 = texture2D(refTex, refvec2);
-    
-    vec2 refdistort3 = wave3.xy*normScale.z;
-    vec2 refvec3 = distort+refdistort3/dmod_scale;
-    vec4 refcol3 = texture2D(refTex, refvec3);
-
-    vec4 refcol = refcol1 + refcol2 + refcol3;
-    float df1 = df.x + df.y + df.z;
-    df1 *= 0.666666f;
-    refcol *= df1;
-    
-    vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5;
-    
-    wavef.z *= max(-viewVec.z, 0.1);
-    wavef = normalize(wavef);
-    
-    float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset;
-    
-    vec2 refdistort4 = wavef.xy*0.125;
-    refdistort4.y -= abs(refdistort4.y);
-    vec2 refvec4 = distort+refdistort4/dmod;
-    float dweight = min(dist2*blurMultiplier, 1.0);
-    vec4 baseCol = texture2D(refTex, refvec4);
-    refcol = mix(baseCol*df2, refcol, dweight);
-
-    //get specular component
-    float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0);
-        
-    //harden specular
-    spec = pow(spec, 128.0);
-
-    //figure out distortion vector (ripply)   
-    vec2 distort2 = distort+wavef.xy*refScale*0.16/max(dmod*df1, 1.0);
-        
-    vec4 fb = texture2D(screenTex, distort2);
-    
-    //mix with reflection
-    // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug
-    color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.9999999);
-    color.rgb += spec * specular;
-
-    color.a = spec * sunAngle2;
-
-    //color.rgb = atmosTransport(color.rgb);
+
+	//get base fresnel components	
+	
+	vec3 df = vec3(
+					dot(viewVec, wave1),
+					dot(viewVec, (wave2 + wave3) * 0.5),
+					dot(viewVec, wave3)
+				 ) * fresnelScale + fresnelOffset;
+	df *= df;
+		    
+	vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
+	
+	float dist2 = dist;
+	dist = max(dist, 5.0);
+	
+	float dmod = sqrt(dist);
+	
+	vec2 dmod_scale = vec2(dmod*dmod, dmod);
+	
+	//get reflected color
+	vec2 refdistort1 = wave1.xy*normScale.x;
+	vec2 refvec1 = distort+refdistort1/dmod_scale;
+	vec4 refcol1 = texture2D(refTex, refvec1);
+	
+	vec2 refdistort2 = wave2.xy*normScale.y;
+	vec2 refvec2 = distort+refdistort2/dmod_scale;
+	vec4 refcol2 = texture2D(refTex, refvec2);
+	
+	vec2 refdistort3 = wave3.xy*normScale.z;
+	vec2 refvec3 = distort+refdistort3/dmod_scale;
+	vec4 refcol3 = texture2D(refTex, refvec3);
+
+	vec4 refcol = refcol1 + refcol2 + refcol3;
+	float df1 = df.x + df.y + df.z;
+	refcol *= df1 * 0.333;
+	
+	vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5;
+	
+	wavef.z *= max(-viewVec.z, 0.1);
+	wavef = normalize(wavef);
+	
+	float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset;
+	
+	vec2 refdistort4 = wavef.xy*0.125;
+	refdistort4.y -= abs(refdistort4.y);
+	vec2 refvec4 = distort+refdistort4/dmod;
+	float dweight = min(dist2*blurMultiplier, 1.0);
+	vec4 baseCol = texture2D(refTex, refvec4);
+	refcol = mix(baseCol*df2, refcol, dweight);
+
+	//get specular component
+	float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0);
+		
+	//harden specular
+	spec = pow(spec, 128.0);
+
+	//figure out distortion vector (ripply)   
+	vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0);
+		
+	vec4 fb = texture2D(screenTex, distort2);
+	
+	//mix with reflection
+	// Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug
+	color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999);
+	color.rgb += spec * specular;
+	
+	color.rgb = atmosTransport(color.rgb);
 	color.rgb = scaleSoftClip(color.rgb);
+	color.a = spec * sunAngle2;
+	
+	frag_color = color;
 
 #if defined(WATER_EDGE)
     gl_FragDepth = 0.9999847f;
 #endif
-
-    frag_color = color;
+	
 }
+
diff --git a/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl
index 79b552ee1a9656fcb18a5e93d406ab30cd8d2b6c..1e244d9dfdae3d0e1ef7920ba3ff2b58c0e75431 100644
--- a/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl
@@ -35,6 +35,7 @@ ATTRIBUTE vec2 texcoord0;
 VARYING vec4 vertex_color;
 VARYING vec2 vary_texcoord0;
 VARYING vec3 vary_texcoord1;
+VARYING vec4 vary_position;
 
 
 void calcAtmospherics(vec3 inPositionEye);
@@ -46,6 +47,9 @@ void main()
 	
 	mat = modelview_matrix * mat;
 	vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz;
+
+    mat4 mvp = modelview_matrix * projection_matrix;
+    vary_position = mvp * vec4(position, 1.0);
 	
 	vec4 norm = vec4(position.xyz, 1.0);
 	norm.xyz += normal.xyz;
diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
index 9c7a4df76746b0cd1f76f030781a7de0d6e34550..b0dff0c62839c89935e2079b6f2118172eb083d2 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
@@ -22,7 +22,7 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
 #extension GL_ARB_texture_rectangle : enable
 #extension GL_ARB_shader_texture_lod : enable
 
@@ -63,6 +63,8 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou
 float getAmbientClamp();
 vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten);
 vec3 scaleSoftClipFrag(vec3 l);
+vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten);
+vec3 fullbrightScaleSoftClip(vec3 light);
 
 vec3 linear_to_srgb(vec3 c);
 vec3 srgb_to_linear(vec3 c);
@@ -78,63 +80,55 @@ void main()
     vec4 pos = getPositionWithDepth(tc, depth);
     vec4 norm = texture2DRect(normalMap, tc);
     float envIntensity = norm.z;
-    norm.xyz = getNorm(tc); // unpack norm
-
-    vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;        
+    norm.xyz = getNorm(tc);
+    
+    vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
+    float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0);
+    float light_gamma = 1.0/1.3;
+    da = pow(da, light_gamma);
+    
+    vec4 diffuse = texture2DRect(diffuseRect, tc);
+    
+    vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
 
-    float scol = 1.0;
     vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg;
+    scol_ambocc = pow(scol_ambocc, vec2(light_gamma));
 
-    float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0);
-    da = pow(da, 1.0/1.3);
-    vec4 diffuse_srgb   = texture2DRect(diffuseRect, tc);
-    vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a);
+    float scol = max(scol_ambocc.r, diffuse.a); 
 
-    // clamping to alpha value kills underwater shadows...
-    //scol = max(scol_ambocc.r, diffuse_linear.a);
-    scol = scol_ambocc.r;
+    float ambocc = scol_ambocc.g;
 
-    vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
     vec3 color = vec3(0);
     float bloom = 0.0;
     {
-        float ambocc = scol_ambocc.g;
-
         vec3 sunlit;
         vec3 amblit;
         vec3 additive;
         vec3 atten;
     
         calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true);
-        
+
+        color.rgb = amblit;
+
         float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);
         ambient *= 0.5;
         ambient *= ambient;
         ambient = (1.0 - ambient);
 
-        vec3 sun_contrib = min(scol, da) * sunlit;
-
-#if !defined(AMBIENT_KILL)
-        color.rgb = amblit;
         color.rgb *= ambient;
-#endif
 
-vec3 post_ambient = color.rgb;
+        vec3 sun_contrib = min(da, scol) * sunlit;
 
-#if !defined(SUNLIGHT_KILL)
         color.rgb += sun_contrib;
-#endif
-
-vec3 post_sunlight = color.rgb;
-
-        color.rgb *= diffuse_srgb.rgb;
 
-vec3 post_diffuse = color.rgb;
+        color.rgb *= diffuse.rgb;
 
         vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
 
         if (spec.a > 0.0) // specular reflection
         {
+
+#if 1 //EEP
             vec3 npos = -normalize(pos.xyz);
 
             //vec3 ref = dot(pos+lv, norm);
@@ -147,75 +141,60 @@ vec3 post_diffuse = color.rgb;
 
             float gtdenom = 2 * nh;
             float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
-                                    
+            
             if (nh > 0.0)
             {
                 float scontrib = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
                 vec3 sp = sun_contrib*scontrib / 6.0;
                 sp = clamp(sp, vec3(0), vec3(1));
                 bloom += dot(sp, sp) / 4.0;
-#if !defined(SUNLIGHT_KILL)
                 color += sp * spec.rgb;
-#endif
             }
+#else //PRODUCTION
+            float sa = dot(refnormpersp, light_dir.xyz);
+            vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r);
+            
+            // add the two types of shiny together
+            vec3 spec_contrib = dumbshiny * spec.rgb;
+            bloom = dot(spec_contrib, spec_contrib) / 6;
+            color.rgb += spec_contrib;
+#endif
+
         }
        
- vec3 post_spec = color.rgb;
+       color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a);
 
         if (envIntensity > 0.0)
         { //add environmentmap
             vec3 env_vec = env_mat * refnormpersp;
             vec3 reflected_color = textureCube(environmentMap, env_vec).rgb;
-#if !defined(SUNLIGHT_KILL)
-            color = mix(color.rgb, reflected_color, envIntensity*0.75); // MAGIC NUMBER SL-12574; ALM: On, Quality >= High
-#endif
+            color = mix(color.rgb, reflected_color, envIntensity);
         }
-        else
-        {
-            color.rgb = mix(color.rgb, diffuse_srgb.rgb, diffuse_srgb.a);
-        }
-
-vec3 post_env = color.rgb;
-
-        if (norm.w < 1)
+       
+        if (norm.w < 0.5)
         {
-#if !defined(SUNLIGHT_KILL)
-            vec3 p = normalize(pos.xyz);
-            color = atmosFragLighting(color, additive, atten);
-            color = scaleSoftClipFrag(color);
-#endif
+            color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a);
+            color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a);
         }
 
-vec3 post_atmo = color.rgb;
-
         #ifdef WATER_FOG
             vec4 fogged = applyWaterFogView(pos.xyz,vec4(color, bloom));
             color = fogged.rgb;
             bloom = fogged.a;
         #endif
 
-// srgb colorspace debuggables
-//color.rgb = amblit;
-//color.rgb = sunlit;
-//color.rgb = post_ambient;
-//color.rgb = sun_contrib;
-//color.rgb = post_sunlight;
-//color.rgb = diffuse_srgb.rgb;
-//color.rgb = post_diffuse;
-//color.rgb = post_spec;
-//color.rgb = post_env;
-//color.rgb = post_atmo;
-
     }
 
 // linear debuggables
 //color.rgb = vec3(final_da);
 //color.rgb = vec3(ambient);
 //color.rgb = vec3(scol);
-//color.rgb = diffuse_linear.rgb;
+//color.rgb = diffuse_srgb.rgb;
 
-        //output linear RGB as lights are summed up in linear space and then gamma corrected prior to the 
-        //post deferred passes
+    // convert to linear as fullscreen lights need to sum in linear colorspace
+    // and will be gamma (re)corrected downstream...
+    
     frag_color.rgb = srgb_to_linear(color.rgb);
     frag_color.a = bloom;
 }
+
diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl
index 8b8b338f6851ffbf916ec28a3399b67b3c6e4b5f..bd11aa3f05865f385d1ad22f17f5dfa038a8f3f7 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl
@@ -31,10 +31,19 @@ uniform vec2 screen_res;
 
 VARYING vec2 vary_fragcoord;
 
+// forwards
+void setAtmosAttenuation(vec3 c);
+void setAdditiveColor(vec3 c);
+
 void main()
 {
 	//transform vertex
 	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
+
+    // appease OSX GLSL compiler/linker by touching all the varyings we said we would
+    setAtmosAttenuation(vec3(1));
+    setAdditiveColor(vec3(0));
+
 	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
 }
diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl
index a4bd0d566baa5d6a6446ee3d18da2e3a9aa09fcd..4c418e414f2f4670bb90e4ef277a9c0c9494c45f 100644
--- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl
+++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl
@@ -24,6 +24,12 @@
  */
 
 // VARYING param funcs
+
+
+uniform vec3 sun_dir;
+uniform vec3 moon_dir;
+uniform int sun_up_factor;
+
 void setSunlitColor(vec3 v);
 void setAmblitColor(vec3 v);
 void setAdditiveColor(vec3 v);
@@ -35,17 +41,16 @@ vec3 getAdditiveColor();
 void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao);
 
 void calcAtmospherics(vec3 inPositionEye) {
-
     vec3 P = inPositionEye;
     setPositionEye(P);
     vec3 tmpsunlit = vec3(1);
     vec3 tmpamblit = vec3(1);
     vec3 tmpaddlit = vec3(1);
     vec3 tmpattenlit = vec3(1);
-    calcAtmosphericVars(inPositionEye, vec3(0), 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, false);
+	vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;	
+    calcAtmosphericVars(inPositionEye, light_dir, 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, false);
     setSunlitColor(tmpsunlit);
     setAmblitColor(tmpamblit);
     setAdditiveColor(tmpaddlit);
     setAtmosAttenuation(tmpattenlit);
 }
-
diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl
index ea37610502e25b7956b9b3d70c6f8a0ec560ff23..d758f85d713eafb34643c126c6212f17ef6fa136 100644
--- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl
+++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsVarsF.glsl
@@ -24,7 +24,6 @@
  */
  
 
-VARYING vec3 vary_SunlitColor;
 VARYING vec3 vary_AdditiveColor;
 VARYING vec3 vary_AtmosAttenuation;
 
diff --git a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl
index f69d36f715897830e1ac6a0695f8e960592a08b8..b53a2e237f332bfb2e39157cf9c5b74b47399e32 100644
--- a/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl
+++ b/indra/newview/app_settings/shaders/class2/windlight/transportF.glsl
@@ -34,14 +34,9 @@ uniform int no_atmo;
 
 vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten)
 {
-    if (no_atmo == 1)
-    {
-        return light * 2.0;
-    }
-    // fullbright responds minimally to atmos scatter effects 
-    light *= min(15.0 * atten.r, 1.0);
-    light += (0.1 * additive);
-    return light * 2.0;
+    light *= atten.r;
+	light += additive * 2.0;
+	return light;
 }
 
 vec3 atmosTransport(vec3 light)
@@ -51,8 +46,8 @@ vec3 atmosTransport(vec3 light)
 
 vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten)
 {
-    float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1;
-    return atmosTransportFrag(light * 0.5, additive * brightness, atten);
+    float brightness = dot(light.rgb * 0.5, vec3(0.3333)) + 0.1;    
+    return mix(atmosTransportFrag(light.rgb, additive, atten), light.rgb + additive, brightness * brightness);
 }
 
 vec3 fullbrightAtmosTransport(vec3 light)
@@ -62,6 +57,6 @@ vec3 fullbrightAtmosTransport(vec3 light)
 
 vec3 fullbrightShinyAtmosTransport(vec3 light)
 {
-    float brightness = dot(light.rgb * 0.5, vec3(0.33333)) + 0.1;
-    return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * brightness), getAtmosAttenuation());
+    float brightness = dot(light.rgb, vec3(0.33333));
+    return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness);
 }
diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl
index aa7dbc39ce23a717015bd1821c8dc3a41bdd466e..545a32a227453028da553139c9d1f17a348a997b 100644
--- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl
+++ b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl
@@ -52,7 +52,8 @@ vec3 atmosTransport(vec3 light)
 vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten)
 {
     float brightness = dot(light.rgb, vec3(0.33333));
-    return atmosTransportFrag(light * 0.5, additive * (brightness * 0.5 + 0.5), atten);
+    return vec3(1,0,1);
+    //return atmosTransportFrag(light * 0.5, additive * (brightness * 0.5 + 0.5), atten);
 }
 
 vec3 fullbrightAtmosTransport(vec3 light)
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index e26ff7cc91b67d19ab582f1822793b57f34c750f..5597e6016fc30cb2e5efcf3cc1e68b8c63180c49 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -33,6 +33,7 @@
 #include "llfeaturemanager.h"
 #include "lluictrlfactory.h"
 #include "lltexteditor.h"
+#include "llenvironment.h"
 #include "llerrorcontrol.h"
 #include "lleventtimer.h"
 #include "llviewertexturelist.h"
@@ -1920,6 +1921,12 @@ bool LLAppViewer::cleanup()
 	// Store the time of our current logoff
 	gSavedPerAccountSettings.setU32("LastLogoff", time_corrected());
 
+    if (LLEnvironment::instanceExists())
+    {
+        //Store environment settings if nessesary
+        LLEnvironment::getInstance()->saveToSettings();
+    }
+
 	// Must do this after all panels have been deleted because panels that have persistent rects
 	// save their rects on delete.
 	gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp
index b8c5648cca7f2ba26611ec91e076f885dea5739f..0e1c4f943468441151193def0616499d121d1831 100644
--- a/indra/newview/llenvironment.cpp
+++ b/indra/newview/llenvironment.cpp
@@ -101,6 +101,8 @@ namespace
     const std::string LISTENER_NAME("LLEnvironmentSingleton");
     const std::string PUMP_EXPERIENCE("experience_permission");
 
+    const std::string LOCAL_ENV_STORAGE_FILE("local_environment_data.bin");
+
     //---------------------------------------------------------------------
     LLTrace::BlockTimerStatHandle   FTM_ENVIRONMENT_UPDATE("Update Environment Tick");
     LLTrace::BlockTimerStatHandle   FTM_SHADER_PARAM_UPDATE("Update Shader Parameters");
@@ -1604,11 +1606,8 @@ void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLS
 
 void LLEnvironment::updateShaderUniforms(LLGLSLShader *shader)
 {
-    if (gPipeline.canUseWindLightShaders())
-    {        
-        updateGLVariablesForSettings(shader, mCurrentEnvironment->getWater());
-        updateGLVariablesForSettings(shader, mCurrentEnvironment->getSky());
-    }    
+    updateGLVariablesForSettings(shader, mCurrentEnvironment->getWater());
+    updateGLVariablesForSettings(shader, mCurrentEnvironment->getSky());
 }
 
 void LLEnvironment::recordEnvironment(S32 parcel_id, LLEnvironment::EnvironmentInfo::ptr_t envinfo, LLSettingsBase::Seconds transition)
@@ -2448,7 +2447,6 @@ LLEnvironment::DayInstance::DayInstance(EnvSelection_t env) :
     mBlenderSky(),
     mBlenderWater(),
     mInitialized(false),
-    mType(TYPE_INVALID),
     mSkyTrack(1),
     mEnv(env),
     mAnimateFlags(0)
@@ -2467,7 +2465,6 @@ LLEnvironment::DayInstance::ptr_t LLEnvironment::DayInstance::clone() const
     environment->mBlenderSky = mBlenderSky;
     environment->mBlenderWater = mBlenderWater;
     environment->mInitialized = mInitialized;
-    environment->mType = mType;
     environment->mSkyTrack = mSkyTrack;
     environment->mAnimateFlags = mAnimateFlags;
 
@@ -2491,7 +2488,6 @@ bool LLEnvironment::DayInstance::applyTimeDelta(const LLSettingsBase::Seconds& d
 
 void LLEnvironment::DayInstance::setDay(const LLSettingsDay::ptr_t &pday, LLSettingsDay::Seconds daylength, LLSettingsDay::Seconds dayoffset)
 {
-    mType = TYPE_CYCLED;
     mInitialized = false;
 
     mAnimateFlags = 0;
@@ -2512,7 +2508,6 @@ void LLEnvironment::DayInstance::setDay(const LLSettingsDay::ptr_t &pday, LLSett
 
 void LLEnvironment::DayInstance::setSky(const LLSettingsSky::ptr_t &psky)
 {
-    mType = TYPE_FIXED;
     mInitialized = false;
 
     bool different_sky = mSky != psky;
@@ -2532,7 +2527,6 @@ void LLEnvironment::DayInstance::setSky(const LLSettingsSky::ptr_t &psky)
 
 void LLEnvironment::DayInstance::setWater(const LLSettingsWater::ptr_t &pwater)
 {
-    mType = TYPE_FIXED;
     mInitialized = false;
 
     bool different_water = mWater != pwater;
@@ -2554,7 +2548,6 @@ void LLEnvironment::DayInstance::initialize()
 
 void LLEnvironment::DayInstance::clear()
 {
-    mType = TYPE_INVALID;
     mDayCycle.reset();
     mSky.reset();
     mWater.reset();
@@ -2692,6 +2685,236 @@ void LLEnvironment::DayTransition::animate()
     });
 }
 
+void LLEnvironment::saveToSettings()
+{
+    std::string user_dir = gDirUtilp->getLindenUserDir();
+    if (user_dir.empty())
+    {
+        // not logged in
+        return;
+    }
+    bool has_data = false;
+
+    if (gSavedSettings.getBOOL("EnvironmentPersistAcrossLogin"))
+    {
+        DayInstance::ptr_t environment = getEnvironmentInstance(ENV_LOCAL);
+        if (environment)
+        {
+            // Environment is 'layered'. No data in ENV_LOCAL means we are using parcel/region
+            // Store local environment for next session
+            LLSD env_data;
+
+            LLSettingsDay::ptr_t day = environment->getDayCycle();
+            if (day)
+            {
+                const std::string name = day->getName();
+                const LLUUID asset_id = day->getAssetId();
+                if (asset_id.notNull())
+                {
+                    // just save the id
+                    env_data["day_id"] = asset_id;
+                    env_data["day_length"] = LLSD::Integer(environment->getDayLength());
+                    env_data["day_offset"] = LLSD::Integer(environment->getDayOffset());
+                    has_data = true;
+                }
+                else if (!name.empty() && name != LLSettingsBase::DEFAULT_SETTINGS_NAME)
+                {
+                    // This setting was created locally and was not saved
+                    // The only option is to save the whole thing
+                    env_data["day_llsd"] = day->getSettings();
+                    env_data["day_length"] = LLSD::Integer(environment->getDayLength());
+                    env_data["day_offset"] = LLSD::Integer(environment->getDayOffset());
+                    has_data = true;
+                }
+            }
+
+            LLSettingsSky::ptr_t sky = environment->getSky();
+            if ((environment->getFlags() & DayInstance::NO_ANIMATE_SKY) && sky)
+            {
+                const std::string name = sky->getName();
+                const LLUUID asset_id = sky->getAssetId();
+                if (asset_id.notNull())
+                {
+                    // just save the id
+                    env_data["sky_id"] = asset_id;
+                    has_data = true;
+                }
+                else if (!name.empty() && name != LLSettingsBase::DEFAULT_SETTINGS_NAME)
+                {
+                    // This setting was created locally and was not saved
+                    // The only option is to save the whole thing
+                    env_data["sky_llsd"] = sky->getSettings();
+                    has_data = true;
+                }
+                has_data = true;
+            }
+
+            LLSettingsWater::ptr_t water = environment->getWater();
+            if ((environment->getFlags() & DayInstance::NO_ANIMATE_WATER) && water)
+            {
+                const std::string name = water->getName();
+                const LLUUID asset_id = water->getAssetId();
+                if (asset_id.notNull())
+                {
+                    // just save the id
+                    env_data["water_id"] = asset_id;
+                    has_data = true;
+                }
+                else if (!name.empty() && name != LLSettingsBase::DEFAULT_SETTINGS_NAME)
+                {
+                    // This setting was created locally and was not saved
+                    // The only option is to save the whole thing
+                    env_data["water_llsd"] = water->getSettings();
+                    has_data = true;
+                }
+            }
+
+            std::string user_filepath = user_dir + gDirUtilp->getDirDelimiter() + LOCAL_ENV_STORAGE_FILE;
+            llofstream out(user_filepath.c_str(), std::ios_base::out | std::ios_base::binary);
+            if (out.good())
+            {
+                LLSDSerialize::toBinary(env_data, out);
+                out.close();
+            }
+            else
+            {
+                LL_WARNS("ENVIRONMENT") << "Unable to open " << user_filepath << " for output." << LL_ENDL;
+            }
+        }
+    }
+
+    if (!has_data)
+    {
+        LLFile::remove(user_dir + gDirUtilp->getDirDelimiter() + LOCAL_ENV_STORAGE_FILE, ENOENT);
+    }
+}
+
+void LLEnvironment::loadSkyWaterFromSettings(const LLSD &env_data, bool &valid, bool &assets_present)
+{
+    if (env_data.has("sky_id"))
+    {
+        // causes asset loaded callback and an update
+        setEnvironment(ENV_LOCAL, env_data["sky_id"].asUUID());
+        valid = true;
+        assets_present = true;
+    }
+    else if (env_data.has("sky_llsd"))
+    {
+        LLSettingsSky::ptr_t sky = std::make_shared<LLSettingsVOSky>(env_data["sky_llsd"]);
+        setEnvironment(ENV_LOCAL, sky);
+        valid = true;
+    }
+
+    if (env_data.has("water_id"))
+    {
+        // causes asset loaded callback and an update
+        setEnvironment(ENV_LOCAL, env_data["water_id"].asUUID());
+        valid = true;
+        assets_present = true;
+    }
+    else if (env_data.has("water_llsd"))
+    {
+        LLSettingsWater::ptr_t sky = std::make_shared<LLSettingsVOWater>(env_data["water_llsd"]);
+        setEnvironment(ENV_LOCAL, sky);
+        valid = true;
+    }
+}
+
+bool LLEnvironment::loadFromSettings()
+{
+    if (!gSavedSettings.getBOOL("EnvironmentPersistAcrossLogin"))
+    {
+        return false;
+    }
+
+    std::string user_path = gDirUtilp->getLindenUserDir();
+    if (user_path.empty())
+    {
+        LL_WARNS("ENVIRONMENT") << "Can't load previous environment, Environment was initialized before user logged in" << LL_ENDL;
+        return false;
+    }
+    std::string user_filepath(user_path + gDirUtilp->getDirDelimiter() + LOCAL_ENV_STORAGE_FILE);
+    if (!gDirUtilp->fileExists(user_filepath))
+    {
+        // No previous environment
+        return false;
+    }
+
+    LLSD env_data;
+    llifstream file(user_filepath.c_str(), std::ios_base::in | std::ios_base::binary);
+    if (file.is_open())
+    {
+        LLSDSerialize::fromBinary(env_data, file, LLSDSerialize::SIZE_UNLIMITED);
+        if (env_data.isUndefined())
+        {
+            LL_WARNS("ENVIRONMENT") << "error loading " << user_filepath << LL_ENDL;
+            return false;
+        }
+        else
+        {
+            LL_INFOS("ENVIRONMENT") << "Loaded previous session environment from: " << user_filepath << LL_ENDL;
+        }
+        file.close();
+    }
+    else
+    {
+        LL_INFOS("ENVIRONMENT") << "Unable to open previous session environment file " << user_filepath << LL_ENDL;
+    }
+
+    if (!env_data.isMap() || env_data.emptyMap())
+    {
+        LL_DEBUGS("ENVIRONMENT") << "Empty map loaded from: " << user_filepath << LL_ENDL;
+        return false;
+    }
+
+    bool valid = false;
+    bool has_assets = false;
+
+    if (env_data.has("day_id"))
+    {
+        LLSettingsDay::Seconds length = LLSettingsDay::Seconds(env_data["day_length"].asInteger());
+        LLSettingsDay::Seconds offset = LLSettingsDay::Seconds(env_data["day_offset"].asInteger());
+        LLUUID assetId = env_data["day_id"].asUUID();
+
+        LLSettingsVOBase::getSettingsAsset(assetId,
+            [this, length, offset, env_data](LLUUID asset_id, LLSettingsBase::ptr_t settings, S32 status, LLExtStat)
+        {
+            // Day should be always applied first,
+            // otherwise it will override sky or water that was set earlier
+            // so wait for asset to load before applying sky/water
+            onSetEnvAssetLoaded(ENV_LOCAL, asset_id, settings, length, offset, TRANSITION_DEFAULT, status, NO_VERSION);
+            bool valid = false, has_assets = false;
+            loadSkyWaterFromSettings(env_data, valid, has_assets);
+            if (!has_assets && valid)
+            {
+                // Settings were loaded from file without having an asset, needs update
+                // otherwise update will be done by asset callback
+                updateEnvironment(TRANSITION_DEFAULT, true);
+            }
+        });
+        // bail early, everything have to be done at callback
+        return true;
+    }
+    else if (env_data.has("day_llsd"))
+    {
+        S32 length = env_data["day_length"].asInteger();
+        S32 offset = env_data["day_offset"].asInteger();
+        LLSettingsDay::ptr_t day = std::make_shared<LLSettingsVODay>(env_data["day_llsd"]);
+        setEnvironment(ENV_LOCAL, day, LLSettingsDay::Seconds(length), LLSettingsDay::Seconds(offset));
+        valid = true;
+    }
+
+    loadSkyWaterFromSettings(env_data, valid, has_assets);
+
+    if (valid && !has_assets)
+    {
+        // Settings were loaded from file without having an asset, needs update
+        // otherwise update will be done by asset callback
+        updateEnvironment(TRANSITION_DEFAULT, true);
+    }
+    return valid;
+}
+
 void LLEnvironment::saveBeaconsState()
 {
     if (mEditorCounter == 0)
diff --git a/indra/newview/llenvironment.h b/indra/newview/llenvironment.h
index 3ae1d37a8c757cd6d6cb6061c54fa3ac86d5fe7f..91c4b851352d9928c5a1d9e899f137e8307af967 100644
--- a/indra/newview/llenvironment.h
+++ b/indra/newview/llenvironment.h
@@ -169,6 +169,8 @@ class LLEnvironment : public LLSingleton<LLEnvironment>
     bool                        getIsSunUp() const;
     bool                        getIsMoonUp() const;
 
+    void                        saveToSettings();
+    bool                        loadFromSettings();
     void                        saveBeaconsState();
     void                        revertBeaconsState();
 
@@ -232,13 +234,6 @@ class LLEnvironment : public LLSingleton<LLEnvironment>
     class DayInstance: public std::enable_shared_from_this<DayInstance>
     {
     public:
-        enum InstanceType_t
-        {
-            TYPE_INVALID,
-            TYPE_FIXED,
-            TYPE_CYCLED
-        };
-
         typedef std::shared_ptr<DayInstance> ptr_t;
 
         static const U32                NO_ANIMATE_SKY;
@@ -282,6 +277,7 @@ class LLEnvironment : public LLSingleton<LLEnvironment>
 
         void                            setFlags(U32 flag) { mAnimateFlags |= flag; }
         void                            clearFlags(U32 flag) { mAnimateFlags &= ~flag; }
+        U32                             getFlags() { return mAnimateFlags; }
 
     protected:
 
@@ -291,7 +287,6 @@ class LLEnvironment : public LLSingleton<LLEnvironment>
         LLSettingsWater::ptr_t      mWater;
         S32                         mSkyTrack;
 
-        InstanceType_t              mType;
         bool                        mInitialized;
 
         LLSettingsDay::Seconds      mDayLength;
@@ -449,6 +444,7 @@ class LLEnvironment : public LLSingleton<LLEnvironment>
     void                        onSetExperienceEnvAssetLoaded(LLUUID experience_id, LLSettingsBase::ptr_t setting, F32 transition_time, S32 status);
 
     void                        listenExperiencePump(const LLSD &message);
+    void                        loadSkyWaterFromSettings(const LLSD &env_data, bool &valid, bool &assets_present); // for use in loadFromSettings()
 
 };
 
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index 7b0ea756e3e26f633385f6949f002db3617dc103..f6efd7b0d83945e6c1dd5dd18b0b855b4dab6a36 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -1439,9 +1439,9 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 				static const GLfloat SHININESS_TO_ALPHA[4] =
 				{
 					0.0000f,
-					0.3333f,
-					0.6666f,
-					1.0000f
+					0.25f,
+					0.5f,
+					0.75f
 				};
 			
 				llassert(tep->getShiny() <= 3);
diff --git a/indra/newview/llfloatereditextdaycycle.cpp b/indra/newview/llfloatereditextdaycycle.cpp
index f57a54163dbfcca09a1026f45171e33956e6d6e4..ea22043de88a567dccdc38c440a595f7b041eff2 100644
--- a/indra/newview/llfloatereditextdaycycle.cpp
+++ b/indra/newview/llfloatereditextdaycycle.cpp
@@ -1715,6 +1715,7 @@ void LLFloaterEditExtDayCycle::doApplyEnvironment(const std::string &where, cons
 
     if (where == ACTION_APPLY_LOCAL)
     {
+        day->setName("Local"); // To distinguish and make sure there is a name. Safe, because this is a copy.
         LLEnvironment::instance().setEnvironment(LLEnvironment::ENV_LOCAL, day);
     }
     else if (where == ACTION_APPLY_PARCEL)
diff --git a/indra/newview/llfloaterfixedenvironment.cpp b/indra/newview/llfloaterfixedenvironment.cpp
index 41d9a6d99b48dc4474b6d788292cff13bd0575bf..37e162b2493c60ddad7eb646ab1d70fceda33fed 100644
--- a/indra/newview/llfloaterfixedenvironment.cpp
+++ b/indra/newview/llfloaterfixedenvironment.cpp
@@ -580,6 +580,7 @@ void LLFloaterFixedEnvironment::doApplyEnvironment(const std::string &where, con
 
     if (where == ACTION_APPLY_LOCAL)
     {
+        settings->setName("Local"); // To distinguish and make sure there is a name. Safe, because this is a copy.
         LLEnvironment::instance().setEnvironment(LLEnvironment::ENV_LOCAL, settings);
     }
     else if (where == ACTION_APPLY_PARCEL)
diff --git a/indra/newview/llpanelvolume.cpp b/indra/newview/llpanelvolume.cpp
index 2b531b6acc1a614f82aebf1fdcb2a4220c8cd42a..05d9346f89a13d03011ca4325d9407439d7dec4c 100644
--- a/indra/newview/llpanelvolume.cpp
+++ b/indra/newview/llpanelvolume.cpp
@@ -300,7 +300,7 @@ void LLPanelVolume::getState( )
 		{
 			LightColorSwatch->setEnabled( TRUE );
 			LightColorSwatch->setValid( TRUE );
-			LightColorSwatch->set(volobjp->getLightBaseColor());
+			LightColorSwatch->set(volobjp->getLightSRGBBaseColor());
 		}
 
 		LLTextureCtrl* LightTextureCtrl = getChild<LLTextureCtrl>("light texture control");
@@ -328,7 +328,7 @@ void LLPanelVolume::getState( )
 		getChild<LLUICtrl>("Light Focus")->setValue(params.mV[1]);
 		getChild<LLUICtrl>("Light Ambiance")->setValue(params.mV[2]);
 
-		mLightSavedColor = volobjp->getLightColor();
+		mLightSavedColor = volobjp->getLightSRGBBaseColor();
 	}
 	else
 	{
@@ -807,7 +807,7 @@ void LLPanelVolume::onLightSelectColor(const LLSD& data)
 	{
 		LLColor4	clr = LightColorSwatch->get();
 		LLColor3	clr3( clr );
-		volobjp->setLightColor(clr3);
+		volobjp->setLightSRGBColor(clr3);
 		mLightSavedColor = clr;
 	}
 }
@@ -881,7 +881,7 @@ void LLPanelVolume::onCommitLight( LLUICtrl* ctrl, void* userdata )
 	if(LightColorSwatch)
 	{
 		LLColor4	clr = LightColorSwatch->get();
-		volobjp->setLightColor(LLColor3(clr));
+		volobjp->setLightSRGBColor(LLColor3(clr));
 	}
 
 	LLTextureCtrl*	LightTextureCtrl = self->getChild<LLTextureCtrl>("light texture control");
diff --git a/indra/newview/llsettingsvo.cpp b/indra/newview/llsettingsvo.cpp
index d96f276a71e7cb5a55b6211d73a84b48b77f59ec..c72a0706cdceb47a71aab25492144fd0f23b8b50 100644
--- a/indra/newview/llsettingsvo.cpp
+++ b/indra/newview/llsettingsvo.cpp
@@ -514,7 +514,7 @@ LLSettingsSky::ptr_t LLSettingsVOSky::buildDefaultSky()
     {
         default_settings = LLSettingsSky::defaults();
 
-        default_settings[SETTING_NAME] = std::string("_default_");
+        default_settings[SETTING_NAME] = DEFAULT_SETTINGS_NAME;
 
         LLSettingsSky::validation_list_t validations = LLSettingsSky::validationList();
         LLSD results = LLSettingsBase::settingValidation(default_settings, validations);
@@ -841,7 +841,7 @@ LLSettingsWater::ptr_t LLSettingsVOWater::buildDefaultWater()
     {
         default_settings = LLSettingsWater::defaults();
 
-        default_settings[SETTING_NAME] = std::string("_default_");
+        default_settings[SETTING_NAME] = DEFAULT_SETTINGS_NAME;
 
         LLSettingsWater::validation_list_t validations = LLSettingsWater::validationList();
         LLSD results = LLSettingsWater::settingValidation(default_settings, validations);
@@ -1169,7 +1169,7 @@ LLSettingsDay::ptr_t LLSettingsVODay::buildDefaultDayCycle()
     if (!default_settings.size())
     {
         default_settings = LLSettingsDay::defaults();
-        default_settings[SETTING_NAME] = std::string("_default_");
+        default_settings[SETTING_NAME] = DEFAULT_SETTINGS_NAME;
 
         LLSettingsDay::validation_list_t validations = LLSettingsDay::validationList();
         LLSD results = LLSettingsDay::settingValidation(default_settings, validations);
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index b6c9a103fca92952a20e171b66f3f3a20e8e9793..f63375ceafdb5c0b0d21be74f419aaaccb4a8351 100644
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -1911,7 +1911,11 @@ bool idle_startup()
 		}
 
 		display_startup();
-        
+
+        // Load stored local environment if needed. Only should be done once at least
+        // initial region data got loaded to avoid race condition with region's environment
+        LLEnvironment::instance().loadFromSettings();
+
         // *TODO : Uncomment that line once the whole grid migrated to SLM and suppress it from LLAgent::handleTeleportFinished() (llagent.cpp)
         //check_merchant_status();
 
diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp
index c8ddc963013863ffd8bc6fa9af749edad858fc65..f108d9632073678d218eb13389e1b252cb4e3732 100644
--- a/indra/newview/llviewershadermgr.cpp
+++ b/indra/newview/llviewershadermgr.cpp
@@ -2146,8 +2146,10 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
 	{
 		gDeferredFullbrightShinyProgram.mName = "Deferred FullbrightShiny Shader";
 		gDeferredFullbrightShinyProgram.mFeatures.calculatesAtmospherics = true;
+		gDeferredFullbrightShinyProgram.mFeatures.hasAtmospherics = true;
 		gDeferredFullbrightShinyProgram.mFeatures.hasGamma = true;
 		gDeferredFullbrightShinyProgram.mFeatures.hasTransport = true;
+		gDeferredFullbrightShinyProgram.mFeatures.hasSrgb = true;
 		gDeferredFullbrightShinyProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels-1;
 		gDeferredFullbrightShinyProgram.mShaderFiles.clear();
 		gDeferredFullbrightShinyProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightShinyV.glsl", GL_VERTEX_SHADER_ARB));
@@ -2161,6 +2163,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
 	{
 		gDeferredSkinnedFullbrightProgram.mName = "Skinned Fullbright Shader";
 		gDeferredSkinnedFullbrightProgram.mFeatures.calculatesAtmospherics = true;
+		gDeferredSkinnedFullbrightProgram.mFeatures.hasAtmospherics = true;
 		gDeferredSkinnedFullbrightProgram.mFeatures.hasGamma = true;
 		gDeferredSkinnedFullbrightProgram.mFeatures.hasTransport = true;
 		gDeferredSkinnedFullbrightProgram.mFeatures.hasObjectSkinning = true;
@@ -2178,10 +2181,12 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
 	{
 		gDeferredSkinnedFullbrightShinyProgram.mName = "Skinned Fullbright Shiny Shader";
 		gDeferredSkinnedFullbrightShinyProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredSkinnedFullbrightShinyProgram.mFeatures.hasAtmospherics = true;
 		gDeferredSkinnedFullbrightShinyProgram.mFeatures.hasGamma = true;
 		gDeferredSkinnedFullbrightShinyProgram.mFeatures.hasTransport = true;
 		gDeferredSkinnedFullbrightShinyProgram.mFeatures.hasObjectSkinning = true;
 		gDeferredSkinnedFullbrightShinyProgram.mFeatures.disableTextureIndex = true;
+        gDeferredSkinnedFullbrightShinyProgram.mFeatures.hasSrgb = true;
 		gDeferredSkinnedFullbrightShinyProgram.mShaderFiles.clear();
 		gDeferredSkinnedFullbrightShinyProgram.mShaderFiles.push_back(make_pair("objects/fullbrightShinySkinnedV.glsl", GL_VERTEX_SHADER_ARB));
 		gDeferredSkinnedFullbrightShinyProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightShinyF.glsl", GL_FRAGMENT_SHADER_ARB));
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index e0609aeeb14b228832c86b9814b1a0b76b815b5c..37d01bd7b0414215c90ba452e7b399fe4f493448 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -3875,7 +3875,7 @@ void LLViewerWindow::renderSelections( BOOL for_gl_pick, BOOL pick_parcel_walls,
 						F32 scale = vovolume->getLightRadius();
 						gGL.scalef(scale, scale, scale);
 
-						LLColor4 color(vovolume->getLightColor(), .5f);
+						LLColor4 color(vovolume->getLightSRGBColor(), .5f);
 						gGL.color4fv(color.mV);
 					
 						//F32 pixel_area = 100000.f;
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 6e7f33d758a64d22640859d2caf88be5628e381e..9ba62cebea53a0215098faec0c9629d350cc0920 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -3151,14 +3151,19 @@ void LLVOVolume::setIsLight(BOOL is_light)
 	}
 }
 
-void LLVOVolume::setLightColor(const LLColor3& color)
+void LLVOVolume::setLightSRGBColor(const LLColor3& color)
+{
+    setLightLinearColor(linearColor3(color));
+}
+
+void LLVOVolume::setLightLinearColor(const LLColor3& color)
 {
 	LLLightParams *param_block = (LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT);
 	if (param_block)
 	{
-		if (param_block->getColor() != color)
+		if (param_block->getLinearColor() != color)
 		{
-			param_block->setColor(LLColor4(color, param_block->getColor().mV[3]));
+			param_block->setLinearColor(LLColor4(color, param_block->getLinearColor().mV[3]));
 			parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
 			gPipeline.markTextured(mDrawable);
 			mFaceMappingChanged = TRUE;
@@ -3171,9 +3176,9 @@ void LLVOVolume::setLightIntensity(F32 intensity)
 	LLLightParams *param_block = (LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT);
 	if (param_block)
 	{
-		if (param_block->getColor().mV[3] != intensity)
+		if (param_block->getLinearColor().mV[3] != intensity)
 		{
-			param_block->setColor(LLColor4(LLColor3(param_block->getColor()), intensity));
+			param_block->setLinearColor(LLColor4(LLColor3(param_block->getLinearColor()), intensity));
 			parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
 		}
 	}
@@ -3225,25 +3230,17 @@ BOOL LLVOVolume::getIsLight() const
 	return getParameterEntryInUse(LLNetworkData::PARAMS_LIGHT);
 }
 
-LLColor3 LLVOVolume::getLightBaseColor() const
+LLColor3 LLVOVolume::getLightSRGBBaseColor() const
 {
-	const LLLightParams *param_block = (const LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT);
-	if (param_block)
-	{
-		return LLColor3(param_block->getColor());
-	}
-	else
-	{
-		return LLColor3(1,1,1);
-	}
+    return srgbColor3(getLightLinearBaseColor());
 }
 
-LLColor3 LLVOVolume::getLightColor() const
+LLColor3 LLVOVolume::getLightLinearBaseColor() const
 {
 	const LLLightParams *param_block = (const LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT);
 	if (param_block)
 	{
-		return LLColor3(param_block->getColor()) * param_block->getColor().mV[3];
+		return LLColor3(param_block->getLinearColor());
 	}
 	else
 	{
@@ -3251,12 +3248,12 @@ LLColor3 LLVOVolume::getLightColor() const
 	}
 }
 
-LLColor3 LLVOVolume::getLightSRGBColor() const
+LLColor3 LLVOVolume::getLightLinearColor() const
 {
     const LLLightParams *param_block = (const LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT);
     if (param_block)
     {
-        return LLColor3(param_block->getSRGBColor()) * param_block->getSRGBColor().mV[3];
+        return LLColor3(param_block->getLinearColor()) * param_block->getLinearColor().mV[3];
     }
     else
     {
@@ -3264,6 +3261,13 @@ LLColor3 LLVOVolume::getLightSRGBColor() const
     }
 }
 
+LLColor3 LLVOVolume::getLightSRGBColor() const
+{
+    LLColor3 ret = getLightLinearColor();
+    ret = srgbColor3(ret);
+    return ret;
+}
+
 LLUUID LLVOVolume::getLightTextureID() const
 {
 	if (getParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE))
@@ -3355,7 +3359,7 @@ F32 LLVOVolume::getLightIntensity() const
 	const LLLightParams *param_block = (const LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT);
 	if (param_block)
 	{
-		return param_block->getColor().mV[3];
+		return param_block->getLinearColor().mV[3];
 	}
 	else
 	{
@@ -3376,12 +3380,12 @@ F32 LLVOVolume::getLightRadius() const
 	}
 }
 
-F32 LLVOVolume::getLightFalloff() const
+F32 LLVOVolume::getLightFalloff(const F32 fudge_factor) const
 {
 	const LLLightParams *param_block = (const LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT);
 	if (param_block)
 	{
-		return param_block->getFalloff() * 0.5f;
+		return param_block->getFalloff() * fudge_factor;
 	}
 	else
 	{
diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h
index dd5c0dfeefb8084f735cc8d5ed4a970157891be1..a2c8101be7c2694392764d38e6f4bfb8cc2e1f39 100644
--- a/indra/newview/llvovolume.h
+++ b/indra/newview/llvovolume.h
@@ -245,7 +245,11 @@ class LLVOVolume : public LLViewerObject
 
 	// For Lights
 	void setIsLight(BOOL is_light);
-	void setLightColor(const LLColor3& color);
+    //set the gamma-corrected (sRGB) color of this light
+	void setLightSRGBColor(const LLColor3& color);
+    //set the linear color of this light
+    void setLightLinearColor(const LLColor3& color);
+
 	void setLightIntensity(F32 intensity);
 	void setLightRadius(F32 radius);
 	void setLightFalloff(F32 falloff);
@@ -254,9 +258,21 @@ class LLVOVolume : public LLViewerObject
 	void setSpotLightParams(LLVector3 params);
 
 	BOOL getIsLight() const;
-	LLColor3 getLightBaseColor() const; // not scaled by intensity
-	LLColor3 getLightColor() const; // scaled by intensity
-    LLColor3 getLightSRGBColor() const; // Used to get the (cached) light color in sRGB color space.  Also scaled by intensity.
+
+
+    // Get the light color in sRGB color space NOT scaled by intensity.
+	LLColor3 getLightSRGBBaseColor() const; 
+
+    // Get the light color in linear color space NOT scaled by intensity.
+    LLColor3 getLightLinearBaseColor() const;
+    
+    // Get the light color in linear color space scaled by intensity 
+    //  this is the value that should be fed into shaders
+    LLColor3 getLightLinearColor() const;
+
+    // Get the light color in sRGB color space scaled by intensity.
+    LLColor3 getLightSRGBColor() const; 
+
 	LLUUID	getLightTextureID() const;
 	bool isLightSpotlight() const;
 	LLVector3 getSpotLightParams() const;
@@ -266,7 +282,7 @@ class LLVOVolume : public LLViewerObject
 	LLViewerTexture* getLightTexture();
 	F32 getLightIntensity() const;
 	F32 getLightRadius() const;
-	F32 getLightFalloff() const;
+	F32 getLightFalloff(const F32 fudge_factor = 1.f) const;
 	F32 getLightCutoff() const;
 	
 	// Flexible Objects
diff --git a/indra/newview/llvowlsky.cpp b/indra/newview/llvowlsky.cpp
index 620367228f3295886318115b626b6eae88060ec9..368a3f23351822c03944e403660f887091bd756f 100644
--- a/indra/newview/llvowlsky.cpp
+++ b/indra/newview/llvowlsky.cpp
@@ -301,6 +301,8 @@ void LLVOWLSky::drawDome(void)
 		updateGeometry(mDrawable);
 	}
 
+	LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
+
 	const U32 data_mask = LLDrawPoolWLSky::SKY_VERTEX_DATA_MASK;
 	
 	std::vector< LLPointer<LLVertexBuffer> >::const_iterator strips_vbo_iter, end_strips;
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 42ff12bb19a64ce0923f45e0559abe09dca5b5a5..051634efc8147e72b2b2a1e59a74b69e490d751e 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -218,6 +218,7 @@ LLTrace::EventStatHandle<S64> LLPipeline::sStatBatchSize("renderbatchsize");
 
 const F32 BACKLIGHT_DAY_MAGNITUDE_OBJECT = 0.1f;
 const F32 BACKLIGHT_NIGHT_MAGNITUDE_OBJECT = 0.08f;
+const F32 DEFERRED_LIGHT_FALLOFF = 0.5f;
 const U32 DEFERRED_VB_MASK = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_TEXCOORD1;
 
 extern S32 gBoxFrame;
@@ -6368,7 +6369,8 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
 				mLightMovingMask |= (1<<cur_light);
 			}
 			
-			LLColor4  light_color = sRenderDeferred ? light->getLightSRGBColor() : light->getLightColor();
+            //send linear light color to shader
+			LLColor4  light_color = light->getLightLinearColor();
 			light_color.mV[3] = 0.0f;
 
 			F32 fade = iter->fade;
@@ -6408,9 +6410,6 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
 			F32 x = (3.f * (1.f + (light->getLightFalloff() * 2.0f))); // why this magic?  probably trying to match a historic behavior.
 			F32 linatten = x / (light_radius); // % of brightness at radius
 
-            // get falloff to match for forward deferred rendering lights
-            F32 falloff = light->getLightFalloff() + (sRenderDeferred ? 1.0 : 0.f);
-
 			mHWLightColors[cur_light] = light_color;
 			LLLightState* light_state = gGL.getLight(cur_light);
 			
@@ -6421,7 +6420,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
 			if (sRenderDeferred)
 			{
 				light_state->setLinearAttenuation(size);
-				light_state->setQuadraticAttenuation(falloff);
+				light_state->setQuadraticAttenuation(light->getLightFalloff(DEFERRED_LIGHT_FALLOFF) + 1.f); // get falloff to match for forward deferred rendering lights
 			}
 			else
 			{
@@ -8810,7 +8809,8 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
 					const F32* c = center.getF32ptr();
 					F32 s = volume->getLightRadius()*1.5f;
 
-                    LLColor3 col = volume->getLightSRGBColor();
+                    //send light color to shader in linear space
+                    LLColor3 col = volume->getLightLinearColor();
 					
 					if (col.magVecSquared() < 0.001f)
 					{
@@ -8851,7 +8851,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
 							gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
 							gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
 							gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
-                            gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff());
+                            gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF));
 							gGL.syncMatrices();
 							
 							mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center));
@@ -8871,7 +8871,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
 						mat.mult_matrix_vec(tc);
 					
 						fullscreen_lights.push_back(LLVector4(tc.v[0], tc.v[1], tc.v[2], s));
-                        light_colors.push_back(LLVector4(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff()));
+                        light_colors.push_back(LLVector4(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF)));
 					}
 				}
 				unbindDeferredShader(gDeferredLightProgram);
@@ -8902,12 +8902,13 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
 
 					setupSpotLight(gDeferredSpotLightProgram, drawablep);
 					
-                    LLColor3 col = volume->getLightSRGBColor();
+                    //send light color to shader in linear space
+                    LLColor3 col = volume->getLightLinearColor();
 					
 					gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
 					gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
 					gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
-                    gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff());
+                    gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF));
 					gGL.syncMatrices();
 										
 					mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center));
@@ -8982,7 +8983,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
 					LLVector3 center = drawablep->getPositionAgent();
 					F32* c = center.mV;
                     F32 light_size_final = volume->getLightRadius()*1.5f;
-                    F32 light_falloff_final = volume->getLightFalloff();
+                    F32 light_falloff_final = volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF);
 
 					sVisibleLightCount++;
 
@@ -8991,8 +8992,8 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
 					
 					setupSpotLight(gDeferredMultiSpotLightProgram, drawablep);
 
-                    LLColor3 col = volume->getLightSRGBColor();
-					
+                    //send light color to shader in linear space
+                    LLColor3 col = volume->getLightLinearColor();
 					
 					gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v);
                     gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, light_size_final);