diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
index 8b2d0a09ab1dddf43444948a75796d248a185988..9afa7e36f8ed77148b892d7b1c2f239de47c1d53 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
@@ -276,8 +276,6 @@ vec3 post_atmo = color.rgb;
 #if !defined(LOCAL_LIGHT_KILL)
     color.rgb += light.rgb;
 #endif
-    // back to sRGB as we're going directly to the final RT post-deferred gamma correction
-    color.rgb = linear_to_srgb(color.rgb);
 
 //color.rgb = amblit;
 //color.rgb = vec3(ambient);
@@ -291,7 +289,9 @@ vec3 post_atmo = color.rgb;
 //color.rgb = post_atmo;
 
 #ifdef WATER_FOG
+    color.rgb = linear_to_srgb(color.rgb);
     color = applyWaterFogView(pos.xyz, color);
+    color.rgb = srgb_to_linear(color.rgb);
 #endif // WATER_FOG
 
 #endif
diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl
index f0522850de8c234e2b17b64a1051720b9fcc054b..7d03392b81ce62783591779f81eb13bb66e0d62f 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl
@@ -39,15 +39,15 @@ vec3 fullbrightScaleSoftClip(vec3 light);
 VARYING vec4 vertex_color;
 VARYING vec2 vary_texcoord0;
 
+vec3 srgb_to_linear(vec3 cs);
+
 void main() 
 {
-	float shadow = 1.0;
-
 	vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color;
 	color.rgb = fullbrightAtmosTransport(color.rgb);
 
 	color.rgb = fullbrightScaleSoftClip(color.rgb);
 
-	frag_color = color;
+	frag_color = vec4(srgb_to_linear(color.rgb), color.a);
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
index 4eedd966c0fa64d3d8cfd0b83ec92ddd75d7686b..5a6e32ff87b0157e593100086c3ca4630508c032 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
@@ -85,6 +85,8 @@ void main()
     color.a   = final_alpha;
 #endif
 
+	color.rgb = srgb_to_linear(color.rgb);
+
 	frag_color.rgb = color.rgb;
 	frag_color.a   = color.a;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl
index 9e491186f3bf876162e0c9dcdce56e7c4cc49cf8..8441e300974acb36573d8a05372ce2f2402e1e6e 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl
@@ -99,7 +99,7 @@ void main()
 
 	color.a = 1.0;
 
-	//color.rgb = linear_to_srgb(color.rgb);
+	color.rgb = srgb_to_linear(color.rgb);
 
 	frag_color = color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
index 15864fc98e1929e7dd43ce40128495d27f2ab03b..d714d6d541e06e886637ca58c27a9a5f2769f45b 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
@@ -422,13 +422,13 @@ void main()
     glare = min(glare, 1.0);
     float al = max(diffcol.a, glare)*vertex_color.a;
 
+#ifdef WATER_FOG
     //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;
+    color = srgb_to_linear(color);
 #endif
 
     frag_color = vec4(color, al);
diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp
index f9f9fe7bb0130dcf5cac6eb40227a3d660046b4c..f2ecd15642e60134cbb6031184f162f4e3355dad 100644
--- a/indra/newview/llviewershadermgr.cpp
+++ b/indra/newview/llviewershadermgr.cpp
@@ -2284,6 +2284,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
 		gDeferredEmissiveProgram.mFeatures.calculatesAtmospherics = true;
 		gDeferredEmissiveProgram.mFeatures.hasGamma = true;
 		gDeferredEmissiveProgram.mFeatures.hasTransport = true;
+        gDeferredEmissiveProgram.mFeatures.hasSrgb = true;
 		gDeferredEmissiveProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
 		gDeferredEmissiveProgram.mShaderFiles.clear();
 		gDeferredEmissiveProgram.mShaderFiles.push_back(make_pair("deferred/emissiveV.glsl", GL_VERTEX_SHADER));
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 8bb4fe202ab32c1ba2c4ed2398466308b0cac992..cfd550eef5d09bd7a7097af2bd623ad0502910f1 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -9319,6 +9319,43 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget *screen_target)
 
     screen_target->flush();
 
