diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp
index 5ba2a149b9339b5bc23c492a7ca28c2b7545bc61..7c7b370bbb1eedc203ceeaf8436125bc97d30808 100644
--- a/indra/newview/llspatialpartition.cpp
+++ b/indra/newview/llspatialpartition.cpp
@@ -4642,8 +4642,7 @@ LLDrawInfo::LLDrawInfo(U16 start, U16 end, U32 count, U32 offset,
 	mSpecColor(1.0f, 1.0f, 1.0f, 0.5f),
 	mEnvIntensity(0.0f),
 	mAlphaMaskCutoff(0.5f),
-	mDiffuseAlphaMode(0),
-	mMaterialID(NULL)
+	mDiffuseAlphaMode(0)
 {
 	mVertexBuffer->validateRange(mStart, mEnd, mCount, mOffset);
 	
diff --git a/indra/newview/llspatialpartition.h b/indra/newview/llspatialpartition.h
index a71ca60d85cfa4d42b3cc09026efed292995b2ea..13196de1ef3311e5d8cd58e498567e2861791f5c 100644
--- a/indra/newview/llspatialpartition.h
+++ b/indra/newview/llspatialpartition.h
@@ -120,7 +120,7 @@ class LLDrawInfo : public LLRefCount
 	F32 mDistance;
 	U32 mDrawMode;
 		
-	const LLMaterialID *mMaterialID; // If this is false, the following parameters are unused.
+	LLMaterialID mMaterialID; // If this is null, the following parameters are unused.
 	LLPointer<LLViewerTexture> mSpecularMap;
 	const LLMatrix4* mSpecularMapMatrix;
 	LLPointer<LLViewerTexture> mNormalMap;
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index becbbbc3a46cdd202ca20e8c60f06a1889e06294..750d6bd2ac46d8b7d130cd4c2b32fedcd8ff5328 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -4071,7 +4071,7 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep,
 
 	U8 index = facep->getTextureIndex();
 	
-	const LLMaterialID* matid = &facep->getTextureEntry()->getMaterialID();
+	const LLMaterialID& matid = facep->getTextureEntry()->getMaterialID();
 
 	bool batchable = false;
 
@@ -4141,7 +4141,7 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep,
 			if (facep->getTextureEntry()->getMaterialParams() != NULL)
 			{
 				// We have a material.  Update our draw info accordingly.
-				draw_info->mMaterialID = &facep->getTextureEntry()->getMaterialID();
+				draw_info->mMaterialID = matid;
 				LLVector4 specColor;
 				specColor.mV[0] = facep->getTextureEntry()->getMaterialParams()->getSpecularLightColor().mV[0] * (1.f / 255.f);
 				specColor.mV[1] = facep->getTextureEntry()->getMaterialParams()->getSpecularLightColor().mV[1] * (1.f / 255.f);
@@ -4702,14 +4702,14 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
 		bump_mask |= LLVertexBuffer::MAP_BINORMAL;
 		genDrawInfo(group, simple_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, simple_faces, FALSE, TRUE);
 		genDrawInfo(group, fullbright_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, fullbright_faces, FALSE, TRUE);
-		genDrawInfo(group, bump_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, bump_faces, FALSE, TRUE);
+		genDrawInfo(group, bump_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, bump_faces, FALSE, FALSE);
 		genDrawInfo(group, alpha_mask | LLVertexBuffer::MAP_TEXTURE_INDEX, alpha_faces, TRUE, TRUE);
 	}
 	else
 	{
 		genDrawInfo(group, simple_mask, simple_faces);
 		genDrawInfo(group, fullbright_mask, fullbright_faces);
-		genDrawInfo(group, bump_mask, bump_faces, FALSE, TRUE);
+		genDrawInfo(group, bump_mask, bump_faces, FALSE, FALSE);
 		genDrawInfo(group, alpha_mask, alpha_faces, TRUE);
 	}
 	
@@ -4864,11 +4864,14 @@ struct CompareBatchBreakerModified
 		{
 			return lte->getFullbright() < rte->getFullbright();
 		}
-		else
+		else if (lhs->getTexture() != rhs->getTexture())
 		{
 			return lhs->getTexture() < rhs->getTexture();
 		}
-		
+		else
+		{
+			return lte->getMaterialParams() < rte->getMaterialParams();
+		}
 	}
 };
 
@@ -4952,6 +4955,7 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
 		//pull off next face
 		LLFace* facep = *face_iter;
 		LLViewerTexture* tex = facep->getTexture();
+		LLMaterialPtr mat = facep->getTextureEntry()->getMaterialParams();
 
 		if (distance_sort)
 		{
@@ -5053,7 +5057,10 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std::
 			else
 			{
 				while (i != faces.end() && 
-					(LLPipeline::sTextureBindTest || (distance_sort || (*i)->getTexture() == tex)))
+					(LLPipeline::sTextureBindTest || 
+						(distance_sort || 
+							((*i)->getTexture() == tex &&
+							((*i)->getTextureEntry()->getMaterialParams() == mat)))))
 				{
 					facep = *i;