diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp
index b74a3fde62bd426dcf5cfe7e3e9588865493116e..2417ceb68dec13dc4c7330a01e09dd24cdd9a84e 100644
--- a/indra/llrender/llrender.cpp
+++ b/indra/llrender/llrender.cpp
@@ -41,11 +41,11 @@
 LLRender gGL;
 
 // Handy copies of last good GL matrices
-F32	gGLModelView[16];
-F32	gGLLastModelView[16];
-F32 gGLLastProjection[16];
-F32 gGLProjection[16];
-S32	gGLViewport[4];
+alignas(16) F32	gGLModelView[16];
+alignas(16) F32	gGLLastModelView[16];
+alignas(16) F32 gGLLastProjection[16];
+alignas(16) F32 gGLProjection[16];
+alignas(16) S32	gGLViewport[4];
 
 U32 LLRender::sUICalls = 0;
 U32 LLRender::sUIVerts = 0;
@@ -1352,8 +1352,9 @@ void LLRender::syncMatrices()
             // but certain render paths (deferred lighting) require it to be mismatched *sigh*
             //if (shader->getUniformLocation(LLShaderMgr::INVERSE_PROJECTION_MATRIX))
             //{
-	        //    glh::matrix4f inv_proj = mat.inverse();
-	        //    shader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, inv_proj.m);
+	        //    LLMatrix4a inv_proj = mat
+			//    mat.invert();
+	        //    shader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, inv_proj.getF32ptr());
             //}
 
 			shader->uniformMatrix4fv(name[MM_PROJECTION], 1, GL_FALSE, mat.getF32ptr());
@@ -2445,82 +2446,44 @@ void LLRender::debugTexUnits(void)
 	LL_INFOS("TextureUnit") << "Active TexUnit Enabled : " << active_enabled << LL_ENDL;
 }
 
-
-
-glh::matrix4f copy_matrix(F32* src)
+LLMatrix4a copy_matrix(F32* src)
 {
-	glh::matrix4f ret;
-	ret.set_value(src);
-	return ret;
+	LLMatrix4a outmat;
+	outmat.load4a(src);
+	return outmat;
 }
 
-glh::matrix4f get_current_modelview()
+LLMatrix4a get_current_modelview()
 {
 	return copy_matrix(gGLModelView);
 }
 
-glh::matrix4f get_current_projection()
+LLMatrix4a get_current_projection()
 {
 	return copy_matrix(gGLProjection);
 }
 
-glh::matrix4f get_last_modelview()
+LLMatrix4a get_last_modelview()
 {
 	return copy_matrix(gGLLastModelView);
 }
 
-glh::matrix4f get_last_projection()
+LLMatrix4a get_last_projection()
 {
 	return copy_matrix(gGLLastProjection);
 }
 
-void copy_matrix(const glh::matrix4f& src, F32* dst)
+void copy_matrix(const LLMatrix4a& src, F32* dst)
 {
-	memcpy(dst, src.m, sizeof(F32) * 16);
+	src.store4a(dst);
 }
 
-void set_current_modelview(const glh::matrix4f& mat)
+void set_current_modelview(const LLMatrix4a& mat)
 {
 	copy_matrix(mat, gGLModelView);
 }
 
-void set_current_projection(const glh::matrix4f& mat)
+void set_current_projection(const LLMatrix4a& mat)
 {
 	copy_matrix(mat, gGLProjection);
 }
