From 530981a2149a74e1dc003cea1bbc9dc392fcae60 Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Thu, 15 Sep 2011 00:54:25 -0500
Subject: [PATCH] SH-2243 work in progress -- no more deprecated built-in
 matrix state when using shaders.

---
 indra/llrender/llglslshader.cpp               |   4 +
 indra/llrender/llglslshader.h                 |   3 +-
 indra/llrender/llrender.cpp                   | 106 +++++++++++++++---
 .../shaders/class1/avatar/avatarV.glsl        |   8 +-
 .../shaders/class1/avatar/eyeballV.glsl       |  14 ++-
 .../shaders/class1/avatar/pickAvatarV.glsl    |   6 +-
 .../class1/deferred/alphaSkinnedV.glsl        |  10 +-
 .../shaders/class1/deferred/alphaV.glsl       |  15 ++-
 .../class1/deferred/attachmentShadowV.glsl    |  10 +-
 .../shaders/class1/deferred/avatarAlphaV.glsl |   6 +-
 .../shaders/class1/deferred/avatarEyesV.glsl  |  11 +-
 .../class1/deferred/avatarShadowV.glsl        |   4 +-
 .../shaders/class1/deferred/avatarV.glsl      |   4 +-
 .../shaders/class1/deferred/blurLightV.glsl   |   6 +-
 .../shaders/class1/deferred/bumpSkinnedV.glsl |  10 +-
 .../shaders/class1/deferred/bumpV.glsl        |  14 ++-
 .../shaders/class1/deferred/cloudsV.glsl      |   6 +-
 .../class1/deferred/diffuseNoColorV.glsl      |  31 ++++-
 .../class1/deferred/diffuseSkinnedV.glsl      |  10 +-
 .../shaders/class1/deferred/diffuseV.glsl     |  11 +-
 .../shaders/class1/deferred/emissiveV.glsl    |  31 ++++-
 .../shaders/class1/deferred/fullbrightV.glsl  |  12 +-
 .../shaders/class1/deferred/giV.glsl          |   6 +-
 .../shaders/class1/deferred/impostorV.glsl    |   9 +-
 .../shaders/class1/deferred/luminanceV.glsl   |   3 +-
 .../class1/deferred/multiPointLightV.glsl     |   3 +-
 .../shaders/class1/deferred/pointLightV.glsl  |   4 +-
 .../class1/deferred/postDeferredV.glsl        |   6 +-
 .../shaders/class1/deferred/postgiV.glsl      |   4 +-
 .../class1/deferred/shadowAlphaMaskV.glsl     |   9 +-
 .../shaders/class1/deferred/shadowV.glsl      |   6 +-
 .../shaders/class1/deferred/skyV.glsl         |   6 +-
 .../shaders/class1/deferred/softenLightV.glsl |   3 +-
 .../shaders/class1/deferred/starsV.glsl       |   8 +-
 .../shaders/class1/deferred/sunLightV.glsl    |   4 +-
 .../shaders/class1/deferred/terrainV.glsl     |  12 +-
 .../shaders/class1/deferred/treeShadowV.glsl  |  27 ++++-
 .../shaders/class1/deferred/treeV.glsl        |  11 +-
 .../shaders/class1/deferred/waterV.glsl       |  10 +-
 .../shaders/class1/effects/glowExtractV.glsl  |   4 +-
 .../shaders/class1/effects/glowV.glsl         |   4 +-
 .../shaders/class1/environment/terrainV.glsl  |  24 ++--
 .../shaders/class1/environment/waterV.glsl    |   8 +-
 .../class1/interface/customalphaV.glsl        |   6 +-
 .../shaders/class1/interface/debugV.glsl      |   4 +-
 .../class1/interface/glowcombineFXAAV.glsl    |  26 ++++-
 .../class1/interface/glowcombineV.glsl        |   6 +-
 .../shaders/class1/interface/highlightV.glsl  |   9 +-
 .../shaders/class1/interface/occlusionV.glsl  |   4 +-
 .../class1/interface/onetexturenocolorV.glsl  |  21 +++-
 .../shaders/class1/interface/solidcolorV.glsl |   4 +-
 .../class1/interface/splattexturerectV.glsl   |   6 +-
 .../class1/interface/twotextureaddV.glsl      |   3 +-
 .../shaders/class1/interface/uiV.glsl         |   8 +-
 .../shaders/class1/objects/bumpV.glsl         |  11 +-
 .../class1/objects/emissiveSkinnedV.glsl      |  31 ++++-
 .../shaders/class1/objects/emissiveV.glsl     |  32 +++++-
 .../class1/objects/fullbrightNoColorV.glsl    |  30 ++++-
 .../objects/fullbrightShinySkinnedV.glsl      |  12 +-
 .../class1/objects/fullbrightShinyV.glsl      |  17 ++-
 .../class1/objects/fullbrightSkinnedV.glsl    |   9 +-
 .../shaders/class1/objects/fullbrightV.glsl   |  12 +-
 .../shaders/class1/objects/impostorV.glsl     |   8 +-
 .../shaders/class1/objects/previewV.glsl      |  33 +++++-
 .../class1/objects/shinySimpleSkinnedV.glsl   |  13 ++-
 .../shaders/class1/objects/shinyV.glsl        |  15 ++-
 .../class1/objects/simpleNoColorV.glsl        |  33 +++++-
 .../class1/objects/simpleSkinnedV.glsl        |  10 +-
 .../shaders/class1/objects/simpleV.glsl       |  15 ++-
 .../shaders/class1/objects/treeV.glsl         |  31 ++++-
 .../shaders/class2/avatar/eyeballV.glsl       |  14 ++-
 .../class2/deferred/alphaSkinnedV.glsl        |  13 ++-
 .../shaders/class2/deferred/alphaV.glsl       |  17 ++-
 .../shaders/class2/deferred/avatarAlphaV.glsl |   3 +-
 .../shaders/class2/deferred/edgeV.glsl        |   3 +-
 .../shaders/class2/deferred/softenLightV.glsl |   5 +-
 .../shaders/class2/deferred/sunLightV.glsl    |   6 +-
 .../shaders/class2/effects/blurV.glsl         |   5 +-
 .../shaders/class2/effects/drawQuadV.glsl     |   5 +-
 .../shaders/class2/environment/terrainV.glsl  |  14 ++-
 .../class2/objects/fullbrightShinyV.glsl      |  17 ++-
 .../shaders/class2/objects/fullbrightV.glsl   |  11 +-
 .../shaders/class2/objects/shinyV.glsl        |  17 ++-
 .../class2/objects/simpleNonIndexedV.glsl     |  31 ++++-
 .../shaders/class2/objects/simpleV.glsl       |  13 ++-
 .../shaders/class2/windlight/cloudsV.glsl     |   6 +-
 .../shaders/class2/windlight/skyV.glsl        |   3 +-
 .../shaders/class3/avatar/avatarV.glsl        |   6 +-
 .../class3/deferred/giDownsampleV.glsl        |   6 +-
 .../shaders/class3/deferred/giFinalV.glsl     |   6 +-
 .../shaders/class3/deferred/giV.glsl          |   6 +-
 .../shaders/class3/deferred/luminanceV.glsl   |   6 +-
 .../class3/deferred/postDeferredV.glsl        |   6 +-
 .../shaders/class3/deferred/postgiV.glsl      |   6 +-
 .../shaders/class3/deferred/softenLightV.glsl |   5 +-
 indra/newview/llviewershadermgr.cpp           |   2 +-
 96 files changed, 847 insertions(+), 297 deletions(-)

diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp
index 61648e527da..95ce2271710 100644
--- a/indra/llrender/llglslshader.cpp
+++ b/indra/llrender/llglslshader.cpp
@@ -76,6 +76,10 @@ hasAlphaMask(false)
 LLGLSLShader::LLGLSLShader()
 	: mProgramObject(0), mActiveTextureChannels(0), mShaderLevel(0), mShaderGroup(SG_DEFAULT), mUniformsDirty(FALSE)
 {
+	for (U32 i = 0; i < LLRender::NUM_MATRIX_MODES; ++i)
+	{
+		mMatHash[i] = 0xFFFFFFFF;
+	}
 }
 
 void LLGLSLShader::unload()
diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h
index 558ea66b50f..c1765e2701a 100644
--- a/indra/llrender/llglslshader.h
+++ b/indra/llrender/llglslshader.h
@@ -117,7 +117,6 @@ class LLGLSLShader
 	GLint getAttribLocation(U32 attrib);
 	GLint mapUniformTextureChannel(GLint location, GLenum type);
 	
-
 	//enable/disable texture channel for specified uniform
 	//if given texture uniform is active in the shader, 
 	//the corresponding channel will be active upon return
@@ -132,6 +131,8 @@ class LLGLSLShader
 	// Unbinds any previously bound shader by explicitly binding no shader.
 	static void bindNoShader(void);
 
+	U32 mMatHash[LLRender::NUM_MATRIX_MODES];
+
 	GLhandleARB mProgramObject;
 	std::vector<GLint> mAttribute; //lookup table of attribute enum to attribute channel
 	std::vector<GLint> mUniform;   //lookup table of uniform enum to uniform location
diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp
index 27d25c0d3a6..359e6fd5609 100644
--- a/indra/llrender/llrender.cpp
+++ b/indra/llrender/llrender.cpp
@@ -1018,6 +1018,8 @@ void LLRender::refreshState(void)
 
 void LLRender::syncMatrices()
 {
+	stop_glerror();
+
 	GLenum mode[] = 
 	{
 		GL_MODELVIEW,
@@ -1028,27 +1030,105 @@ void LLRender::syncMatrices()
 		GL_TEXTURE,
 	};
 
-	for (U32 i = 0; i < 2; ++i)
+	std::string name[] = 
+	{
+		"modelview_matrix",
+		"projection_matrix",
+		"texture_matrix0",
+		"texture_matrix1",
+		"texture_matrix2",
+		"texture_matrix3",
+	};
+
+	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+
+	if (shader)
 	{
-		if (mMatHash[i] != mCurMatHash[i])
+		
+		llassert(shader);
+
+		bool do_normal = false;
+		bool do_mvp = false;
+
+		for (U32 i = 0; i < NUM_MATRIX_MODES; ++i)
 		{
-			glMatrixMode(mode[i]);
-			glLoadMatrixf(mMatrix[i][mMatIdx[i]].m);
-			mCurMatHash[i] = mMatHash[i];
+			if (mMatHash[i] != shader->mMatHash[i])
+			{
+				shader->uniformMatrix4fv(name[i], 1, GL_FALSE, mMatrix[i][mMatIdx[i]].m);
+				shader->mMatHash[i] = mMatHash[i];
+
+				if (i == MM_MODELVIEW)
+				{
+					do_normal = true;
+					do_mvp = true;
+				}
+				else if (i == MM_PROJECTION)
+				{
+					do_mvp = true;
+				}
+			}
 		}
-	}
 
-	for (U32 i = 2; i < NUM_MATRIX_MODES; ++i)
+		if (do_normal)
+		{
+			S32 loc = shader->getUniformLocation("normal_matrix");
+			if (loc > -1)
+			{
+				U32 i = MM_MODELVIEW;
+
+				glh::matrix4f norm = mMatrix[i][mMatIdx[i]].inverse().transpose();
+
+				F32 norm_mat[] = 
+				{
+					norm.m[0], norm.m[1], norm.m[2],
+					norm.m[4], norm.m[5], norm.m[6],
+					norm.m[8], norm.m[9], norm.m[10] 
+				};
+
+				shader->uniformMatrix3fv("normal_matrix", 1, GL_FALSE, norm_mat);
+			}
+		}
+
+		if (do_mvp)
+		{
+			S32 loc = shader->getUniformLocation("modelview_projection_matrix");
+			if (loc > -1)
+			{
+				U32 mv = MM_MODELVIEW;
+				U32 proj = MM_PROJECTION;
+
+				glh::matrix4f mvp = mMatrix[mv][mMatIdx[mv]];
+				mvp.mult_left(mMatrix[proj][mMatIdx[proj]]);
+				
+				shader->uniformMatrix4fv("modelview_projection_matrix", 1, GL_FALSE, mvp.m);
+			}
+		}
+	}
+	else
 	{
-		if (mMatHash[i] != mCurMatHash[i])
+		for (U32 i = 0; i < 2; ++i)
 		{
-			gGL.getTexUnit(i-2)->activate();
-			glMatrixMode(mode[i]);
-			glLoadMatrixf(mMatrix[i][mMatIdx[i]].m);
-			mCurMatHash[i] = mMatHash[i];
+			if (mMatHash[i] != mCurMatHash[i])
+			{
+				glMatrixMode(mode[i]);
+				glLoadMatrixf(mMatrix[i][mMatIdx[i]].m);
+				mCurMatHash[i] = mMatHash[i];
+			}
+		}
+
+		for (U32 i = 2; i < NUM_MATRIX_MODES; ++i)
+		{
+			if (mMatHash[i] != mCurMatHash[i])
+			{
+				gGL.getTexUnit(i-2)->activate();
+				glMatrixMode(mode[i]);
+				glLoadMatrixf(mMatrix[i][mMatIdx[i]].m);
+				mCurMatHash[i] = mMatHash[i];
+			}
 		}
 	}
-	
+
+	stop_glerror();
 }
 
 void LLRender::translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z)
diff --git a/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl b/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl
index ec1a8137907..c98b99b15ac 100644
--- a/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl
+++ b/indra/newview/app_settings/shaders/class1/avatar/avatarV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 projection_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec2 texcoord0;
@@ -51,9 +53,7 @@ void main()
 	norm.z = dot(trans[2].xyz, normal);
 	norm = normalize(norm);
 		
