From 55c36ab7dbee9463c3df72d60cdc882cdeb69b9d Mon Sep 17 00:00:00 2001
From: Arun Bapu <arun@lindenlab.com>
Date: Wed, 14 Aug 2013 11:35:06 -0700
Subject: [PATCH] Fix for NORSPEC 271 - Transparent prims in Materials Viewer
 are incorrectly affecting depth of field by modifying the depth buffer

---
 indra/newview/lldrawpoolalpha.cpp | 27 ++++++++++++++++++++++-----
 indra/newview/lldrawpoolalpha.h   |  2 +-
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp
index ba83c955180..9c510d360f3 100755
--- a/indra/newview/lldrawpoolalpha.cpp
+++ b/indra/newview/lldrawpoolalpha.cpp
@@ -100,7 +100,7 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass)
 		}
 		else
 		{
-			simple_shader = &gDeferredAlphaProgram;
+		simple_shader = &gDeferredAlphaProgram;
 			fullbright_shader = &gDeferredFullbrightProgram;
 		}
 		
@@ -276,11 +276,11 @@ void LLDrawPoolAlpha::render(S32 pass)
 
 	if (mVertexShaderLevel > 0)
 	{
-		renderAlpha(getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2);
+		renderAlpha(getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2, pass);
 	}
 	else
 	{
-		renderAlpha(getVertexDataMask());
+		renderAlpha(getVertexDataMask(), pass);
 	}
 
 	gGL.setColorMask(true, false);
@@ -352,7 +352,7 @@ void LLDrawPoolAlpha::renderAlphaHighlight(U32 mask)
 	}
 }
 
-void LLDrawPoolAlpha::renderAlpha(U32 mask)
+void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass)
 {
 	BOOL initialized_lighting = FALSE;
 	BOOL light_enabled = TRUE;
@@ -385,6 +385,23 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask)
 					continue;
 				}
 
+				// Fix for bug - NORSPEC-271
+				// If the face is more than 90% transparent, then don't update the Depth buffer for Dof
+				// We don't want the nearly invisible objects to cause of DoF effects
+				if(pass == 1)
+				{
+					LLFace*	face = params.mFace;
+					if(face)
+					{
+						const LLTextureEntry* tep = face->getTextureEntry();
+						if(tep)
+						{
+							if(tep->getColor().mV[3] < 0.1f)
+								continue;
+						}
+					}
+				}
+
 				LLRenderPass::applyModelMatrix(params);
 				
 				LLMaterial* mat = NULL;
@@ -548,7 +565,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask)
 				gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode);
 				
 				// If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow).  Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha.
-				if (current_shader &&
+				if (current_shader && 
                     !LLPipeline::sImpostorRender &&
 					draw_glow_for_this_partition &&
 					params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE))
diff --git a/indra/newview/lldrawpoolalpha.h b/indra/newview/lldrawpoolalpha.h
index 43122218eda..d064a3a324b 100755
--- a/indra/newview/lldrawpoolalpha.h
+++ b/indra/newview/lldrawpoolalpha.h
@@ -63,7 +63,7 @@ class LLDrawPoolAlpha: public LLRenderPass
 	/*virtual*/ void prerender();
 
 	void renderGroupAlpha(LLSpatialGroup* group, U32 type, U32 mask, BOOL texture = TRUE);
-	void renderAlpha(U32 mask);
+	void renderAlpha(U32 mask, S32 pass);
 	void renderAlphaHighlight(U32 mask);
 		
 	static BOOL sShowDebugAlpha;
-- 
GitLab