-
-glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar)
-{
-	glh::matrix4f ret(
-		2.f/(right-left), 0.f, 0.f, -(right+left)/(right-left),
-		0.f, 2.f/(top-bottom), 0.f, -(top+bottom)/(top-bottom),
-		0.f, 0.f, -2.f/(zfar-znear),  -(zfar+znear)/(zfar-znear),
-		0.f, 0.f, 0.f, 1.f);
-
-	return ret;
-}
-
-glh::matrix4f gl_perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar)
-{
-	GLfloat f = 1.f/tanf(DEG_TO_RAD*fovy/2.f);
-
-	return glh::matrix4f(f/aspect, 0, 0, 0,
-						 0, f, 0, 0,
-						 0, 0, (zFar+zNear)/(zNear-zFar), (2.f*zFar*zNear)/(zNear-zFar),
-						 0, 0, -1.f, 0);
-}
-
-glh::matrix4f gl_lookat(LLVector3 eye, LLVector3 center, LLVector3 up)
-{
-	LLVector3 f = center-eye;
-	f.normVec();
-	up.normVec();
-	LLVector3 s = f % up;
-	LLVector3 u = s % f;
-
-	return glh::matrix4f(s[0], s[1], s[2], 0,
-					  u[0], u[1], u[2], 0,
-					  -f[0], -f[1], -f[2], 0,
-					  0, 0, 0, 1);
-	
-}
diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h
index 00b37978ac911c08ab2ce797190c253b6fe2d854..04b222985a6dffa6e248a0b3cd5ee3167ec39e37 100644
--- a/indra/llrender/llrender.h
+++ b/indra/llrender/llrender.h
@@ -532,11 +532,11 @@ class LLRender
 
 };
 
-extern F32 gGLModelView[16];
-extern F32 gGLLastModelView[16];
-extern F32 gGLLastProjection[16];
-extern F32 gGLProjection[16];
-extern S32 gGLViewport[4];
+extern alignas(16) F32 gGLModelView[16];
+extern alignas(16) F32 gGLLastModelView[16];
+extern alignas(16) F32 gGLLastProjection[16];
+extern alignas(16) F32 gGLProjection[16];
+extern alignas(16) S32 gGLViewport[4];
 
 extern LLRender gGL;
 
@@ -555,19 +555,17 @@ inline static LL_ALIGN_16(const LLMatrix4a) OGL_TO_CFR_ROTATION_4A(
 	LLVector4a(0.f, 1.f, 0.f, 0.f),		//  Y becomes Z
 	LLVector4a(0.f, 0.f, 0.f, 1.f));
 
-glh::matrix4f copy_matrix(F32* src);
-glh::matrix4f get_current_modelview();
-glh::matrix4f get_current_projection();
-glh::matrix4f get_last_modelview();
-glh::matrix4f get_last_projection();
+LLMatrix4a copy_matrix(F32* src);
+LLMatrix4a get_current_modelview();
+LLMatrix4a get_current_projection();
+LLMatrix4a get_last_modelview();
+LLMatrix4a get_last_projection();
 
-void copy_matrix(const glh::matrix4f& src, F32* dst);
-void set_current_modelview(const glh::matrix4f& mat);
-void set_current_projection(const glh::matrix4f& mat);
+void copy_matrix(const LLMatrix4a& src, F32* dst);
+void set_current_modelview(const LLMatrix4a& mat);
+void set_current_projection(const LLMatrix4a& mat);
 
-glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar);
 glh::matrix4f gl_perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar);
-glh::matrix4f gl_lookat(LLVector3 eye, LLVector3 center, LLVector3 up);
 
 #if LL_RELEASE_FOR_DOWNLOAD
     #define LL_SHADER_LOADING_WARNS(...) LL_WARNS_ONCE("ShaderLoading")
diff --git a/indra/newview/llpanelprimmediacontrols.cpp b/indra/newview/llpanelprimmediacontrols.cpp
index fb4645f199f6f644095166d54729067ab122f0f3..76d4b5e05f0dd00c7d240e1b47f66870992b8117 100644
--- a/indra/newview/llpanelprimmediacontrols.cpp
+++ b/indra/newview/llpanelprimmediacontrols.cpp
@@ -63,9 +63,6 @@
 #include "llfloatertools.h"  // to enable hide if build tools are up
 #include "llvector4a.h"
 