-	gl_Position = gl_ProjectionMatrix * pos;
-	
-	//gl_Position = gl_ModelViewProjectionMatrix * position;
+	gl_Position = projection_matrix * pos;
 	
 	gl_FogFragCoord = length(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl b/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl
index 31db10ae855..9a19fb928bd 100644
--- a/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl
+++ b/indra/newview/app_settings/shaders/class1/avatar/eyeballV.glsl
@@ -22,7 +22,11 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec4 diffuse_color;
@@ -35,12 +39,12 @@ void calcAtmospherics(vec3 inPositionEye);
 void main()
 {
 	//transform vertex
-	vec3 pos = (gl_ModelViewMatrix * vec4(position.xyz, 1.0)).xyz;
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	vec3 pos = (modelview_matrix * vec4(position.xyz, 1.0)).xyz;
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 		
 	calcAtmospherics(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class1/avatar/pickAvatarV.glsl b/indra/newview/app_settings/shaders/class1/avatar/pickAvatarV.glsl
index f07e5c124b1..21a9e91bf51 100644
--- a/indra/newview/app_settings/shaders/class1/avatar/pickAvatarV.glsl
+++ b/indra/newview/app_settings/shaders/class1/avatar/pickAvatarV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 projection_matrix;
+
 attribute vec3 position;
 attribute vec4 diffuse_color;
 attribute vec2 texcoord0;
@@ -41,5 +43,5 @@ void main()
 			
 	gl_FrontColor = diffuse_color;
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
-	gl_Position = gl_ProjectionMatrix * pos;
+	gl_Position = projection_matrix * pos;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl
index 2c2b58d59b3..9deb9a701e6 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl
@@ -21,7 +21,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 projection_matrix;
+uniform mat4 modelview_matrix;
 
 attribute vec3 position;
 attribute vec3 normal;
@@ -86,14 +88,14 @@ void main()
 	vec3 norm;
 	
 	mat4 trans = getObjectSkinnedTransform();
-	trans = gl_ModelViewMatrix * trans;
+	trans = modelview_matrix * trans;
 	
 	pos = trans * vec4(position.xyz, 1.0);
 	
 	norm = position.xyz + normal.xyz;
-	norm = normalize(( trans*vec4(norm, 1.0) ).xyz-pos.xyz);
+	norm = normalize(( trans*vec4(norojrm, 1.0) ).xyz-pos.xyz);
 	
-	vec4 frag_pos = gl_ProjectionMatrix * pos;
+	vec4 frag_pos = projection_matrix * pos;
 	gl_Position = frag_pos;
 	
 	vary_position = pos.xyz;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl
index 7a2f34ca1df..51e7c0780de 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl
@@ -23,6 +23,11 @@
  * $/LicenseInfo$
  */
 
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec4 position;
 attribute vec3 normal;
 attribute vec4 diffuse_color;
@@ -85,12 +90,12 @@ void main()
 	//transform vertex
 	vec4 vert = vec4(position.xyz, 1.0);
 	vary_texture_index = position.w;
-	vec4 pos = (gl_ModelViewMatrix * vert);
-	gl_Position = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
+	vec4 pos = (modelview_matrix * vert);
+	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
 	
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 	
 	float dp_directional_light = max(0.0, dot(norm, gl_LightSource[0].position.xyz));
 	vary_position = pos.xyz + gl_LightSource[0].position.xyz * (1.0-dp_directional_light)*shadow_offset;
@@ -126,7 +131,7 @@ void main()
 
 	gl_FogFragCoord = pos.z;
 	
-	pos = gl_ModelViewProjectionMatrix * vert;
+	pos = modelview_projection_matrix * vert;
 	vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip);
 	
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl
index e03615eebbd..fc055e555d2 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl
@@ -22,6 +22,10 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 projection_matrix;
+uniform mat4 modelview_matrix;
+uniform mat4 texture_matrix0;
+
 attribute vec3 position;
 attribute vec4 diffuse_color;
 attribute vec2 texcoord0;
@@ -31,16 +35,16 @@ mat4 getObjectSkinnedTransform();
 void main()
 {
 	//transform vertex
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	mat4 mat = getObjectSkinnedTransform();
 	
-	mat = gl_ModelViewMatrix * mat;
+	mat = modelview_matrix * mat;
 	vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz;
 	
 	gl_FrontColor = diffuse_color;
 	
-	vec4 p = gl_ProjectionMatrix * vec4(pos, 1.0);
+	vec4 p = projection_matrix * vec4(pos, 1.0);
 	p.z = max(p.z, -p.w+0.01);
 	gl_Position = p;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaV.glsl
index e15727f6f7b..df4de4f4329 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 projection_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec2 texcoord0;
@@ -96,7 +98,7 @@ void main()
 	norm.z = dot(trans[2].xyz, normal);
 	norm = normalize(norm);
 		
-	vec4 frag_pos = gl_ProjectionMatrix * pos;
+	vec4 frag_pos = projection_matrix * pos;
 	gl_Position = frag_pos;
 	
 	vary_position = pos.xyz;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl
index 58efa475671..d5c20a22d93 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl
@@ -22,7 +22,10 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec3 normal;
@@ -34,10 +37,10 @@ varying vec3 vary_normal;
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0); 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
-	vary_normal = normalize(gl_NormalMatrix * normal);
+	vary_normal = normalize(normal_matrix * normal);
 
 	gl_FrontColor = diffuse_color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl
index 543e998def7..6835b9c0214 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl
@@ -23,7 +23,7 @@
  * $/LicenseInfo$
  */
  
-
+uniform mat4 projection_matrix;
 
 mat4 getSkinnedTransform();
 
@@ -52,7 +52,7 @@ void main()
 	norm.z = dot(trans[2].xyz, normal);
 	norm = normalize(norm);
 	
-	pos = gl_ProjectionMatrix * pos;
+	pos = projection_matrix * pos;
 	post_pos = pos;
 
 	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl
index 66e9119e28e..704845d310a 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl
@@ -23,6 +23,8 @@
  * $/LicenseInfo$
  */
  
+uniform mat4 projection_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec2 texcoord0;
@@ -54,7 +56,7 @@ void main()
 	
 	vary_normal = norm;
 	
-	gl_Position = gl_ProjectionMatrix * pos;
+	gl_Position = projection_matrix * pos;
 }
 
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl
index 0168c40ae53..5339e380181 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 varying vec2 vary_fragcoord;
@@ -31,7 +33,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
 	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl
index 421299d4a78..cf93430217e 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl
@@ -22,6 +22,10 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 projection_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+
 attribute vec3 position;
 attribute vec4 diffuse_color;
 attribute vec3 normal;
@@ -36,11 +40,11 @@ mat4 getObjectSkinnedTransform();
 
 void main()
 {
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	mat4 mat = getObjectSkinnedTransform();
 	
-	mat = gl_ModelViewMatrix * mat;
+	mat = modelview_matrix * mat;
 	
 	vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz;
 	
@@ -53,6 +57,6 @@ void main()
 	vary_mat1 = vec3(t.y, b.y, n.y);
 	vary_mat2 = vec3(t.z, b.z, n.z);
 	
-	gl_Position = gl_ProjectionMatrix*vec4(pos, 1.0);
+	gl_Position = projection_matrix*vec4(pos, 1.0);
 	gl_FrontColor = diffuse_color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl
index b724def93de..9ec31383acf 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl
@@ -22,7 +22,11 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec4 diffuse_color;
 attribute vec3 normal;
@@ -36,11 +40,11 @@ varying vec3 vary_mat2;
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0); 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
-	vec3 n = normalize(gl_NormalMatrix * normal);
-	vec3 b = normalize(gl_NormalMatrix * binormal);
+	vec3 n = normalize(normal_matrix * normal);
+	vec3 b = normalize(normal_matrix * binormal);
 	vec3 t = cross(b, n);
 	
 	vary_mat0 = vec3(t.x, b.x, n.x);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl
index 297b3904a60..67b5e7fb837 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec2 texcoord0;
 
@@ -60,7 +62,7 @@ void main()
 {
 
 	// World / view / projection
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl
index ff9578e2533..37864578ecd 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl
@@ -1,10 +1,31 @@
 /** 
  * @file diffuseNoColorV.glsl
  *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix; 
 
 attribute vec3 position;
 attribute vec3 normal;
@@ -16,8 +37,8 @@ varying float vary_texture_index;
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0); 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
-	vary_normal = normalize(gl_NormalMatrix * normal);
+	vary_normal = normalize(normal_matrix * normal);
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseSkinnedV.glsl
index 02fb34af326..880a7ea0a29 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/diffuseSkinnedV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseSkinnedV.glsl
@@ -22,7 +22,9 @@
  * $/LicenseInfo$
  */
 
-
+uniform mat4 projection_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
 
 attribute vec3 position;
 attribute vec4 diffuse_color;
@@ -35,11 +37,11 @@ mat4 getObjectSkinnedTransform();
 
 void main()
 {
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	mat4 mat = getObjectSkinnedTransform();
 	
-	mat = gl_ModelViewMatrix * mat;
+	mat = modelview_matrix * mat;
 	vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz;
 	
 	vec4 norm = vec4(position.xyz, 1.0);
@@ -51,5 +53,5 @@ void main()
 			
 	gl_FrontColor = diffuse_color;
 	
-	gl_Position = gl_ProjectionMatrix*vec4(pos, 1.0);
+	gl_Position = projection_matrix*vec4(pos, 1.0);
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl
index 553cfff52f2..e158df13f70 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl
@@ -22,7 +22,10 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec4 position;
 attribute vec4 diffuse_color;
@@ -35,11 +38,11 @@ varying float vary_texture_index;
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0); 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	vary_texture_index = position.w;
-	vary_normal = normalize(gl_NormalMatrix * normal);
+	vary_normal = normalize(normal_matrix * normal);
 
 	gl_FrontColor = diffuse_color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl
index 9841943fe69..fccf8554d21 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl
@@ -1,10 +1,31 @@
 /** 
  * @file emissiveV.glsl
  *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec4 position;
 attribute float emissive;
@@ -23,12 +44,12 @@ void main()
 {
 	//transform vertex
 	vec4 vert = vec4(position.xyz, 1.0);
-	vec4 pos = (gl_ModelViewMatrix * vert);
+	vec4 pos = (modelview_matrix * vert);
 	vary_texture_index = position.w;
 
-	gl_Position = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
 	
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	calcAtmospherics(pos.xyz);
 	
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl
index 93571058dce..27591654719 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl
@@ -22,7 +22,11 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
+
 
 attribute vec4 position;
 attribute vec4 diffuse_color;
@@ -41,12 +45,12 @@ void main()
 {
 	//transform vertex
 	vec4 vert = vec4(position.xyz, 1.0);
-	vec4 pos = (gl_ModelViewMatrix * vert);
+	vec4 pos = (modelview_matrix * vert);
 	vary_texture_index = position.w;
 
-	gl_Position = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
 	
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	calcAtmospherics(pos.xyz);
 	
diff --git a/indra/newview/app_settings/shaders/class1/deferred/giV.glsl b/indra/newview/app_settings/shaders/class1/deferred/giV.glsl
index 1a23be349ee..2766691bd02 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/giV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/giV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec4 diffuse_color;
 attribute vec2 texcoord0;
@@ -35,7 +37,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
 	
 	vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res;	
diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl
index 28ba2c432da..645b0d793a7 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl
@@ -22,7 +22,10 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec4 diffuse_color;
 attribute vec2 texcoord0;
@@ -30,8 +33,8 @@ attribute vec2 texcoord0;
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0); 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	gl_FrontColor = diffuse_color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl
index 3f2e07cf087..dafc55a6ff5 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl
@@ -23,6 +23,7 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 modelview_projection_matrix;
  
 attribute vec3 position;
 attribute vec4 diffuse_color;
@@ -34,7 +35,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos;
 	
 	vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res;	
diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl
index 39e60b6cc8d..1d54d7bede0 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl
@@ -23,6 +23,7 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 
@@ -31,7 +32,7 @@ varying vec4 vary_fragcoord;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	vary_fragcoord = pos;
 
 	gl_Position = pos;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl
index afaf58020bc..cab98175834 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl
@@ -23,6 +23,8 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 varying vec4 vary_fragcoord;
@@ -30,7 +32,7 @@ varying vec4 vary_fragcoord;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	vary_fragcoord = pos;
 		
 	gl_Position = pos;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl
index 74a9df64e0b..b11f26fbae3 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 varying vec2 vary_fragcoord;
@@ -35,7 +37,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos;	
 	vary_tc = (pos.xy*0.5+0.5)*tc_scale;
 	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/postgiV.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiV.glsl
index a3751be1fbf..61c63936482 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/postgiV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/postgiV.glsl
@@ -22,6 +22,8 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
+
+uniform mat4 modelview_projection_matrix;
  
 attribute vec3 position;
 
@@ -32,7 +34,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 	
 	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl
index bbd7516337a..f7bed00214d 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl
@@ -22,7 +22,10 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec4 diffuse_color;
 attribute vec2 texcoord0;
@@ -32,12 +35,12 @@ varying vec4 post_pos;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix*vec4(position.xyz, 1.0);
 	
 	post_pos = pos;
 	
 	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w);
 	
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	gl_FrontColor = diffuse_color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl
index 1ac3dbd5dea..190cac9e2ce 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 varying vec4 post_pos;
@@ -30,7 +32,7 @@ varying vec4 post_pos;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix*vec4(position.xyz, 1.0);
 	
 	post_pos = pos;
 	
diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl
index 23171fe940b..e97d3e08287 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec2 texcoord0;
 
@@ -58,7 +60,7 @@ void main()
 {
 
 	// World / view / projection
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
 
 	// Get relative position
diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl
index 4b6b3c242ea..7d1e99b4aaf 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl
@@ -23,6 +23,7 @@
  * $/LicenseInfo$
  */
  
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 
@@ -32,7 +33,7 @@ varying vec2 vary_fragcoord;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
 		
 	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl
index dbd2b5595a3..1fcb05ef2c8 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec4 diffuse_color;
@@ -31,7 +33,7 @@ attribute vec2 texcoord0;
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0); 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	gl_FrontColor = diffuse_color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl
index d19e67b67de..10751304ae2 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl
@@ -22,6 +22,8 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
+
+uniform mat4 modelview_projection_matrix;
  
 attribute vec3 position;
 
@@ -32,7 +34,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
 	
 	vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res;	
diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl
index 793106f2cf2..7f84ef1cff3 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl
@@ -22,7 +22,11 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec4 diffuse_color;
@@ -48,12 +52,12 @@ vec4 texgen_object(vec4  vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1)
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 			
-	vary_normal = normalize(gl_NormalMatrix * normal);
+	vary_normal = normalize(normal_matrix * normal);
 	
 	// Transform and pass tex coords
- 	gl_TexCoord[0].xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), gl_TextureMatrix[0], gl_ObjectPlaneS[0], gl_ObjectPlaneT[0]).xy;
+ 	gl_TexCoord[0].xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, gl_ObjectPlaneS[0], gl_ObjectPlaneT[0]).xy;
 	
 	vec4 t = vec4(texcoord1,0,1);
 	
diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl
index 42ce2f52267..c695d374ac9 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl
@@ -1,9 +1,30 @@
 /** 
  * @file treeShadowV.glsl
  *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
  
 attribute vec3 position;
 attribute vec2 texcoord0;
@@ -13,11 +34,11 @@ varying vec4 post_pos;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix*vec4(position.xyz, 1.0);
 	
 	post_pos = pos;
 	
 	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w);
 	
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl
index 2ec73980242..45bfc0ce09c 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl
@@ -22,7 +22,10 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
+uniform mat3 normal_matrix;
 
 attribute vec3 position;
 attribute vec3 normal;
@@ -33,10 +36,10 @@ varying vec3 vary_normal;
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0); 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
-	vary_normal = normalize(gl_NormalMatrix * normal);
+	vary_normal = normalize(normal_matrix * normal);
 
 	gl_FrontColor = vec4(1,1,1,1);
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl
index 2f808b25db2..ac51cb1741b 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 
@@ -50,7 +52,7 @@ void main()
 {
 	//transform vertex
 	vec4 pos = vec4(position.xyz, 1.0);
-	mat4 modelViewProj = gl_ModelViewProjectionMatrix;
+	mat4 modelViewProj = modelview_projection_matrix;
 	
 	vec4 oPosition;
 		    
@@ -69,7 +71,7 @@ void main()
 		
 	oPosition = vec4(position, 1.0);
 	oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d);
-	vary_position = gl_ModelViewMatrix * oPosition;
+	vary_position = modelview_matrix * oPosition;
 	oPosition = modelViewProj * oPosition;
 	
 	refCoord.xyz = oPosition.xyz + vec3(0,0,0.2);
@@ -81,7 +83,7 @@ void main()
 	//push position for further horizon effect.
 	pos.xyz = oEyeVec.xyz*(waterHeight/oEyeVec.z);
 	pos.w = 1.0;
-	pos = gl_ModelViewMatrix*pos;
+	pos = modelview_matrix*pos;
 	
 	calcAtmospherics(pos.xyz);
 		
diff --git a/indra/newview/app_settings/shaders/class1/effects/glowExtractV.glsl b/indra/newview/app_settings/shaders/class1/effects/glowExtractV.glsl
index b5f6cb62d93..628489296fa 100644
--- a/indra/newview/app_settings/shaders/class1/effects/glowExtractV.glsl
+++ b/indra/newview/app_settings/shaders/class1/effects/glowExtractV.glsl
@@ -23,13 +23,15 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec2 texcoord0;
 
 
 void main() 
 {
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position, 1.0);
 	
 	gl_TexCoord[0].xy = texcoord0;
 }
diff --git a/indra/newview/app_settings/shaders/class1/effects/glowV.glsl b/indra/newview/app_settings/shaders/class1/effects/glowV.glsl
index e8fd7a796d4..615ca6a0b4d 100644
--- a/indra/newview/app_settings/shaders/class1/effects/glowV.glsl
+++ b/indra/newview/app_settings/shaders/class1/effects/glowV.glsl
@@ -23,6 +23,8 @@
  * $/LicenseInfo$
  */
  
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec2 texcoord0;
 
@@ -30,7 +32,7 @@ uniform vec2 glowDelta;
 
 void main() 
 {
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position, 1.0);
 	
 	gl_TexCoord[0].xy = texcoord0 + glowDelta*(-3.5);
 	gl_TexCoord[1].xy = texcoord0 + glowDelta*(-2.5);
diff --git a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl
index 8facc1ca963..04b3033dd83 100644
--- a/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl
+++ b/indra/newview/app_settings/shaders/class1/environment/terrainV.glsl
@@ -22,7 +22,15 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 texture_matrix1;
+uniform mat4 texture_matrix2;
+uniform mat4 texture_matrix3;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec4 diffuse_color;
@@ -51,17 +59,17 @@ vec4 texgen_object(vec4  vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1)
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 			
-	vec4 pos = gl_ModelViewMatrix * position;
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec4 pos = modelview_matrix * position;
+	vec3 norm = normalize(normal_matrix * normal);
 	
 	vec4 color = calcLighting(pos.xyz, norm, vec4(1,1,1,1), diffuse_color);
 	
 	gl_FrontColor = color;
 	
-	gl_TexCoord[0] = texgen_object(vec4(position.xyz, 1.0),vec4(texcoord0,0,1),gl_TextureMatrix[0],gl_ObjectPlaneS[0],gl_ObjectPlaneT[0]);
-	gl_TexCoord[1] = gl_TextureMatrix[1]*vec4(texcoord1,0,1);
-	gl_TexCoord[2] = texgen_object(vec4(position.xyz, 1.0),vec4(texcoord2,0,1),gl_TextureMatrix[2],gl_ObjectPlaneS[2],gl_ObjectPlaneT[2]);
-	gl_TexCoord[3] = gl_TextureMatrix[3]*vec4(texcoord3,0,1);
+	gl_TexCoord[0] = texgen_object(vec4(position.xyz, 1.0),vec4(texcoord0,0,1),texture_matrix0,gl_ObjectPlaneS[0],gl_ObjectPlaneT[0]);
+	gl_TexCoord[1] = texture_matrix1*vec4(texcoord1,0,1);
+	gl_TexCoord[2] = texgen_object(vec4(position.xyz, 1.0),vec4(texcoord2,0,1),texture_matrix2,gl_ObjectPlaneS[2],gl_ObjectPlaneT[2]);
+	gl_TexCoord[3] = texture_matrix3*vec4(texcoord3,0,1);
 }
