diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 8372c2430b3e4efcbd9f20b2f4871f2476acf924..bd801ae4c2d218f0e5b211038c91270a2ad90cd9 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -2147,9 +2147,18 @@ void LLPipeline::doOcclusion(LLCamera& camera)
 
 		LLGLDisable cull(GL_CULL_FACE);
 
-		if (canUseVertexShaders())
+		
+		bool bind_shader = LLGLSLShader::sNoFixedFunction && LLGLSLShader::sCurBoundShader == 0;
+		if (bind_shader)
 		{
-			gOcclusionProgram.bind();
+			if (LLPipeline::sShadowRender)
+			{
+				gDeferredShadowProgram.bind();
+			}
+			else
+			{
+				gOcclusionProgram.bind();
+			}
 		}
 
 		for (LLCullResult::sg_list_t::iterator iter = sCull->beginOcclusionGroups(); iter != sCull->endOcclusionGroups(); ++iter)
@@ -2159,9 +2168,16 @@ void LLPipeline::doOcclusion(LLCamera& camera)
 			group->clearOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION);
 		}
 	
-		if (canUseVertexShaders())
+		if (bind_shader)
 		{
-			gOcclusionProgram.unbind();
+			if (LLPipeline::sShadowRender)
+			{
+				gDeferredShadowProgram.unbind();
+			}
+			else
+			{
+				gOcclusionProgram.unbind();
+			}
 		}
 
 		gGL.setColorMask(true, false);