-// Functions pulled from pipeline.cpp
-glh::matrix4f get_current_modelview();
-glh::matrix4f get_current_projection();
 // Functions pulled from llviewerdisplay.cpp
 bool get_hud_matrices(LLMatrix4a& proj, LLMatrix4a& model);
 
diff --git a/indra/newview/llviewercamera.cpp b/indra/newview/llviewercamera.cpp
index a1557315c5a3ecce6a387d10fc78ebc6aa6bdee4..0add1f044bf95978ebf867d91a96350fef1b7408 100644
--- a/indra/newview/llviewercamera.cpp
+++ b/indra/newview/llviewercamera.cpp
@@ -310,7 +310,7 @@ void LLViewerCamera::setPerspective(BOOL for_selection,
 	
 	gGL.loadMatrix(proj_mat);
 	
-	set_current_projection(proj_mat.getF32ptr());
+	set_current_projection(proj_mat);
 
 	gGL.matrixMode(LLRender::MM_MODELVIEW);
 
@@ -338,7 +338,7 @@ void LLViewerCamera::setPerspective(BOOL for_selection,
 	if (!for_selection && mZoomFactor == 1.f)
 	{
 		// Save GL matrices for access elsewhere in code, especially project_world_to_screen
-		set_current_modelview(modelview.getF32ptr());
+		set_current_modelview(modelview);
 	}
 
 	updateFrustumPlanes(*this);
diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp
index 106494b7ef067d9c122084fa24c9000bbdce5952..270685ccd7d1873033b6f97871cbe4af9fadc4fd 100644
--- a/indra/newview/llviewerdisplay.cpp
+++ b/indra/newview/llviewerdisplay.cpp
@@ -785,8 +785,8 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot)
 				LLGLState::checkTextureChannels();
 				LLGLState::checkClientArrays();
 
-				glh::matrix4f proj = get_current_projection();
-				glh::matrix4f mod = get_current_modelview();
+				LLMatrix4a proj = get_current_projection();
+				LLMatrix4a mod = get_current_modelview();
 				glViewport(0,0,512,512);
 				LLVOAvatar::updateFreezeCounter() ;
 
@@ -795,9 +795,9 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot)
 				set_current_projection(proj);
 				set_current_modelview(mod);
 				gGL.matrixMode(LLRender::MM_PROJECTION);
-				gGL.loadMatrix(proj.m);
+				gGL.loadMatrix(proj);
 				gGL.matrixMode(LLRender::MM_MODELVIEW);
-				gGL.loadMatrix(mod.m);
+				gGL.loadMatrix(mod);
 				gViewerWindow->setup3DViewport();
 
 				LLGLState::checkStates();
@@ -1112,8 +1112,8 @@ void render_hud_attachments()
 	gGL.matrixMode(LLRender::MM_MODELVIEW);
 	gGL.pushMatrix();
 		
-	glh::matrix4f current_proj = get_current_projection();
-	glh::matrix4f current_mod = get_current_modelview();
+	LLMatrix4a current_proj = get_current_projection();
+	LLMatrix4a current_mod = get_current_modelview();
 
 	// clamp target zoom level to reasonable values
 //	gAgentCamera.mHUDTargetZoom = llclamp(gAgentCamera.mHUDTargetZoom, 0.1f, 1.f);
@@ -1291,11 +1291,11 @@ bool setup_hud_matrices(const LLRect& screen_region)
 	// set up transform to keep HUD objects in front of camera
 	gGL.matrixMode(LLRender::MM_PROJECTION);
 	gGL.loadMatrix(proj);
-	set_current_projection(proj.getF32ptr());
+	set_current_projection(proj);
 	
 	gGL.matrixMode(LLRender::MM_MODELVIEW);
 	gGL.loadMatrix(model);
-	set_current_modelview(model.getF32ptr());
+	set_current_modelview(model);
 	return TRUE;
 }
 
@@ -1305,13 +1305,13 @@ void render_ui(F32 zoom_factor, int subfield)
 
 	LLGLState::checkStates();
 	