diff --git a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl
index 831a7de0ea1..99433ada7bd 100644
--- a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl
+++ b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 
@@ -46,7 +48,7 @@ float wave(vec2 v, float t, float f, vec2 d, float s)
 void main()
 {
 	//transform vertex
-	mat4 modelViewProj = gl_ModelViewProjectionMatrix;
+	mat4 modelViewProj = modelview_projection_matrix;
 	
 	vec4 oPosition;
 		    
@@ -77,7 +79,7 @@ void main()
 	vec4 pos;
 	pos.xyz = oEyeVec.xyz*(waterHeight/oEyeVec.z);
 	pos.w = 1.0;
-	pos = gl_ModelViewMatrix*pos;
+	pos = modelview_matrix*pos;
 	
 	calcAtmospherics(pos.xyz);
 	
diff --git a/indra/newview/app_settings/shaders/class1/interface/customalphaV.glsl b/indra/newview/app_settings/shaders/class1/interface/customalphaV.glsl
index df67f76ad5e..5bbc7deff03 100644
--- a/indra/newview/app_settings/shaders/class1/interface/customalphaV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/customalphaV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec4 diffuse_color;
 attribute vec2 texcoord0;
@@ -30,7 +32,7 @@ attribute vec2 texcoord0;
 
 void main()
 {
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
 	gl_FrontColor = diffuse_color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/interface/debugV.glsl b/indra/newview/app_settings/shaders/class1/interface/debugV.glsl
index 2f64fdb7bc6..cd3d090e52a 100644
--- a/indra/newview/app_settings/shaders/class1/interface/debugV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/debugV.glsl
@@ -23,10 +23,12 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 void main()
 {
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAV.glsl b/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAV.glsl
index f54876135e9..bd5dd6046b0 100644
--- a/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAV.glsl
@@ -1,17 +1,37 @@
 /** 
  * @file glowcombineFXAAV.glsl
  *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 varying vec2 vary_tc;
 
 void main()
 {
-	vec4 pos = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix*vec4(position.xyz, 1.0);
 	gl_Position = pos;
 
 	vary_tc = pos.xy*0.5+0.5;
diff --git a/indra/newview/app_settings/shaders/class1/interface/glowcombineV.glsl b/indra/newview/app_settings/shaders/class1/interface/glowcombineV.glsl
index 303535ee310..94edbe5ab14 100644
--- a/indra/newview/app_settings/shaders/class1/interface/glowcombineV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/glowcombineV.glsl
@@ -22,14 +22,16 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec2 texcoord0;
 attribute vec2 texcoord1;
 
 void main()
 {
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
 	gl_TexCoord[1] = vec4(texcoord1,0,1);
 }
diff --git a/indra/newview/app_settings/shaders/class1/interface/highlightV.glsl b/indra/newview/app_settings/shaders/class1/interface/highlightV.glsl
index 1d312313a84..6bb5affd931 100644
--- a/indra/newview/app_settings/shaders/class1/interface/highlightV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/highlightV.glsl
@@ -22,14 +22,17 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec2 texcoord0;
 
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/interface/occlusionV.glsl b/indra/newview/app_settings/shaders/class1/interface/occlusionV.glsl
index 62fe4a2ce5b..43dcd5dbe26 100644
--- a/indra/newview/app_settings/shaders/class1/interface/occlusionV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/occlusionV.glsl
@@ -23,10 +23,12 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 void main()
 {
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/interface/onetexturenocolorV.glsl b/indra/newview/app_settings/shaders/class1/interface/onetexturenocolorV.glsl
index 7df45e90e60..615412c7a2e 100644
--- a/indra/newview/app_settings/shaders/class1/interface/onetexturenocolorV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/onetexturenocolorV.glsl
@@ -2,9 +2,28 @@
  * @file onetexturenocolorV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
  
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec2 texcoord0;
@@ -12,7 +31,7 @@ attribute vec2 texcoord0;
 
 void main()
 {
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1);
+	gl_Position = modelview_projection_matrix * vec4(position, 1);
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/interface/solidcolorV.glsl b/indra/newview/app_settings/shaders/class1/interface/solidcolorV.glsl
index be03d19290a..45e6a9febce 100644
--- a/indra/newview/app_settings/shaders/class1/interface/solidcolorV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/solidcolorV.glsl
@@ -22,6 +22,8 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
+
+uniform mat4 modelview_projection_matrix;
  
 attribute vec3 position;
 attribute vec4 diffuse_color;
@@ -29,7 +31,7 @@ attribute vec2 texcoord0;
 
 void main()
 {
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_FrontColor = diffuse_color;
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
 }
diff --git a/indra/newview/app_settings/shaders/class1/interface/splattexturerectV.glsl b/indra/newview/app_settings/shaders/class1/interface/splattexturerectV.glsl
index 085970f549e..2b471d99e82 100644
--- a/indra/newview/app_settings/shaders/class1/interface/splattexturerectV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/splattexturerectV.glsl
@@ -22,14 +22,16 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec2 texcoord0;
 attribute vec4 diffuse_color;
 
 void main()
 {
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
 	gl_FrontColor = diffuse_color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/interface/twotextureaddV.glsl b/indra/newview/app_settings/shaders/class1/interface/twotextureaddV.glsl
index 80c57e77661..2a36feaa211 100644
--- a/indra/newview/app_settings/shaders/class1/interface/twotextureaddV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/twotextureaddV.glsl
@@ -23,6 +23,7 @@
  * $/LicenseInfo$
  */
  
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec2 texcoord0;
@@ -30,7 +31,7 @@ attribute vec2 texcoord1;
 
 void main()
 {
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
 	gl_TexCoord[1] = vec4(texcoord1,0,1);
 }
diff --git a/indra/newview/app_settings/shaders/class1/interface/uiV.glsl b/indra/newview/app_settings/shaders/class1/interface/uiV.glsl
index faef21689e9..a9e42a432f0 100644
--- a/indra/newview/app_settings/shaders/class1/interface/uiV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/uiV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec4 diffuse_color;
@@ -31,8 +33,8 @@ attribute vec2 texcoord0;
 
 void main()
 {
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1);
-	gl_TexCoord[0] =  gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_Position = modelview_projection_matrix * vec4(position, 1);
+	gl_TexCoord[0] =  texture_matrix0 * vec4(texcoord0,0,1);
 	gl_FrontColor = diffuse_color;
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/objects/bumpV.glsl b/indra/newview/app_settings/shaders/class1/objects/bumpV.glsl
index 7d38e07d65b..dccc6925930 100644
--- a/indra/newview/app_settings/shaders/class1/objects/bumpV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/bumpV.glsl
@@ -22,7 +22,10 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 texture_matrix1;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec2 texcoord0;
@@ -31,7 +34,7 @@ attribute vec2 texcoord1;
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
-	gl_TexCoord[1] = gl_TextureMatrix[1] * vec4(texcoord1,0,1);
+	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
+	gl_TexCoord[1] = texture_matrix1 * vec4(texcoord1,0,1);
 }
diff --git a/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl
index 78668711ac2..e2a00e84407 100644
--- a/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl
@@ -1,10 +1,31 @@
 /** 
  * @file emissiveSkinnedV.glsl
  *
- * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
- * $License$
+ * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
+ * $/LicenseInfo$
  */
 
+uniform mat4 projection_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
 
 attribute vec3 position;
 attribute float emissive;
@@ -16,18 +37,18 @@ mat4 getObjectSkinnedTransform();
 void main()
 {
 	//transform vertex
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	mat4 mat = getObjectSkinnedTransform();
 	
-	mat = gl_ModelViewMatrix * mat;
+	mat = modelview_matrix * mat;
 	vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz;
 	
 	calcAtmospherics(pos.xyz);
 
 	gl_FrontColor = vec4(0,0,0,emissive);
 	
-	gl_Position = gl_ProjectionMatrix*vec4(pos, 1.0);
+	gl_Position = projection_matrix*vec4(pos, 1.0);
 		
 	gl_FogFragCoord = pos.z;
 }
diff --git a/indra/newview/app_settings/shaders/class1/objects/emissiveV.glsl b/indra/newview/app_settings/shaders/class1/objects/emissiveV.glsl
index 05d7cc397fd..dedf00f3743 100644
--- a/indra/newview/app_settings/shaders/class1/objects/emissiveV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/emissiveV.glsl
@@ -1,10 +1,32 @@
 /**
  * @file emissiveV.glsl
  *
- * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec4 position;
 attribute float emissive;
 attribute vec2 texcoord0;
@@ -17,10 +39,10 @@ void main()
 {
 	//transform vertex
 	vary_texture_index = position.w;
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
-	vec4 pos = (gl_ModelViewMatrix * vec4(position.xyz, 1.0));
+	vec4 pos = (modelview_matrix * vec4(position.xyz, 1.0));
 	calcAtmospherics(pos.xyz);
 
 	gl_FrontColor = vec4(0,0,0,emissive);
diff --git a/indra/newview/app_settings/shaders/class1/objects/fullbrightNoColorV.glsl b/indra/newview/app_settings/shaders/class1/objects/fullbrightNoColorV.glsl
index 57d98038e09..b9c1078c309 100644
--- a/indra/newview/app_settings/shaders/class1/objects/fullbrightNoColorV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/fullbrightNoColorV.glsl
@@ -2,9 +2,31 @@
  * @file fullbrightNoColorV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
-  
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec2 texcoord0;
 attribute vec3 normal;
@@ -15,9 +37,9 @@ void main()
 {
 	//transform vertex
 	vec4 vert = vec4(position.xyz,1.0);
-	vec4 pos = (gl_ModelViewMatrix * vert);
-	gl_Position = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	vec4 pos = (modelview_matrix * vert);
+	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 
 	calcAtmospherics(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl
index ebbcb2f719d..546b7cad4af 100644
--- a/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/fullbrightShinySkinnedV.glsl
@@ -22,6 +22,10 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 texture_matrix0;
+uniform mat4 texture_matrix1;
+uniform mat4 modelview_matrix;
+uniform mat4 projection_matrix;
 
 attribute vec3 position;
 attribute vec3 normal;
@@ -35,7 +39,7 @@ void main()
 {
 	mat4 mat = getObjectSkinnedTransform();
 	
-	mat = gl_ModelViewMatrix * mat;
+	mat = modelview_matrix * mat;
 	vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz;
 	
 	vec4 norm = vec4(position.xyz, 1.0);
@@ -45,14 +49,14 @@ void main()
 		
 	vec3 ref = reflect(pos.xyz, -norm.xyz);
 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
-	gl_TexCoord[1] = gl_TextureMatrix[1]*vec4(ref,1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
+	gl_TexCoord[1] = texture_matrix1*vec4(ref,1.0);
 
 	calcAtmospherics(pos.xyz);
 
 	gl_FrontColor = diffuse_color;
 	
-	gl_Position = gl_ProjectionMatrix*vec4(pos, 1.0);
+	gl_Position = projection_matrix*vec4(pos, 1.0);
 	
 	gl_FogFragCoord = pos.z;
 }
diff --git a/indra/newview/app_settings/shaders/class1/objects/fullbrightShinyV.glsl b/indra/newview/app_settings/shaders/class1/objects/fullbrightShinyV.glsl
index e8126daee04..a9b086e215e 100644
--- a/indra/newview/app_settings/shaders/class1/objects/fullbrightShinyV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/fullbrightShinyV.glsl
@@ -22,7 +22,12 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 texture_matrix1;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec4 diffuse_color;
@@ -36,15 +41,15 @@ uniform vec4 origin;
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 	vec3 ref = reflect(pos.xyz, -norm);
 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
-	gl_TexCoord[1] = gl_TextureMatrix[1]*vec4(ref,1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
+	gl_TexCoord[1] = texture_matrix1*vec4(ref,1.0);
 
-	vec4 pos = (gl_ModelViewMatrix * vec4(position.xyz, 1.0));
+	vec4 pos = (modelview_matrix * vec4(position.xyz, 1.0));
 	calcAtmospherics(pos.xyz);
 
 	gl_FrontColor = diffuse_color;
diff --git a/indra/newview/app_settings/shaders/class1/objects/fullbrightSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/fullbrightSkinnedV.glsl
index 276f423eea9..f0722a1e4d8 100644
--- a/indra/newview/app_settings/shaders/class1/objects/fullbrightSkinnedV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/fullbrightSkinnedV.glsl
@@ -22,6 +22,9 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 projection_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
 
 attribute vec3 position;
 attribute vec4 diffuse_color;
@@ -33,18 +36,18 @@ mat4 getObjectSkinnedTransform();
 void main()
 {
 	//transform vertex
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	mat4 mat = getObjectSkinnedTransform();
 	
-	mat = gl_ModelViewMatrix * mat;
+	mat = modelview_matrix * mat;
 	vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz;
 	
 	calcAtmospherics(pos.xyz);
 
 	gl_FrontColor = diffuse_color;
 	
-	gl_Position = gl_ProjectionMatrix*vec4(pos, 1.0);
+	gl_Position = projection_matrix*vec4(pos, 1.0);
 		
 	gl_FogFragCoord = pos.z;
 }
diff --git a/indra/newview/app_settings/shaders/class1/objects/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/objects/fullbrightV.glsl
index 159e34f0448..d8f223d403f 100644
--- a/indra/newview/app_settings/shaders/class1/objects/fullbrightV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/fullbrightV.glsl
@@ -22,7 +22,11 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec4 diffuse_color;
 attribute vec2 texcoord0;
@@ -32,9 +36,9 @@ void calcAtmospherics(vec3 inPositionEye);
 void main()
 {
 	//transform vertex
-	vec4 pos = (gl_ModelViewMatrix * vec4(position.xyz, 1.0));
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	vec4 pos = (modelview_matrix * vec4(position.xyz, 1.0));
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 
 
diff --git a/indra/newview/app_settings/shaders/class1/objects/impostorV.glsl b/indra/newview/app_settings/shaders/class1/objects/impostorV.glsl
index f175e3e76d8..69007610c6e 100644
--- a/indra/newview/app_settings/shaders/class1/objects/impostorV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/impostorV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_projection_matrix;
 
 
 attribute vec3 position;
@@ -31,6 +33,6 @@ attribute vec2 texcoord0;
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0, 0, 1);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0, 0, 1);
 }
diff --git a/indra/newview/app_settings/shaders/class1/objects/previewV.glsl b/indra/newview/app_settings/shaders/class1/objects/previewV.glsl
index 555c59c37ec..3771c2e795d 100644
--- a/indra/newview/app_settings/shaders/class1/objects/previewV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/previewV.glsl
@@ -2,9 +2,32 @@
  * @file previewV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec2 texcoord0;
@@ -15,11 +38,11 @@ void calcAtmospherics(vec3 inPositionEye);
 void main()
 {
 	//transform vertex
-	vec4 pos = (gl_ModelViewMatrix * vec4(position.xyz, 1.0));
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	vec4 pos = (modelview_matrix * vec4(position.xyz, 1.0));
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 		
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 
 	calcAtmospherics(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl
index f0bea5f3e7d..7e5c8ca2d59 100644
--- a/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/shinySimpleSkinnedV.glsl
@@ -22,6 +22,11 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 projection_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 texture_matrix1;
+uniform mat4 modelview_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec4 diffuse_color;
@@ -35,7 +40,7 @@ void main()
 {
 	mat4 mat = getObjectSkinnedTransform();
 	
-	mat = gl_ModelViewMatrix * mat;
+	mat = modelview_matrix * mat;
 	vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz;
 	
 	vec4 norm = vec4(position.xyz, 1.0);
@@ -45,13 +50,13 @@ void main()
 		
 	vec3 ref = reflect(pos.xyz, -norm.xyz);
 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
-	gl_TexCoord[1] = gl_TextureMatrix[1]*vec4(ref,1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
+	gl_TexCoord[1] = texture_matrix1*vec4(ref,1.0);
 
 	calcAtmospherics(pos.xyz);
 
 	vec4 color = calcLighting(pos.xyz, norm.xyz, diffuse_color, vec4(0.));
 	gl_FrontColor = color;
 	
-	gl_Position = gl_ProjectionMatrix*vec4(pos, 1.0);
+	gl_Position = projection_matrix*vec4(pos, 1.0);
 }
diff --git a/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl b/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl
index e8b6b71b3d5..da47f8a58aa 100644
--- a/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl
@@ -22,7 +22,12 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec4 diffuse_color;
@@ -35,10 +40,10 @@ uniform vec4 origin;
 void main()
 {
 	//transform vertex
-	vec4 pos = (gl_ModelViewMatrix * vec4(position.xyz, 1.0));
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = (modelview_matrix * vec4(position.xyz, 1.0));
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 
 	calcAtmospherics(pos.xyz);
 	
@@ -46,7 +51,7 @@ void main()
 	
 	vec3 ref = reflect(pos.xyz, -norm);
 	
-	gl_TexCoord[0] = gl_TextureMatrix[0]*vec4(ref,1.0);
+	gl_TexCoord[0] = texture_matrix0*vec4(ref,1.0);
 	
 	gl_FogFragCoord = pos.z;
 }
diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl
index 54c262885e5..d1d8126cb46 100644
--- a/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/simpleNoColorV.glsl
@@ -2,9 +2,32 @@
  * @file simpleNoColorV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec2 texcoord0;
@@ -15,11 +38,11 @@ void calcAtmospherics(vec3 inPositionEye);
 void main()
 {
 	//transform vertex
-	vec4 pos = (gl_ModelViewMatrix * vec4(position.xyz, 1.0));
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	vec4 pos = (modelview_matrix * vec4(position.xyz, 1.0));
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 		
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 
 	calcAtmospherics(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl
index 14c4a3aa8d9..bf083a55c47 100644
--- a/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/simpleSkinnedV.glsl
@@ -22,6 +22,10 @@
  * $/LicenseInfo$
  */
 
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 projection_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec4 diffuse_color;
@@ -34,11 +38,11 @@ mat4 getObjectSkinnedTransform();
 void main()
 {
 	//transform vertex
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	mat4 mat = getObjectSkinnedTransform();
 	
-	mat = gl_ModelViewMatrix * mat;
+	mat = modelview_matrix * mat;
 	vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz;
 	
 	vec4 norm = vec4(position.xyz, 1.0);
@@ -51,7 +55,7 @@ void main()
 	vec4 color = calcLighting(pos.xyz, norm.xyz, diffuse_color, vec4(0.));
 	gl_FrontColor = color;
 	
-	gl_Position = gl_ProjectionMatrix*vec4(pos, 1.0);
+	gl_Position = projection_matrix*vec4(pos, 1.0);
 	
 	gl_FogFragCoord = pos.z;
 }
diff --git a/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl b/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl
index bbc170b1af4..87ece3972ee 100644
--- a/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/simpleV.glsl
@@ -22,7 +22,12 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec4 diffuse_color;
@@ -34,11 +39,11 @@ void calcAtmospherics(vec3 inPositionEye);
 void main()
 {
 	//transform vertex
-	vec4 pos = (gl_ModelViewMatrix * vec4(position.xyz, 1.0));
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	vec4 pos = (modelview_matrix * vec4(position.xyz, 1.0));
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 		
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 
 	calcAtmospherics(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class1/objects/treeV.glsl b/indra/newview/app_settings/shaders/class1/objects/treeV.glsl
index 1e9e7f4b0b3..64ca63731b1 100644
--- a/indra/newview/app_settings/shaders/class1/objects/treeV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/treeV.glsl
@@ -2,10 +2,31 @@
  * @file treeV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
 
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec2 texcoord0;
@@ -19,12 +40,12 @@ void main()
 	//transform vertex
 	vec4 vert = vec4(position.xyz,1.0);
 	
-	gl_Position = gl_ModelViewProjectionMatrix*vert;
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0, 0, 1);
+	gl_Position = modelview_projection_matrix*vert;
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0, 0, 1);
 	
-	vec4 pos = (gl_ModelViewMatrix * vert);
+	vec4 pos = (modelview_matrix * vert);
 	
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 
 	calcAtmospherics(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl b/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl
index c0065f0bbe8..43e19909d4e 100644
--- a/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl
+++ b/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl
@@ -22,7 +22,11 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec4 diffuse_color;
@@ -35,11 +39,11 @@ void calcAtmospherics(vec3 inPositionEye);
 void main()
 {
 	//transform vertex
-	vec3 pos = (gl_ModelViewMatrix * vec4(position.xyz, 1.0)).xyz;
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	vec3 pos = (modelview_matrix * vec4(position.xyz, 1.0)).xyz;
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 		
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 
 	calcAtmospherics(pos.xyz);
 	
diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaSkinnedV.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaSkinnedV.glsl
index 501fcb004b1..df4d26997ac 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/alphaSkinnedV.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/alphaSkinnedV.glsl
@@ -21,6 +21,11 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
+
+uniform mat4 projection_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
  
 attribute vec3 position;
 attribute vec3 normal;
@@ -79,15 +84,15 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa
 
 void main()
 {
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	mat4 mat = getObjectSkinnedTransform();
 	
-	mat = gl_ModelViewMatrix * mat;
+	mat = modelview_matrix * mat;
 	
 	vec3 pos = (mat*vec4(position, 1.0)).xyz;
 	
-	gl_Position = gl_ProjectionMatrix * vec4(pos, 1.0);
+	gl_Position = projection_matrix * vec4(pos, 1.0);
 	
 	vec4 n = vec4(position, 1.0);
 	n.xyz += normal.xyz;
@@ -128,7 +133,7 @@ void main()
 
 	gl_FogFragCoord = pos.z;
 	
-	pos.xyz = (gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0)).xyz;
+	pos.xyz = (modelview_projection_matrix * vec4(position.xyz, 1.0)).xyz;
 	vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip);
 	
 }
diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl
index b0ae0107fb2..996203ffd62 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl
@@ -22,7 +22,12 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
+
 attribute vec4 position;
 attribute vec3 normal;
 attribute vec4 diffuse_color;
@@ -84,12 +89,12 @@ void main()
 	//transform vertex
 	vec4 vert = vec4(position.xyz, 1.0);
 	vary_texture_index = position.w;
-	vec4 pos = (gl_ModelViewMatrix * vert);
-	gl_Position = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
+	vec4 pos = (modelview_matrix * vert);
+	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
 	
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 		
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 	
 	float dp_directional_light = max(0.0, dot(norm, gl_LightSource[0].position.xyz));
 	vary_position = pos.xyz + gl_LightSource[0].position.xyz * (1.0-dp_directional_light)*shadow_offset;
@@ -123,7 +128,7 @@ void main()
 
 	gl_FogFragCoord = pos.z;
 	
-	pos = gl_ModelViewProjectionMatrix * vert;
+	pos = modelview_projection_matrix * vert;
 	vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip);
 	
 }