+	screen_target->bindTarget();
+
+    {  // render non-deferred geometry (alpha, fullbright, glow)
+        LLGLDisable blend(GL_BLEND);
+        LLGLDisable stencil(GL_STENCIL_TEST);
+
+        pushRenderTypeMask();
+        andRenderTypeMask(LLPipeline::RENDER_TYPE_ALPHA,
+                          LLPipeline::RENDER_TYPE_FULLBRIGHT,
+                          LLPipeline::RENDER_TYPE_VOLUME,
+                          LLPipeline::RENDER_TYPE_GLOW,
+                          LLPipeline::RENDER_TYPE_BUMP,
+                          LLPipeline::RENDER_TYPE_PASS_SIMPLE,
+                          LLPipeline::RENDER_TYPE_PASS_ALPHA,
+                          LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK,
+                          LLPipeline::RENDER_TYPE_PASS_BUMP,
+                          LLPipeline::RENDER_TYPE_PASS_POST_BUMP,
+                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT,
+                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK,
+                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY,
+                          LLPipeline::RENDER_TYPE_PASS_GLOW,
+                          LLPipeline::RENDER_TYPE_PASS_GRASS,
+                          LLPipeline::RENDER_TYPE_PASS_SHINY,
+                          LLPipeline::RENDER_TYPE_PASS_INVISIBLE,
+                          LLPipeline::RENDER_TYPE_PASS_INVISI_SHINY,
+                          LLPipeline::RENDER_TYPE_AVATAR,
+                          LLPipeline::RENDER_TYPE_CONTROL_AV,
+                          LLPipeline::RENDER_TYPE_ALPHA_MASK,
+                          LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK,
+                          END_RENDER_TYPES);
+
+        renderGeomPostDeferred(camera);
+        popRenderTypeMask();
+    }
+
+	 screen_target->flush();
+
     // gamma correct lighting
     gGL.matrixMode(LLRender::MM_PROJECTION);
     gGL.pushMatrix();
@@ -9336,9 +9373,8 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget *screen_target)
         screen_target->bindTarget();
         // Apply gamma correction to the frame here.
         gDeferredPostGammaCorrectProgram.bind();
-        // mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
-        S32 channel = 0;
-        channel     = gDeferredPostGammaCorrectProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, screen_target->getUsage());
+
+		S32 channel = gDeferredPostGammaCorrectProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, screen_target->getUsage());
         if (channel > -1)
         {
             screen_target->bindTexture(0, channel, LLTexUnit::TFO_POINT);
@@ -9371,39 +9407,6 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget *screen_target)
 
     screen_target->bindTarget();
 
-    {  // render non-deferred geometry (alpha, fullbright, glow)
-        LLGLDisable blend(GL_BLEND);
-        LLGLDisable stencil(GL_STENCIL_TEST);
-
-        pushRenderTypeMask();
-        andRenderTypeMask(LLPipeline::RENDER_TYPE_ALPHA,
-                          LLPipeline::RENDER_TYPE_FULLBRIGHT,
-                          LLPipeline::RENDER_TYPE_VOLUME,
-                          LLPipeline::RENDER_TYPE_GLOW,
-                          LLPipeline::RENDER_TYPE_BUMP,
-                          LLPipeline::RENDER_TYPE_PASS_SIMPLE,
-                          LLPipeline::RENDER_TYPE_PASS_ALPHA,
-                          LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK,
-                          LLPipeline::RENDER_TYPE_PASS_BUMP,
-                          LLPipeline::RENDER_TYPE_PASS_POST_BUMP,
-                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT,
-                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK,
-                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY,
-                          LLPipeline::RENDER_TYPE_PASS_GLOW,
-                          LLPipeline::RENDER_TYPE_PASS_GRASS,
-                          LLPipeline::RENDER_TYPE_PASS_SHINY,
-                          LLPipeline::RENDER_TYPE_PASS_INVISIBLE,
-                          LLPipeline::RENDER_TYPE_PASS_INVISI_SHINY,
-                          LLPipeline::RENDER_TYPE_AVATAR,
-                          LLPipeline::RENDER_TYPE_CONTROL_AV,
-                          LLPipeline::RENDER_TYPE_ALPHA_MASK,
-                          LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK,
-                          END_RENDER_TYPES);
-
-		renderGeomPostDeferred(camera);
-        popRenderTypeMask();
-    }
-
     {
         // render highlights, etc.
         renderHighlights();