-	glh::matrix4f saved_view = get_current_modelview();
+	LLMatrix4a saved_view = get_current_modelview();
 
 	if (!gSnapshot)
 	{
 		gGL.pushMatrix();
 		gGL.loadMatrix(gGLLastModelView);
-		set_current_modelview(copy_matrix(gGLLastModelView));
+		set_current_modelview(get_last_modelview());
 	}
 	
 	if(LLSceneMonitor::getInstanceFast()->needsUpdate())
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 6ef02884b2b96f8680455ee4224717a6f97afadf..9ca8e7fcbd9c024b7870c3d04be104b7b71d6048 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -8590,8 +8590,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_
 		
     if (shader.getUniformLocation(LLShaderMgr::INVERSE_PROJECTION_MATRIX) != -1)
     {
-		LLMatrix4a inv_proj;
-		inv_proj.loadu(get_current_projection().m);
+		LLMatrix4a inv_proj = get_current_projection();
 		inv_proj.invert();
 		shader.uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, inv_proj.getF32ptr());
     }
@@ -8739,13 +8738,12 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_
 		shader.uniform1f(LLShaderMgr::DEFERRED_NEAR_CLIP, LLViewerCamera::getInstanceFast()->getNear() * 2.f);
 	}
 
-	shader.uniform3fv(LLShaderMgr::DEFERRED_SUN_DIR, 1, mTransformedSunDir.mV);
-    shader.uniform3fv(LLShaderMgr::DEFERRED_MOON_DIR, 1, mTransformedMoonDir.mV);
+	shader.uniform3fv(LLShaderMgr::DEFERRED_SUN_DIR, 1, mTransformedSunDir.getF32ptr());
+    shader.uniform3fv(LLShaderMgr::DEFERRED_MOON_DIR, 1, mTransformedMoonDir.getF32ptr());
 	
 	if (shader.getUniformLocation(LLShaderMgr::DEFERRED_NORM_MATRIX) >= 0)
 	{
-		LLMatrix4a norm_mat;
-		norm_mat.loadu(get_current_modelview().m);
+		LLMatrix4a norm_mat = get_current_modelview();
 		norm_mat.invert();
 		norm_mat.transpose();
 		shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_NORM_MATRIX, 1, FALSE, norm_mat.getF32ptr());
@@ -8836,18 +8834,17 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget *screen_target)
         LLGLEnable cull(GL_CULL_FACE);
         LLGLEnable blend(GL_BLEND);
 
-        glh::matrix4f mat = copy_matrix(gGLModelView);
-
-        setupHWLights(NULL);  // to set mSun/MoonDir;
+        LLMatrix4a mat = get_current_modelview();
+		{
+			setupHWLights(NULL);  // to set mSun/MoonDir;
 
-        glh::vec4f tc(mSunDir.mV);
-        mat.mult_matrix_vec(tc);
-        mTransformedSunDir.set(tc.v);
+			mTransformedSunDir.loadua(mSunDir.mV);
+			mat.rotate(mTransformedSunDir, mTransformedSunDir);
 
-        glh::vec4f tc_moon(mMoonDir.mV);
-        mat.mult_matrix_vec(tc_moon);
-        mTransformedMoonDir.set(tc_moon.v);
+			mTransformedMoonDir.loadua(mMoonDir.mV);
+			mat.rotate(mTransformedMoonDir, mTransformedMoonDir);
 
+		}
         gGL.pushMatrix();
         gGL.loadIdentity();
         gGL.matrixMode(LLRender::MM_PROJECTION);
@@ -9130,10 +9127,11 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget *screen_target)
                             continue;
                         }
 
-                        glh::vec3f tc(c);
-                        mat.mult_matrix_vec(tc);
+                        mat.affineTransform(center,center);
 