diff --git a/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaV.glsl b/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaV.glsl
index f35af53f952..3e356757844 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaV.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaV.glsl
@@ -23,6 +23,7 @@
  * $/LicenseInfo$
  */
  
+uniform mat4 projection_matrix;
 
 attribute vec3 position;
 attribute vec3 normal;
@@ -99,7 +100,7 @@ void main()
 	norm.z = dot(trans[2].xyz, normal);
 	norm = normalize(norm);
 		
-	gl_Position = gl_ProjectionMatrix * pos;
+	gl_Position = projection_matrix * pos;
 	
 	float dp_directional_light = max(0.0, dot(norm, gl_LightSource[0].position.xyz));
 	vary_position = pos.xyz + gl_LightSource[0].position.xyz * (1.0-dp_directional_light)*shadow_offset;
diff --git a/indra/newview/app_settings/shaders/class2/deferred/edgeV.glsl b/indra/newview/app_settings/shaders/class2/deferred/edgeV.glsl
index 964f12afcfd..1f5470db3c3 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/edgeV.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/edgeV.glsl
@@ -23,6 +23,7 @@
  * $/LicenseInfo$
  */
  
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 
@@ -32,7 +33,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
 	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
 }
diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl
index e52edcba412..424299269fd 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl
@@ -22,7 +22,8 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 
@@ -33,7 +34,7 @@ varying vec2 vary_fragcoord;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
 	
 	
diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl
index 2cf7375d4d2..60ba2d7ad4d 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 varying vec2 vary_fragcoord;
@@ -32,7 +34,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
 	
 	vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res;	
diff --git a/indra/newview/app_settings/shaders/class2/effects/blurV.glsl b/indra/newview/app_settings/shaders/class2/effects/blurV.glsl
index 556e131d348..4fd4b101ff7 100644
--- a/indra/newview/app_settings/shaders/class2/effects/blurV.glsl
+++ b/indra/newview/app_settings/shaders/class2/effects/blurV.glsl
@@ -22,7 +22,8 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec2 texcoord0;
@@ -34,7 +35,7 @@ uniform float blurWidth;
 void main(void)
 {
 	// Transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	
 	vec2 blurDelta = texelSize * blurDirection * vec2(blurWidth, blurWidth);
 	vec2 s = vec4(texcoord0,0,1).st - (blurDelta * 3.0);
diff --git a/indra/newview/app_settings/shaders/class2/effects/drawQuadV.glsl b/indra/newview/app_settings/shaders/class2/effects/drawQuadV.glsl
index fbb87b65787..d3c93ab05f1 100644
--- a/indra/newview/app_settings/shaders/class2/effects/drawQuadV.glsl
+++ b/indra/newview/app_settings/shaders/class2/effects/drawQuadV.glsl
@@ -22,7 +22,8 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec2 texcoord0;
@@ -32,7 +33,7 @@ attribute vec2 texcoord1;
 void main(void)
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
 	gl_TexCoord[1] = vec4(texcoord1,0,1);
 }