-                        fullscreen_lights.push_back(LLVector4(tc.v[0], tc.v[1], tc.v[2], s));
+						LLVector4 tc(center.getF32ptr());
+						tc.mV[VW] = s;
+                        fullscreen_lights.push_back(tc);
                         light_colors.push_back(LLVector4(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF)));
                     }
                 }
@@ -9237,23 +9235,22 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget *screen_target)
                 {
                     LL_RECORD_BLOCK_TIME(FTM_PROJECTORS);
 					
-                    LLVOVolume *volume              = drawablep->getVOVolume();
-                    LLVector3   center              = drawablep->getPositionAgent();
-                    F32 *       c                   = center.mV;
-                    F32         light_size_final    = volume->getLightRadius() * 1.5f;
-                    F32         light_falloff_final = volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF);
+                    LLVOVolume *volume = drawablep->getVOVolume();
+					LLVector4a center;
+					center.load3(drawablep->getPositionAgent().mV);
+                    F32 light_size_final = volume->getLightRadius() * 1.5f;
+                    F32 light_falloff_final = volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF);
 
                     sVisibleLightCount++;
 
-                    glh::vec3f tc(c);
-                    mat.mult_matrix_vec(tc);
+                    mat.affineTransform(center,center);
 
                     setupSpotLight(gDeferredMultiSpotLightProgram, drawablep);
 
                     // send light color to shader in linear space
                     LLColor3 col = volume->getLightLinearColor();
 
-                    gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v);
+                    gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, center.getF32ptr());
                     gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, light_size_final);
                     gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
                     gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, light_falloff_final);
@@ -9620,7 +9617,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in)
 
             mReflectionModelView = mat;
 
-            set_current_modelview(mat.getF32ptr());
+            set_current_modelview(mat);
             gGL.loadMatrix(mat);
 
             LLViewerCamera::updateFrustumPlanes(camera, FALSE, TRUE);
@@ -9719,7 +9716,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in)
             gGL.matrixMode(LLRender::MM_MODELVIEW);
             gGL.popMatrix();
 
-            set_current_modelview(saved_modelview.getF32ptr());
+            set_current_modelview(saved_modelview);
         }
 
         //LLPipeline::sUseOcclusion = occlusion;
@@ -9843,72 +9840,6 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in)
     }
 }
 
-glh::matrix4f look(const LLVector3 pos, const LLVector3 dir, const LLVector3 up)
-{
-	glh::matrix4f ret;
-
-	LLVector3 dirN;
-	LLVector3 upN;
-	LLVector3 lftN;
-
-	lftN = dir % up;
-	lftN.normVec();
-	
-	upN = lftN % dir;
-	upN.normVec();
-	
-	dirN = dir;
-	dirN.normVec();
-
-	ret.m[ 0] = lftN[0];
-	ret.m[ 1] = upN[0];
-	ret.m[ 2] = -dirN[0];
-	ret.m[ 3] = 0.f;
-
-	ret.m[ 4] = lftN[1];
-	ret.m[ 5] = upN[1];
-	ret.m[ 6] = -dirN[1];
-	ret.m[ 7] = 0.f;
-
-	ret.m[ 8] = lftN[2];
-	ret.m[ 9] = upN[2];
-	ret.m[10] = -dirN[2];
-	ret.m[11] = 0.f;
-
-	ret.m[12] = -(lftN*pos);
-	ret.m[13] = -(upN*pos);
-	ret.m[14] = dirN*pos;
-	ret.m[15] = 1.f;
-
-	return ret;
-}
-
-glh::matrix4f scale_translate_to_fit(const LLVector3 min, const LLVector3 max)
-{
-	glh::matrix4f ret;
-	ret.m[ 0] = 2/(max[0]-min[0]);
-	ret.m[ 4] = 0;
-	ret.m[ 8] = 0;
-	ret.m[12] = -(max[0]+min[0])/(max[0]-min[0]);
-
-	ret.m[ 1] = 0;
-	ret.m[ 5] = 2/(max[1]-min[1]);
-	ret.m[ 9] = 0;
-	ret.m[13] = -(max[1]+min[1])/(max[1]-min[1]);
-
-	ret.m[ 2] = 0;
-	ret.m[ 6] = 0;
-	ret.m[10] = 2/(max[2]-min[2]);
-	ret.m[14] = -(max[2]+min[2])/(max[2]-min[2]);
-
-	ret.m[ 3] = 0;
-	ret.m[ 7] = 0;
-	ret.m[11] = 0;
-	ret.m[15] = 1;
-
-	return ret;
-}
-
 static LLTrace::BlockTimerStatHandle FTM_SHADOW_RENDER("Render Shadows");
 static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA("Alpha Shadow");
 static LLTrace::BlockTimerStatHandle FTM_SHADOW_SIMPLE("Simple Shadow");