diff --git a/indra/newview/app_settings/shaders/class2/environment/terrainV.glsl b/indra/newview/app_settings/shaders/class2/environment/terrainV.glsl
index 1a7edbd61b8..69f4d4ae458 100644
--- a/indra/newview/app_settings/shaders/class2/environment/terrainV.glsl
+++ b/indra/newview/app_settings/shaders/class2/environment/terrainV.glsl
@@ -22,7 +22,11 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec3 normal;
@@ -52,10 +56,10 @@ vec4 texgen_object(vec4  vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1)
 void main()
 {
 	//transform vertex
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 
-	vec4 pos = gl_ModelViewMatrix * vec4(position.xyz, 1.0);
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec4 pos = modelview_matrix * vec4(position.xyz, 1.0);
+	vec3 norm = normalize(normal_matrix * normal);
 
 	calcAtmospherics(pos.xyz);
 
@@ -67,7 +71,7 @@ void main()
 	gl_FrontColor = color;
 
 	// Transform and pass tex coords
- 	gl_TexCoord[0].xy = texgen_object(vec4(position.xyz, 1.0), vec4(texcoord0,0,1), gl_TextureMatrix[0], gl_ObjectPlaneS[0], gl_ObjectPlaneT[0]).xy;
+ 	gl_TexCoord[0].xy = texgen_object(vec4(position.xyz, 1.0), vec4(texcoord0,0,1), texture_matrix0, gl_ObjectPlaneS[0], gl_ObjectPlaneT[0]).xy;
 	
 	vec4 t = vec4(texcoord1,0,1);
 	
diff --git a/indra/newview/app_settings/shaders/class2/objects/fullbrightShinyV.glsl b/indra/newview/app_settings/shaders/class2/objects/fullbrightShinyV.glsl
index 8a889576591..b9eff87a13b 100644
--- a/indra/newview/app_settings/shaders/class2/objects/fullbrightShinyV.glsl
+++ b/indra/newview/app_settings/shaders/class2/objects/fullbrightShinyV.glsl
@@ -22,7 +22,12 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 texture_matrix1;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 
 void calcAtmospherics(vec3 inPositionEye);
@@ -41,14 +46,14 @@ void main()
 	//transform vertex
 	vec4 vert = vec4(position.xyz,1.0);
 	vary_texture_index = position.w;
-	vec4 pos = (gl_ModelViewMatrix * vert);
-	gl_Position = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
+	vec4 pos = (modelview_matrix * vert);
+	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
 	
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 	vec3 ref = reflect(pos.xyz, -norm);
 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
-	gl_TexCoord[1] = gl_TextureMatrix[1]*vec4(ref,1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
+	gl_TexCoord[1] = texture_matrix1*vec4(ref,1.0);
 
 	calcAtmospherics(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class2/objects/fullbrightV.glsl b/indra/newview/app_settings/shaders/class2/objects/fullbrightV.glsl
index f5ff1d1d008..b7f7af7885b 100644
--- a/indra/newview/app_settings/shaders/class2/objects/fullbrightV.glsl
+++ b/indra/newview/app_settings/shaders/class2/objects/fullbrightV.glsl
@@ -22,7 +22,10 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
  
 attribute vec4 position;
 attribute vec2 texcoord0;
@@ -39,9 +42,9 @@ void main()
 	//transform vertex
 	vec4 vert = vec4(position.xyz,1.0);
 	vary_texture_index = position.w;
-	vec4 pos = (gl_ModelViewMatrix * vert);
-	gl_Position = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
+	vec4 pos = (modelview_matrix * vert);
+	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
 	
 	calcAtmospherics(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class2/objects/shinyV.glsl b/indra/newview/app_settings/shaders/class2/objects/shinyV.glsl
index d6fca4cda71..4511c4bc91d 100644
--- a/indra/newview/app_settings/shaders/class2/objects/shinyV.glsl
+++ b/indra/newview/app_settings/shaders/class2/objects/shinyV.glsl
@@ -22,7 +22,12 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 texture_matrix1;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec4 position;
 attribute vec2 texcoord0;
@@ -42,14 +47,14 @@ void main()
 	//transform vertex
 	vec4 vert = vec4(position.xyz,1.0);
 	vary_texture_index = position.w;
-	vec4 pos = (gl_ModelViewMatrix * vert);
-	gl_Position = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
+	vec4 pos = (modelview_matrix * vert);
+	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
 		
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 	vec3 ref = reflect(pos.xyz, -norm);
 
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0,0,1);
-	gl_TexCoord[1] = gl_TextureMatrix[1]*vec4(ref,1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0,0,1);
+	gl_TexCoord[1] = texture_matrix1*vec4(ref,1.0);
 
 	calcAtmospherics(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class2/objects/simpleNonIndexedV.glsl b/indra/newview/app_settings/shaders/class2/objects/simpleNonIndexedV.glsl
index d2a83c97249..5f78495ae36 100644
--- a/indra/newview/app_settings/shaders/class2/objects/simpleNonIndexedV.glsl
+++ b/indra/newview/app_settings/shaders/class2/objects/simpleNonIndexedV.glsl
@@ -2,10 +2,31 @@
  * @file simpleNonIndexedV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
 
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec2 texcoord0;
@@ -20,12 +41,12 @@ void main()
 	//transform vertex
 	vec4 vert = vec4(position.xyz,1.0);
 	
-	gl_Position = gl_ModelViewProjectionMatrix*vert;
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0, 0, 1);
+	gl_Position = modelview_projection_matrix*vert;
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0, 0, 1);
 	
-	vec4 pos = (gl_ModelViewMatrix * vert);
+	vec4 pos = (modelview_matrix * vert);
 	
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 
 	calcAtmospherics(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class2/objects/simpleV.glsl b/indra/newview/app_settings/shaders/class2/objects/simpleV.glsl
index c2db1e19495..91ee5e016e0 100644
--- a/indra/newview/app_settings/shaders/class2/objects/simpleV.glsl
+++ b/indra/newview/app_settings/shaders/class2/objects/simpleV.glsl
@@ -22,8 +22,11 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
 
+uniform mat3 normal_matrix;
+uniform mat4 texture_matrix0;
+uniform mat4 modelview_matrix;
+uniform mat4 modelview_projection_matrix;
 
 attribute vec4 position;
 attribute vec2 texcoord0;
@@ -40,13 +43,13 @@ void main()
 	//transform vertex
 	vec4 vert = vec4(position.xyz,1.0);
 	vary_texture_index = position.w;
-	vec4 pos = (gl_ModelViewMatrix * vert);
-	gl_Position = gl_ModelViewProjectionMatrix*vec4(position.xyz, 1.0);
-	gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(texcoord0, 0, 1);
+	vec4 pos = (modelview_matrix * vert);
+	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
+	gl_TexCoord[0] = texture_matrix0 * vec4(texcoord0, 0, 1);
 	
 	
 	
-	vec3 norm = normalize(gl_NormalMatrix * normal);
+	vec3 norm = normalize(normal_matrix * normal);
 
 	calcAtmospherics(pos.xyz);
 
diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl
index 297b3904a60..67b5e7fb837 100644
--- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl
+++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec2 texcoord0;
 
@@ -60,7 +62,7 @@ void main()
 {
 
 	// World / view / projection
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
 
diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl
index 84e1f827d6c..50fdba64c25 100644
--- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl
+++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl
@@ -23,6 +23,7 @@
  * $/LicenseInfo$
  */
  
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec2 texcoord0;
@@ -59,7 +60,7 @@ void main()
 {
 
 	// World / view / projection
-	gl_Position = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_TexCoord[0] = vec4(texcoord0,0,1);
 
 	// Get relative position
diff --git a/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl b/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl
index f1d06b4fec8..c10635c898c 100644
--- a/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl
+++ b/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 projection_matrix;
+
 attribute vec3 position;
 attribute vec3 normal;
 attribute vec2 texcoord0;
@@ -123,7 +125,7 @@ void main()
 	vec4 color = calcLighting(pos.xyz, norm, vec4(1,1,1,1), vec4(0.0));			
 	gl_FrontColor = color; 
 					
-	gl_Position = gl_ProjectionMatrix * pos;
+	gl_Position = projection_matrix * pos;
 	
 	
 	gl_TexCoord[2] = vec4(pos.xyz, 1.0);
diff --git a/indra/newview/app_settings/shaders/class3/deferred/giDownsampleV.glsl b/indra/newview/app_settings/shaders/class3/deferred/giDownsampleV.glsl
index 870d4c36bcb..5e75aec171d 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/giDownsampleV.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/giDownsampleV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 varying vec2 vary_fragcoord;
@@ -31,7 +33,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 	
 	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
 }
diff --git a/indra/newview/app_settings/shaders/class3/deferred/giFinalV.glsl b/indra/newview/app_settings/shaders/class3/deferred/giFinalV.glsl
index 76206f88d9e..969b6e2f1c0 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/giFinalV.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/giFinalV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 
@@ -32,7 +34,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos;
 	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
 }
diff --git a/indra/newview/app_settings/shaders/class3/deferred/giV.glsl b/indra/newview/app_settings/shaders/class3/deferred/giV.glsl
index 1a23be349ee..2766691bd02 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/giV.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/giV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 attribute vec4 diffuse_color;
 attribute vec2 texcoord0;
@@ -35,7 +37,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
 	
 	vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res;	
diff --git a/indra/newview/app_settings/shaders/class3/deferred/luminanceV.glsl b/indra/newview/app_settings/shaders/class3/deferred/luminanceV.glsl
index a2606f2fb2d..d0205fa824c 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/luminanceV.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/luminanceV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 varying vec2 vary_fragcoord;
 
 uniform vec2 screen_res;
@@ -33,7 +35,7 @@ attribute vec4 diffuse_color;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
 	
 	vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res;	
diff --git a/indra/newview/app_settings/shaders/class3/deferred/postDeferredV.glsl b/indra/newview/app_settings/shaders/class3/deferred/postDeferredV.glsl
index 2d0b60d513b..2d7fa22edcb 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/postDeferredV.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/postDeferredV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 varying vec2 vary_fragcoord;
@@ -31,7 +33,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
 	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
 }
diff --git a/indra/newview/app_settings/shaders/class3/deferred/postgiV.glsl b/indra/newview/app_settings/shaders/class3/deferred/postgiV.glsl
index 25bdfdce453..e9c6f3e27b8 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/postgiV.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/postgiV.glsl
@@ -22,7 +22,9 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
+
 attribute vec3 position;
 
 varying vec2 vary_fragcoord;
@@ -31,7 +33,7 @@ uniform vec2 screen_res;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 
 	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
 }
diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl
index 9e07a4d219f..8e405de9a3d 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl
@@ -22,7 +22,8 @@
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
+uniform mat4 modelview_projection_matrix;
 
 attribute vec3 position;
 attribute vec2 texcoord0;
@@ -34,7 +35,7 @@ varying vec2 vary_fragcoord;
 void main()
 {
 	//transform vertex
-	vec4 pos = gl_ModelViewProjectionMatrix * vec4(position.xyz, 1.0);
+	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
 	gl_Position = pos; 	
 	
 	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp
index 917462c1ee7..7155311f8ef 100644
--- a/indra/newview/llviewershadermgr.cpp
+++ b/indra/newview/llviewershadermgr.cpp
@@ -380,7 +380,7 @@ void LLViewerShaderMgr::initAttribsAndUniforms(void)
 		mReservedUniforms.push_back("lastNormalGIMap");
 		mReservedUniforms.push_back("lastMinpGIMap");
 		mReservedUniforms.push_back("lastMaxpGIMap");
-					
+
 		mWLUniforms.push_back("camPosLocal");
 
 		mTerrainUniforms.reserve(5);
-- 
GitLab