@@ -9970,10 +9901,10 @@ void LLPipeline::renderShadow(const LLMatrix4a& view, const LLMatrix4a& proj, LL
 	//generate shadow map
 	gGL.matrixMode(LLRender::MM_PROJECTION);
 	gGL.pushMatrix();
-	gGL.loadMatrix(proj.getF32ptr());
+	gGL.loadMatrix(proj);
 	gGL.matrixMode(LLRender::MM_MODELVIEW);
 	gGL.pushMatrix();
-	gGL.loadMatrix(view.getF32ptr());
+	gGL.loadMatrix(view);
 
 	stop_glerror();
 	gGLLastMatrix = NULL;
@@ -10608,8 +10539,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
 			LLViewerCamera::sCurCameraID = (LLViewerCamera::eCameraID)(LLViewerCamera::CAMERA_SHADOW0+j);
 
 			//restore render matrices
-			set_current_modelview(saved_view.getF32ptr());
-			set_current_projection(saved_proj.getF32ptr());
+			set_current_modelview(saved_view);
+			set_current_projection(saved_proj);
 
 			LLVector3 eye = camera.getOrigin();
 
@@ -11101,9 +11032,9 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
 		memcpy(gGLModelView, view[1].getF32ptr(), sizeof(F32) * 16);
 		memcpy(gGLProjection, proj[1].getF32ptr(), sizeof(F32) * 16);
 
-		gGL.loadMatrix(view[1].getF32ptr());
+		gGL.loadMatrix(view[1]);
 		gGL.matrixMode(LLRender::MM_PROJECTION);
-		gGL.loadMatrix(proj[1].getF32ptr());
+		gGL.loadMatrix(proj[1]);
 		gGL.matrixMode(LLRender::MM_MODELVIEW);
 	}
 	gGL.setColorMask(true, false);
@@ -11284,18 +11215,18 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar)
 		F32 distance = (pos-camera.getOrigin()).length();
 		F32 fov = atanf(tdim.mV[1]/distance)*2.f*RAD_TO_DEG;
 		F32 aspect = tdim.mV[0]/tdim.mV[1];
-		glh::matrix4f persp = gl_perspective(fov, aspect, 1.f, 256.f);
+		LLMatrix4a persp = ALGLMath::genPersp(fov, aspect, 1.f, 256.f);
 		set_current_projection(persp);
-		gGL.loadMatrix(persp.m);
+		gGL.loadMatrix(persp);
 
 		gGL.matrixMode(LLRender::MM_MODELVIEW);
 		gGL.pushMatrix();
-		glh::matrix4f mat;
-		camera.getOpenGLTransform(mat.m);
+		LLMatrix4a mat;
+		camera.getOpenGLTransform(mat.getF32ptr());
 
-		mat = glh::matrix4f((GLfloat*) OGL_TO_CFR_ROTATION) * mat;
+		mat.setMul(OGL_TO_CFR_ROTATION_4A, mat);
 
-		gGL.loadMatrix(mat.m);
+		gGL.loadMatrix(mat);
 		set_current_modelview(mat);
 
 		glClearColor(0.0f,0.0f,0.0f,0.0f);
diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h
index 35ebe24b70aa648f4d812851dcea89bcd57fa6ba..b22ccd7896d29dc9239a6496e2d199b402616439 100644
--- a/indra/newview/pipeline.h
+++ b/indra/newview/pipeline.h
@@ -691,8 +691,8 @@ class LLPipeline
     LLVector4			mMoonDir;
     bool                mNeedsShadowTargetClear;
 
-	LLVector4			mTransformedSunDir;
-    LLVector4			mTransformedMoonDir;
+	LL_ALIGN_16(LLVector4a			mTransformedSunDir);
+    LL_ALIGN_16(LLVector4a			mTransformedMoonDir);
 
 	bool					mInitialized;
 	bool					mVertexShadersEnabled;
diff --git a/indra/newview/rlveffects.cpp b/indra/newview/rlveffects.cpp
index a6cdfb14d7156504ecd51d36d2c1a98fb317f9b0..e37381e5423cea71b1b1d1e1fa77c28d969b15fb 100644
--- a/indra/newview/rlveffects.cpp
+++ b/indra/newview/rlveffects.cpp
@@ -304,7 +304,9 @@ ERlvCmdRet RlvSphereEffect::onValueMaxChanged(const LLUUID& idRlvObj, const boos
 
 void RlvSphereEffect::setShaderUniforms(LLGLSLShader* pShader)
 {
-	pShader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, get_current_projection().inverse().m);
+	LLMatrix4a proj = get_current_projection();
+	proj.invert();
+	pShader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, proj.getF32ptr());
 	pShader->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, gPipeline.mScreen.getWidth(), gPipeline.mScreen.getHeight());
 	pShader->uniform1i(LLShaderMgr::RLV_EFFECT_MODE, llclamp((int)m_eMode, 0, (int)ESphereMode::Count));
 
@@ -320,15 +322,15 @@ void RlvSphereEffect::setShaderUniforms(LLGLSLShader* pShader)
 			posSphereOrigin.setVec((isAgentAvatarValid()) ? gAgentAvatarp->getRenderPosition() : gAgent.getPositionAgent(), 1.0f);
 			break;
 	}
-	glh::vec4f posSphereOriginGl(posSphereOrigin.mV);
-	const glh::matrix4f& mvMatrix = gGLModelView;
-	mvMatrix.mult_matrix_vec(posSphereOriginGl);
-	pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM1, 1, posSphereOriginGl.v);
+	LLVector4a posSphereOriginGl;
+	posSphereOriginGl.loadua(posSphereOrigin.mV);
+	get_current_modelview().rotate4(posSphereOriginGl, posSphereOriginGl);
+	pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM1, 1, posSphereOriginGl.getF32ptr());
 
 	// Pack min/max distance and alpha together
 	float nDistMin = m_nDistanceMin.get(), nDistMax = m_nDistanceMax.get();
-	const glh::vec4f sphereParams(m_nValueMin.get(), nDistMin, m_nValueMax.get(), (nDistMax >= nDistMin) ? nDistMax : nDistMin);
-	pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM2, 1, sphereParams.v);
+	const LLVector4 sphereParams(m_nValueMin.get(), nDistMin, m_nValueMax.get(), (nDistMax >= nDistMin) ? nDistMax : nDistMin);
+	pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM2, 1, sphereParams.mV);
 
 	// Pass dist extend
 	int eDistExtend = (int)m_eDistExtend;
@@ -336,7 +338,7 @@ void RlvSphereEffect::setShaderUniforms(LLGLSLShader* pShader)
 
 	// Pass effect params
 	const glh::vec4f effectParams(m_Params.get().mV);
-	pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM4, 1, effectParams.v);
+	pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM4, 1, m_Params.get().mV);
 }
 
 void RlvSphereEffect::renderPass(LLGLSLShader* pShader, const LLShaderEffectParams* pParams) const