(view as text)
diff --git a/Source/Core/DolphinWX/Src/Frame.cpp b/Source/Core/DolphinWX/Src/Frame.cpp
index 1ca16ff..9170758 100644
--- a/Source/Core/DolphinWX/Src/Frame.cpp
+++ b/Source/Core/DolphinWX/Src/Frame.cpp
@@ -32,7 +32,7 @@
 #include "Movie.h"
 #include "RenderBase.h"
 #include "VideoConfig.h"
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 
 #include "VideoBackendBase.h"
 
@@ -979,25 +979,25 @@ void CFrame::OnKeyDown(wxKeyEvent& event)
 				debugSpeed *= 2.0f;
 				break;
 			case 'W':
-				VertexShaderManager::TranslateView(0.0f, debugSpeed);
+				ConstantManager::TranslateView(0.0f, debugSpeed);
 				break;
 			case 'S':
-				VertexShaderManager::TranslateView(0.0f, -debugSpeed);
+				ConstantManager::TranslateView(0.0f, -debugSpeed);
 				break;
 			case 'A':
-				VertexShaderManager::TranslateView(debugSpeed, 0.0f);
+				ConstantManager::TranslateView(debugSpeed, 0.0f);
 				break;
 			case 'D':
-				VertexShaderManager::TranslateView(-debugSpeed, 0.0f);
+				ConstantManager::TranslateView(-debugSpeed, 0.0f);
 				break;
 			case 'Q':
-				VertexShaderManager::TranslateView(0.0f, 0.0f, debugSpeed);
+				ConstantManager::TranslateView(0.0f, 0.0f, debugSpeed);
 				break;
 			case 'E':
-				VertexShaderManager::TranslateView(0.0f, 0.0f, -debugSpeed);
+				ConstantManager::TranslateView(0.0f, 0.0f, -debugSpeed);
 				break;
 			case 'R':
-				VertexShaderManager::ResetView();
+				ConstantManager::ResetView();
 				break;
 			default:
 				break;
diff --git a/Source/Core/DolphinWX/Src/GLInterface/AGL.cpp b/Source/Core/DolphinWX/Src/GLInterface/AGL.cpp
index 1068e87..a54d6de 100644
--- a/Source/Core/DolphinWX/Src/GLInterface/AGL.cpp
+++ b/Source/Core/DolphinWX/Src/GLInterface/AGL.cpp
@@ -22,7 +22,6 @@
 
 #include <wx/panel.h>
 
-#include "VertexShaderManager.h"
 #include "../GLInterface.h"
 #include "AGL.h"
 
diff --git a/Source/Core/DolphinWX/Src/GLInterface/WGL.cpp b/Source/Core/DolphinWX/Src/GLInterface/WGL.cpp
index 62a4438..abdbacd 100644
--- a/Source/Core/DolphinWX/Src/GLInterface/WGL.cpp
+++ b/Source/Core/DolphinWX/Src/GLInterface/WGL.cpp
@@ -6,7 +6,6 @@
 #include "Host.h"
 #include "RenderBase.h"
 
-#include "VertexShaderManager.h"
 #include "../GLInterface.h"
 #include "WGL.h"
 
diff --git a/Source/Core/DolphinWX/Src/GLInterface/X11_Util.cpp b/Source/Core/DolphinWX/Src/GLInterface/X11_Util.cpp
index e57c095..f3473cd 100644
--- a/Source/Core/DolphinWX/Src/GLInterface/X11_Util.cpp
+++ b/Source/Core/DolphinWX/Src/GLInterface/X11_Util.cpp
@@ -18,7 +18,7 @@
 #include "Host.h"
 #include "VideoConfig.h"
 #include "../GLInterface.h"
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 
 #if USE_EGL
 bool cXInterface::ServerConnect(void)
@@ -214,7 +214,7 @@ void cX11Window::XEventThread()
 					{
 						if (mouseLookEnabled)
 						{
-							VertexShaderManager::RotateView((event.xmotion.x - lastMouse[0]) / 200.0f,
+							ConstantManager::RotateView((event.xmotion.x - lastMouse[0]) / 200.0f,
 									(event.xmotion.y - lastMouse[1]) / 200.0f);
 							lastMouse[0] = event.xmotion.x;
 							lastMouse[1] = event.xmotion.y;
@@ -222,7 +222,7 @@ void cX11Window::XEventThread()
 
 						if (mouseMoveEnabled)
 						{
-							VertexShaderManager::TranslateView((event.xmotion.x - lastMouse[0]) / 50.0f,
+							ConstantManager::TranslateView((event.xmotion.x - lastMouse[0]) / 50.0f,
 									(event.xmotion.y - lastMouse[1]) / 50.0f);
 							lastMouse[0] = event.xmotion.x;
 							lastMouse[1] = event.xmotion.y;
diff --git a/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp b/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp
index d8716c8..7b5c461 100644
--- a/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp
+++ b/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp
@@ -14,7 +14,7 @@
 #include "Globals.h"
 #include "PixelShaderGen.h"
 #include "PixelShaderCache.h"
-#include "PixelShaderManager.h"
+#include "ConstantManager.h"
 
 #include "ConfigManager.h"
 
@@ -336,15 +336,15 @@ ID3D11PixelShader* PixelShaderCache::GetClearProgram()
 ID3D11Buffer* &PixelShaderCache::GetConstantBuffer()
 {
 	// TODO: divide the global variables of the generated shaders into about 5 constant buffers to speed this up
-	if (PixelShaderManager::dirty)
+	if (ConstantManager::dirty)
 	{
 		D3D11_MAPPED_SUBRESOURCE map;
 		D3D::context->Map(pscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
-		memcpy(map.pData, &PixelShaderManager::constants, sizeof(PixelShaderConstants));
+		memcpy(map.pData, &ConstantManager::constants, sizeof(Constants));
 		D3D::context->Unmap(pscbuf, 0);
-		PixelShaderManager::dirty = false;
+		ConstantManager::dirty = false;
 
-		ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(PixelShaderConstants));
+		ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(Constants));
 	}
 	return pscbuf;
 }
diff --git a/Source/Core/VideoBackends/D3D/Src/Render.cpp b/Source/Core/VideoBackends/D3D/Src/Render.cpp
index 9790f2b..3531482 100644
--- a/Source/Core/VideoBackends/D3D/Src/Render.cpp
+++ b/Source/Core/VideoBackends/D3D/Src/Render.cpp
@@ -13,7 +13,7 @@
 #include "OnScreenDisplay.h"
 #include "PixelEngine.h"
 #include "Statistics.h"
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 #include "VideoConfig.h"
 
 #include "D3DBase.h"
@@ -478,7 +478,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
 }
 
 
-// Called from VertexShaderManager
+// Called from ConstantManager
 void Renderer::UpdateViewport()
 {
 	// reversed gxsetviewport(xorig, yorig, width, height, nearz, farz)
diff --git a/Source/Core/VideoBackends/D3D/Src/VertexManager.cpp b/Source/Core/VideoBackends/D3D/Src/VertexManager.cpp
index a48a3d2..460bb1c 100644
--- a/Source/Core/VideoBackends/D3D/Src/VertexManager.cpp
+++ b/Source/Core/VideoBackends/D3D/Src/VertexManager.cpp
@@ -11,12 +11,11 @@
 #include "Debugger.h"
 #include "IndexGenerator.h"
 #include "MainBase.h"
-#include "PixelShaderManager.h"
+#include "ConstantManager.h"
 #include "RenderBase.h"
 #include "Render.h"
 #include "Statistics.h"
 #include "TextureCacheBase.h"
-#include "VertexShaderManager.h"
 #include "VideoConfig.h"
 
 // internal state for loading vertices
@@ -229,7 +228,7 @@ void VertexManager::vFlush()
 			if (tentry)
 			{
 				// 0s are probably for no manual wrapping needed.
-				PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
+				ConstantManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
 			}
 			else
 				ERROR_LOG(VIDEO, "error loading texture");
@@ -237,8 +236,7 @@ void VertexManager::vFlush()
 	}
 
 	// set global constants
-	VertexShaderManager::SetConstants();
-	PixelShaderManager::SetConstants(g_nativeVertexFmt->m_components);
+	ConstantManager::SetConstants(g_nativeVertexFmt->m_components);
 
 	bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate &&
 		bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
diff --git a/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp b/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp
index e17f273..bfff549 100644
--- a/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp
+++ b/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp
@@ -12,7 +12,7 @@
 #include "D3DShader.h"
 #include "Globals.h"
 #include "VertexShaderCache.h"
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 
 #include "ConfigManager.h"
 
@@ -40,15 +40,15 @@ ID3D11Buffer* vscbuf = NULL;
 ID3D11Buffer* &VertexShaderCache::GetConstantBuffer()
 {
 	// TODO: divide the global variables of the generated shaders into about 5 constant buffers to speed this up
-	if (VertexShaderManager::dirty)
+	if (ConstantManager::dirty)
 	{
 		D3D11_MAPPED_SUBRESOURCE map;
 		D3D::context->Map(vscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
-		memcpy(map.pData, &VertexShaderManager::constants, sizeof(VertexShaderConstants));
+		memcpy(map.pData, &ConstantManager::constants, sizeof(Constants));
 		D3D::context->Unmap(vscbuf, 0);
-		VertexShaderManager::dirty = false;
+		ConstantManager::dirty = false;
 
-		ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(VertexShaderConstants));
+		ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(Constants));
 	}
 	return vscbuf;
 }
diff --git a/Source/Core/VideoBackends/D3D/Src/main.cpp b/Source/Core/VideoBackends/D3D/Src/main.cpp
index 0514106..82ab941 100644
--- a/Source/Core/VideoBackends/D3D/Src/main.cpp
+++ b/Source/Core/VideoBackends/D3D/Src/main.cpp
@@ -12,10 +12,9 @@
 #include "OnScreenDisplay.h"
 #include "OpcodeDecoding.h"
 #include "PixelEngine.h"
-#include "PixelShaderManager.h"
+#include "ConstantManager.h"
 #include "VideoConfig.h"
 #include "VertexLoaderManager.h"
-#include "VertexShaderManager.h"
 #include "Core.h"
 #include "Host.h"
 
@@ -197,8 +196,7 @@ void VideoBackend::Video_Prepare()
 	IndexGenerator::Init();
 	VertexLoaderManager::Init();
 	OpcodeDecoder_Init();
-	VertexShaderManager::Init();
-	PixelShaderManager::Init();
+	ConstantManager::Init();
 	CommandProcessor::Init();
 	PixelEngine::Init();
 	DLCache::Init();
@@ -222,8 +220,7 @@ void VideoBackend::Shutdown()
 		DLCache::Shutdown();
 		Fifo_Shutdown();
 		CommandProcessor::Shutdown();
-		PixelShaderManager::Shutdown();
-		VertexShaderManager::Shutdown();
+		ConstantManager::Shutdown();
 		OpcodeDecoder_Shutdown();
 		VertexLoaderManager::Shutdown();
 
diff --git a/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp
index cc807b7..a5f27c6 100644
--- a/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp
+++ b/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.cpp
@@ -10,8 +10,7 @@
 #include "Statistics.h"
 #include "ImageWrite.h"
 #include "Render.h"
-#include "PixelShaderManager.h"
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 
 namespace OGL
 {
@@ -49,8 +48,6 @@ const char *UniformNames[NUM_UNIFORMS] =
 	I_INDTEXSCALE ,
 	I_INDTEXMTX,
 	I_FOG,
-	I_PLIGHTS,
-	I_PMATERIALS,
 	// VERTEX SHADER UNIFORMS
 	I_POSNORMALMATRIX,
 	I_PROJECTION ,
@@ -63,29 +60,25 @@ const char *UniformNames[NUM_UNIFORMS] =
 	I_DEPTHPARAMS,
 };
 
-const static int PSVar_Loc[] = {
-	offsetof(PixelShaderConstants, colors)/16,
-	offsetof(PixelShaderConstants, kcolors)/16,
-	offsetof(PixelShaderConstants, alpha)/16,
-	offsetof(PixelShaderConstants, texdims)/16,
-	offsetof(PixelShaderConstants, zbias)/16,
-	offsetof(PixelShaderConstants, indtexscale)/16,
-	offsetof(PixelShaderConstants, indtexmtx)/16,
-	offsetof(PixelShaderConstants, fog)/16,
-	offsetof(PixelShaderConstants, plights)/16,
-	offsetof(PixelShaderConstants, pmaterials)/16,
-};
-
-const static int VSVar_Loc[] = {
-	offsetof(VertexShaderConstants, posnormalmatrix)/16,
-	offsetof(VertexShaderConstants, projection)/16,
-	offsetof(VertexShaderConstants, materials)/16,
-	offsetof(VertexShaderConstants, lights)/16,
-	offsetof(VertexShaderConstants, texmatrices)/16,
-	offsetof(VertexShaderConstants, transformmatrices)/16,
-	offsetof(VertexShaderConstants, normalmatrices)/16,
-	offsetof(VertexShaderConstants, posttransformmatrices)/16,
-	offsetof(VertexShaderConstants, depthparams)/16,
+const static int PSVar_Loc[NUM_UNIFORMS] = {
+	offsetof(Constants, colors)/16,
+	offsetof(Constants, kcolors)/16,
+	offsetof(Constants, alpha)/16,
+	offsetof(Constants, texdims)/16,
+	offsetof(Constants, zbias)/16,
+	offsetof(Constants, indtexscale)/16,
+	offsetof(Constants, indtexmtx)/16,
+	offsetof(Constants, fog)/16,
+	
+	offsetof(Constants, posnormalmatrix)/16,
+	offsetof(Constants, projection)/16,
+	offsetof(Constants, materials)/16,
+	offsetof(Constants, lights)/16,
+	offsetof(Constants, texmatrices)/16,
+	offsetof(Constants, transformmatrices)/16,
+	offsetof(Constants, normalmatrices)/16,
+	offsetof(Constants, posttransformmatrices)/16,
+	offsetof(Constants, depthparams)/16,
 };
 
 // End of UBO workaround
@@ -98,11 +91,11 @@ void SHADER::SetProgramVariables()
 	// Bind UBO
 	if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
 	{
-		GLint PSBlock_id = glGetUniformBlockIndex(glprogid, "PSBlock");
+		GLint CBlock_id = glGetUniformBlockIndex(glprogid, "CBlock");
 		GLint VSBlock_id = glGetUniformBlockIndex(glprogid, "VSBlock");
 
-		if(PSBlock_id != -1)
-			glUniformBlockBinding(glprogid, PSBlock_id, 1);
+		if(CBlock_id != -1)
+			glUniformBlockBinding(glprogid, CBlock_id, 1);
 		if(VSBlock_id != -1)
 			glUniformBlockBinding(glprogid, VSBlock_id, 2);
 	}
@@ -195,34 +188,13 @@ void ProgramShaderCache::UploadConstants()
 {
 	if(g_ActiveConfig.backend_info.bSupportsGLSLUBO)
 	{
-		if(PixelShaderManager::dirty || VertexShaderManager::dirty)
+		if(ConstantManager::dirty)
 		{
 			s_buffer->Alloc(s_ubo_buffer_size);
-			if (DriverDetails::HasBug(DriverDetails::BUG_BROKENBUFFERSTREAM))
-			{
-				// This is just a hack to support our BUFFERDATA upload method
-				// as it's broken to uploaded in a splited way
-				static u8 *tmpbuffer = new u8[s_ubo_buffer_size];
-				memcpy(tmpbuffer, &PixelShaderManager::constants, sizeof(PixelShaderConstants));
-				memcpy(tmpbuffer+ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align), &VertexShaderManager::constants, sizeof(VertexShaderConstants));
-				size_t offset = s_buffer->Upload(tmpbuffer, s_ubo_buffer_size);
-				glBindBufferRange(GL_UNIFORM_BUFFER, 1,
-						s_buffer->getBuffer(), offset, sizeof(PixelShaderConstants));
-				glBindBufferRange(GL_UNIFORM_BUFFER, 2,
-						s_buffer->getBuffer(), offset+ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align), sizeof(VertexShaderConstants));
-			}
-			else
-			{
-				size_t offset = s_buffer->Upload((u8*)&PixelShaderManager::constants, ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align));
-				glBindBufferRange(GL_UNIFORM_BUFFER, 1,
-						s_buffer->getBuffer(), offset, sizeof(PixelShaderConstants));
-				offset = s_buffer->Upload((u8*)&VertexShaderManager::constants, ROUND_UP(sizeof(VertexShaderConstants), s_ubo_align));
-				glBindBufferRange(GL_UNIFORM_BUFFER, 2,
-						s_buffer->getBuffer(), offset, sizeof(VertexShaderConstants));
-			}
+			size_t offset = s_buffer->Upload((u8*)&ConstantManager::constants, ROUND_UP(sizeof(Constants), s_ubo_align));
+			glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_buffer->getBuffer(), offset, sizeof(Constants));
 
-			PixelShaderManager::dirty = false;
-			VertexShaderManager::dirty = false;
+			ConstantManager::dirty = false;
 
 			ADDSTAT(stats.thisFrame.bytesUniformStreamed, s_ubo_buffer_size);
 		}
@@ -231,15 +203,10 @@ void ProgramShaderCache::UploadConstants()
 	{
 		// UBO workaround
 		// this must be updated per shader switch, so also update it when it's not dirty
-		for (unsigned int a = 0; a < 10; ++a)
+		for (unsigned int a = 0; a < NUM_UNIFORMS; ++a)
 		{
 			if(last_entry->shader.UniformSize[a] > 0)
-				glUniform4fv(last_entry->shader.UniformLocations[a], last_entry->shader.UniformSize[a], (float*) &PixelShaderManager::constants + 4*PSVar_Loc[a]);
-		}
-		for (unsigned int a = 0; a < 9; ++a)
-		{
-			if(last_entry->shader.UniformSize[a+10] > 0)
-				glUniform4fv(last_entry->shader.UniformLocations[a+10], last_entry->shader.UniformSize[a+10], (float*) &VertexShaderManager::constants + 4*VSVar_Loc[a]);
+				glUniform4fv(last_entry->shader.UniformLocations[a], last_entry->shader.UniformSize[a], (float*) &ConstantManager::constants + 4*PSVar_Loc[a]);
 		}
 
 		ADDSTAT(stats.thisFrame.bytesUniformStreamed, s_ubo_buffer_size);
@@ -480,7 +447,7 @@ void ProgramShaderCache::Init(void)
 	{
 		glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &s_ubo_align);
 
-		s_ubo_buffer_size = ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align) + ROUND_UP(sizeof(VertexShaderConstants), s_ubo_align);
+		s_ubo_buffer_size = ROUND_UP(sizeof(Constants), s_ubo_align);
 
 		// We multiply by *4*4 because we need to get down to basic machine units.
 		// So multiply by four to get how many floats we have from vec4s
diff --git a/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.h b/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.h
index a7b21a9..48f2d8f 100644
--- a/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.h
+++ b/Source/Core/VideoBackends/OGL/Src/ProgramShaderCache.h
@@ -41,7 +41,7 @@ public:
 };
 
 
-const int NUM_UNIFORMS = 19;
+const int NUM_UNIFORMS = 17;
 extern const char *UniformNames[NUM_UNIFORMS];
 
 struct SHADER
diff --git a/Source/Core/VideoBackends/OGL/Src/Render.cpp b/Source/Core/VideoBackends/OGL/Src/Render.cpp
index 4583c67..4ee7945 100644
--- a/Source/Core/VideoBackends/OGL/Src/Render.cpp
+++ b/Source/Core/VideoBackends/OGL/Src/Render.cpp
@@ -30,7 +30,7 @@
 #include "VertexShaderGen.h"
 #include "DLCache.h"
 #include "ProgramShaderCache.h"
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 #include "VertexLoaderManager.h"
 #include "VertexLoader.h"
 #include "PostProcessing.h"
@@ -1076,7 +1076,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
 	return 0;
 }
 
-// Called from VertexShaderManager
+// Called from ConstantManager
 void Renderer::UpdateViewport()
 {
 	// reversed gxsetviewport(xorig, yorig, width, height, nearz, farz)
diff --git a/Source/Core/VideoBackends/OGL/Src/VertexManager.cpp b/Source/Core/VideoBackends/OGL/Src/VertexManager.cpp
index 4fb355d..3b0e945 100644
--- a/Source/Core/VideoBackends/OGL/Src/VertexManager.cpp
+++ b/Source/Core/VideoBackends/OGL/Src/VertexManager.cpp
@@ -17,8 +17,7 @@
 #include "ImageWrite.h"
 #include "BPMemory.h"
 #include "TextureCache.h"
-#include "PixelShaderManager.h"
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 #include "ProgramShaderCache.h"
 #include "VertexShaderGen.h"
 #include "VertexLoader.h"
@@ -243,7 +242,7 @@ void VertexManager::vFlush()
 			if (tentry)
 			{
 				// 0s are probably for no manual wrapping needed.
-				PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
+				ConstantManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
 			}
 			else
 				ERROR_LOG(VIDEO, "Error loading texture");
@@ -276,8 +275,7 @@ void VertexManager::vFlush()
 	}
 
 	// set global constants
-	VertexShaderManager::SetConstants();
-	PixelShaderManager::SetConstants(g_nativeVertexFmt->m_components);
+	ConstantManager::SetConstants(g_nativeVertexFmt->m_components);
 	ProgramShaderCache::UploadConstants();
 
 	// setup the pointers
@@ -297,8 +295,7 @@ void VertexManager::vFlush()
 		if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
 		{
 			// Need to set these again, if we don't support UBO
-			VertexShaderManager::SetConstants();
-			PixelShaderManager::SetConstants(g_nativeVertexFmt->m_components);
+			ConstantManager::SetConstants(g_nativeVertexFmt->m_components);
 		}
 
 		// only update alpha
diff --git a/Source/Core/VideoBackends/OGL/Src/main.cpp b/Source/Core/VideoBackends/OGL/Src/main.cpp
index 7ad18bc..d0c6f83 100644
--- a/Source/Core/VideoBackends/OGL/Src/main.cpp
+++ b/Source/Core/VideoBackends/OGL/Src/main.cpp
@@ -68,8 +68,7 @@ Make AA apply instantly during gameplay if possible
 #include "VertexLoader.h"
 #include "VertexLoaderManager.h"
 #include "VertexManager.h"
-#include "PixelShaderManager.h"
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 #include "ProgramShaderCache.h"
 #include "CommandProcessor.h"
 #include "PixelEngine.h"
@@ -211,8 +210,7 @@ void VideoBackend::Video_Prepare()
 	Fifo_Init(); // must be done before OpcodeDecoder_Init()
 	OpcodeDecoder_Init();
 	IndexGenerator::Init();
-	VertexShaderManager::Init();
-	PixelShaderManager::Init();
+	ConstantManager::Init();
 	ProgramShaderCache::Init();
 	PostProcessing::Init();
 	g_texture_cache = new TextureCache();
@@ -262,8 +260,7 @@ void VideoBackend::Video_Cleanup() {
 		g_texture_cache = NULL;
 		PostProcessing::Shutdown();
 		ProgramShaderCache::Shutdown();
-		VertexShaderManager::Shutdown();
-		PixelShaderManager::Shutdown();
+		ConstantManager::Shutdown();
 		delete g_perf_query;
 		g_perf_query = NULL;
 		delete g_vertex_manager;
diff --git a/Source/Core/VideoCommon/CMakeLists.txt b/Source/Core/VideoCommon/CMakeLists.txt
index 5946245..249ed8e 100644
--- a/Source/Core/VideoCommon/CMakeLists.txt
+++ b/Source/Core/VideoCommon/CMakeLists.txt
@@ -3,6 +3,7 @@ set(SRCS	Src/BPFunctions.cpp
 			Src/BPStructs.cpp
 			Src/CPMemory.cpp
 			Src/CommandProcessor.cpp
+			Src/ConstantManager.cpp
 			Src/Debugger.cpp
 			Src/DriverDetails.cpp
 			Src/Fifo.cpp
@@ -19,7 +20,6 @@ set(SRCS	Src/BPFunctions.cpp
 			Src/PerfQueryBase.cpp
 			Src/PixelEngine.cpp
 			Src/PixelShaderGen.cpp
-			Src/PixelShaderManager.cpp
 			Src/RenderBase.cpp
 			Src/Statistics.cpp
 			Src/TextureCacheBase.cpp
@@ -32,7 +32,6 @@ set(SRCS	Src/BPFunctions.cpp
 			Src/VertexLoader_TextCoord.cpp
 			Src/VertexManagerBase.cpp
 			Src/VertexShaderGen.cpp
-			Src/VertexShaderManager.cpp
 			Src/VideoBackendBase.cpp
 			Src/VideoConfig.cpp
 			Src/VideoState.cpp
diff --git a/Source/Core/VideoCommon/Src/BPFunctions.cpp b/Source/Core/VideoCommon/Src/BPFunctions.cpp
index 43623a9..33b855f 100644
--- a/Source/Core/VideoCommon/Src/BPFunctions.cpp
+++ b/Source/Core/VideoCommon/Src/BPFunctions.cpp
@@ -7,7 +7,7 @@
 #include "RenderBase.h"
 #include "TextureCacheBase.h"
 #include "VertexManagerBase.h"
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 #include "VideoConfig.h"
 #include "HW/Memmap.h"
 #include "ConfigManager.h"
diff --git a/Source/Core/VideoCommon/Src/BPStructs.cpp b/Source/Core/VideoCommon/Src/BPStructs.cpp
index ed3fcce..698a629 100644
--- a/Source/Core/VideoCommon/Src/BPStructs.cpp
+++ b/Source/Core/VideoCommon/Src/BPStructs.cpp
@@ -8,13 +8,12 @@
 #include "Statistics.h"
 #include "RenderBase.h"
 #include "VideoCommon.h"
-#include "PixelShaderManager.h"
+#include "ConstantManager.h"
 #include "PixelEngine.h"
 #include "BPFunctions.h"
 #include "BPStructs.h"
 #include "TextureDecoder.h"
 #include "VertexLoader.h"
-#include "VertexShaderManager.h"
 #include "Thread.h"
 #include "HW/Memmap.h"
 #include "PerfQueryBase.h"
@@ -168,15 +167,15 @@ void BPWritten(const BPCmd& bp)
 	case BPMEM_IND_MTXB+6:
 	case BPMEM_IND_MTXC+6:
 		if(bp.changes)
-			PixelShaderManager::SetIndMatrixChanged((bp.address - BPMEM_IND_MTXA) / 3);
+			ConstantManager::SetIndMatrixChanged((bp.address - BPMEM_IND_MTXA) / 3);
 		break;
 	case BPMEM_RAS1_SS0: // Index Texture Coordinate Scale 0
 		if(bp.changes)
-			PixelShaderManager::SetIndTexScaleChanged(false);
+			ConstantManager::SetIndTexScaleChanged(false);
 		break;
 	case BPMEM_RAS1_SS1: // Index Texture Coordinate Scale 1
 		if(bp.changes)
-			PixelShaderManager::SetIndTexScaleChanged(true);
+			ConstantManager::SetIndTexScaleChanged(true);
 		break;
 	// ----------------
 	// Scissor Control
@@ -185,7 +184,7 @@ void BPWritten(const BPCmd& bp)
 	case BPMEM_SCISSORBR: // Scissor Rectable Bottom, Right
 	case BPMEM_SCISSOROFFSET: // Scissor Offset
 		SetScissor();
-		VertexShaderManager::SetViewportChanged();
+		ConstantManager::SetViewportChanged();
 		break;
 	case BPMEM_LINEPTWIDTH: // Line Width
 		SetLineWidth();
@@ -225,7 +224,7 @@ void BPWritten(const BPCmd& bp)
 		{
 			PRIM_LOG("constalpha: alp=%d, en=%d", bpmem.dstalpha.alpha, bpmem.dstalpha.enable);
 			if(bp.changes & 0xFF)
-				PixelShaderManager::SetDestAlpha();
+				ConstantManager::SetDestAlpha();
 			if(bp.changes & 0x100)
 				SetBlendMode();
 			break;
@@ -347,36 +346,36 @@ void BPWritten(const BPCmd& bp)
 	case BPMEM_FOGRANGE+4:
 	case BPMEM_FOGRANGE+5:
 		if (!GetConfig(CONFIG_DISABLEFOG) && bp.changes)
-			PixelShaderManager::SetFogRangeAdjustChanged();
+			ConstantManager::SetFogRangeAdjustChanged();
 		break;
 	case BPMEM_FOGPARAM0:
 	case BPMEM_FOGBMAGNITUDE:
 	case BPMEM_FOGBEXPONENT:
 	case BPMEM_FOGPARAM3:
 		if (!GetConfig(CONFIG_DISABLEFOG) && bp.changes)
-			PixelShaderManager::SetFogParamChanged();
+			ConstantManager::SetFogParamChanged();
 		break;
 	case BPMEM_FOGCOLOR: // Fog Color
 		if (!GetConfig(CONFIG_DISABLEFOG) && bp.changes)
-			PixelShaderManager::SetFogColorChanged();
+			ConstantManager::SetFogColorChanged();
 		break;
 	case BPMEM_ALPHACOMPARE: // Compare Alpha Values
 		PRIM_LOG("alphacmp: ref0=%d, ref1=%d, comp0=%d, comp1=%d, logic=%d", bpmem.alpha_test.ref0,
 				bpmem.alpha_test.ref1, bpmem.alpha_test.comp0, bpmem.alpha_test.comp1, bpmem.alpha_test.logic);
 		if(bp.changes & 0xFFFF)
-			PixelShaderManager::SetAlpha();
+			ConstantManager::SetAlpha();
 		if(bp.changes)
 			g_renderer->SetColorMask();
 		break;
 	case BPMEM_BIAS: // BIAS
 		PRIM_LOG("ztex bias=0x%x", bpmem.ztex1.bias);
 		if(bp.changes)
-			PixelShaderManager::SetZTextureBias();
+			ConstantManager::SetZTextureBias();
 		break;
 	case BPMEM_ZTEX2: // Z Texture type
 		{
 			if (bp.changes & 3)
-				PixelShaderManager::SetZTextureTypeChanged();
+				ConstantManager::SetZTextureTypeChanged();
 			#if defined(_DEBUG) || defined(DEBUGFAST)
 			const char* pzop[] = {"DISABLE", "ADD", "REPLACE", "?"};
 			const char* pztype[] = {"Z8", "Z16", "Z24", "?"};
@@ -582,7 +581,7 @@ void BPWritten(const BPCmd& bp)
 		case BPMEM_SU_SSIZE+14:
 		case BPMEM_SU_TSIZE+14:
 			if(bp.changes)
-				PixelShaderManager::SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
+				ConstantManager::SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
 			break;
 		// ------------------------
 		// BPMEM_TX_SETMODE0 - (Texture lookup and filtering mode) LOD/BIAS Clamp, MaxAnsio, LODBIAS, DiagLoad, Min Filter, Mag Filter, Wrap T, S
@@ -636,9 +635,9 @@ void BPWritten(const BPCmd& bp)
 				// don't compare with changes!
 				int num = (bp.address >> 1) & 0x3;
 				if ((bp.address & 1) == 0)
-					PixelShaderManager::SetColorChanged(bpmem.tevregs[num].low.type, num);
+					ConstantManager::SetColorChanged(bpmem.tevregs[num].low.type, num);
 				else
-					PixelShaderManager::SetColorChanged(bpmem.tevregs[num].high.type, num);
+					ConstantManager::SetColorChanged(bpmem.tevregs[num].high.type, num);
 			}
 			break;
 
@@ -721,7 +720,7 @@ void BPReload()
 {
 	// restore anything that goes straight to the renderer.
 	// let's not risk actually replaying any writes.
-	// note that PixelShaderManager is already covered since it has its own DoState.
+	// note that ConstantManager is already covered since it has its own DoState.
 	SetGenerationMode();
 	SetScissor();
 	SetLineWidth();
diff --git a/Source/Core/VideoCommon/Src/ConstantManager.cpp b/Source/Core/VideoCommon/Src/ConstantManager.cpp
new file mode 100644
index 0000000..2da2f99
--- /dev/null
+++ b/Source/Core/VideoCommon/Src/ConstantManager.cpp
@@ -0,0 +1,895 @@
+// Copyright 2013 Dolphin Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include <cmath>
+
+#include "Common.h"
+#include "Statistics.h"
+#include "ConstantManager.h"
+#include "VideoCommon.h"
+#include "VideoConfig.h"
+#include "BPMemory.h"
+#include "XFMemory.h"
+#include "MathUtil.h"
+#include "CPMemory.h"
+#include "VertexManagerBase.h"
+
+#include "RenderBase.h"
+static bool s_bFogRangeAdjustChanged;
+
+float GC_ALIGNED16(g_fProjectionMatrix[16]);
+
+// track changes
+static bool bTexMatricesChanged[2], bPosNormalMatrixChanged, bProjectionChanged, bViewportChanged;
+static int nTransformMatricesChanged[2]; // min,max
+static int nNormalMatricesChanged[2]; // min,max
+static int nPostTransformMatricesChanged[2]; // min,max
+static int nLightsChanged[2]; // min,max
+
+static Matrix44 s_viewportCorrection;
+static Matrix33 s_viewRotationMatrix;
+static Matrix33 s_viewInvRotationMatrix;
+static float s_fViewTranslationVector[3];
+static float s_fViewRotation[2];
+
+Constants ConstantManager::constants;
+bool ConstantManager::dirty;
+
+struct ProjectionHack
+{
+	float sign;
+	float value;
+	ProjectionHack() { }
+	ProjectionHack(float new_sign, float new_value)
+		: sign(new_sign), value(new_value) {}
+};
+
+namespace
+{
+// Control Variables
+static ProjectionHack g_ProjHack1;
+static ProjectionHack g_ProjHack2;
+static bool g_ProjHack3;
+} // Namespace
+
+float PHackValue(std::string sValue)
+{
+	float f = 0;
+	bool fp = false;
+	const char *cStr = sValue.c_str();
+	char *c = new char[strlen(cStr)+1];
+	std::istringstream sTof("");
+
+	for (unsigned int i=0; i<=strlen(cStr); ++i)
+	{
+		if (i == 20)
+		{
+			c[i] = '\0';
+			break;
+		}
+
+		c[i] = (cStr[i] == ',') ? '.' : *(cStr+i);
+		if (c[i] == '.')
+			fp = true;
+	}
+
+	cStr = c;
+	sTof.str(cStr);
+	sTof >> f;
+
+	if (!fp)
+		f /= 0xF4240;
+
+	delete [] c;
+	return f;
+}
+
+void UpdateProjectionHack(int iPhackvalue[], std::string sPhackvalue[])
+{
+	float fhackvalue1 = 0, fhackvalue2 = 0;
+	float fhacksign1 = 1.0, fhacksign2 = 1.0;
+	bool bProjHack3 = false;
+	const char *sTemp[2];
+
+	if (iPhackvalue[0] == 1)
+	{
+		NOTICE_LOG(VIDEO, "\t\t--- Orthographic Projection Hack ON ---");
+
+		fhacksign1 *= (iPhackvalue[1] == 1) ? -1.0f : fhacksign1;
+		sTemp[0] = (iPhackvalue[1] == 1) ? " * (-1)" : "";
+		fhacksign2 *= (iPhackvalue[2] == 1) ? -1.0f : fhacksign2;
+		sTemp[1] = (iPhackvalue[2] == 1) ? " * (-1)" : "";
+
+		fhackvalue1 = PHackValue(sPhackvalue[0]);
+		NOTICE_LOG(VIDEO, "- zNear Correction = (%f + zNear)%s", fhackvalue1, sTemp[0]);
+
+		fhackvalue2 = PHackValue(sPhackvalue[1]);
+		NOTICE_LOG(VIDEO, "- zFar Correction =  (%f + zFar)%s", fhackvalue2, sTemp[1]);
+
+		sTemp[0] = "DISABLED";
+		bProjHack3 = (iPhackvalue[3] == 1) ? true : bProjHack3;
+		if (bProjHack3)
+			sTemp[0] = "ENABLED";
+		NOTICE_LOG(VIDEO, "- Extra Parameter: %s", sTemp[0]);
+	}
+
+	// Set the projections hacks
+	g_ProjHack1 = ProjectionHack(fhacksign1, fhackvalue1);
+	g_ProjHack2 = ProjectionHack(fhacksign2, fhackvalue2);
+	g_ProjHack3 = bProjHack3;
+}
+
+
+// Viewport correction:
+// In D3D, the viewport rectangle must fit within the render target.
+// Say you want a viewport at (ix, iy) with size (iw, ih),
+// but your viewport must be clamped at (ax, ay) with size (aw, ah).
+// Just multiply the projection matrix with the following to get the same
+// effect:
+// [   (iw/aw)         0     0    ((iw - 2*(ax-ix)) / aw - 1)   ]
+// [         0   (ih/ah)     0   ((-ih + 2*(ay-iy)) / ah + 1)   ]
+// [         0         0     1                              0   ]
+// [         0         0     0                              1   ]
+static void ViewportCorrectionMatrix(Matrix44& result)
+{
+	int scissorXOff = bpmem.scissorOffset.x * 2;
+	int scissorYOff = bpmem.scissorOffset.y * 2;
+
+	// TODO: ceil, floor or just cast to int?
+	// TODO: Directly use the floats instead of rounding them?
+	float intendedX = xfregs.viewport.xOrig - xfregs.viewport.wd - scissorXOff;
+	float intendedY = xfregs.viewport.yOrig + xfregs.viewport.ht - scissorYOff;
+	float intendedWd = 2.0f * xfregs.viewport.wd;
+	float intendedHt = -2.0f * xfregs.viewport.ht;
+	
+        if (intendedWd < 0.f)
+        {
+                intendedX += intendedWd;
+                intendedWd = -intendedWd;
+        }
+        if (intendedHt < 0.f)
+        {
+                intendedY += intendedHt;
+                intendedHt = -intendedHt;
+        }
+
+	// fit to EFB size
+        float X = (intendedX >= 0.f) ? intendedX : 0.f;
+        float Y = (intendedY >= 0.f) ? intendedY : 0.f;
+        float Wd = (X + intendedWd <= EFB_WIDTH) ? intendedWd : (EFB_WIDTH - X);
+        float Ht = (Y + intendedHt <= EFB_HEIGHT) ? intendedHt : (EFB_HEIGHT - Y);
+	
+	Matrix44::LoadIdentity(result);
+	if (Wd == 0 || Ht == 0)
+		return;
+	
+	result.data[4*0+0] = intendedWd / Wd;
+	result.data[4*0+3] = (intendedWd - 2.f * (X - intendedX)) / Wd - 1.f;
+	result.data[4*1+1] = intendedHt / Ht;
+	result.data[4*1+3] = (-intendedHt + 2.f * (Y - intendedY)) / Ht + 1.f;
+}
+
+void UpdateViewport();
+
+void ConstantManager::Init()
+{
+	memset(&constants, 0, sizeof(constants));
+
+	memset(&xfregs, 0, sizeof(xfregs));
+	memset(xfmem, 0, sizeof(xfmem));
+	memset(&constants, 0 , sizeof(constants));
+	ResetView();
+
+	// TODO: should these go inside ResetView()?
+	Matrix44::LoadIdentity(s_viewportCorrection);
+	memset(g_fProjectionMatrix, 0, sizeof(g_fProjectionMatrix));
+	for (int i = 0; i < 4; ++i)
+		g_fProjectionMatrix[i*5] = 1.0f;
+	
+	Dirty();
+}
+
+void ConstantManager::Dirty()
+{
+	s_bFogRangeAdjustChanged = true;
+	bViewportChanged = true;
+	
+	nTransformMatricesChanged[0] = 0;
+	nTransformMatricesChanged[1] = 256;
+
+	nNormalMatricesChanged[0] = 0;
+	nNormalMatricesChanged[1] = 96;
+
+	nPostTransformMatricesChanged[0] = 0;
+	nPostTransformMatricesChanged[1] = 256;
+
+	nLightsChanged[0] = 0;
+	nLightsChanged[1] = 0x80;
+
+	bPosNormalMatrixChanged = true;
+	bTexMatricesChanged[0] = true;
+	bTexMatricesChanged[1] = true;
+
+	bProjectionChanged = true;
+
+	SetColorChanged(0, 0);
+	SetColorChanged(0, 1);
+	SetColorChanged(0, 2);
+	SetColorChanged(0, 3);
+	SetColorChanged(1, 0);
+	SetColorChanged(1, 1);
+	SetColorChanged(1, 2);
+	SetColorChanged(1, 3);
+	SetAlpha();
+	SetDestAlpha();
+	SetZTextureBias();
+	SetViewportChanged();
+	SetIndTexScaleChanged(false);
+	SetIndTexScaleChanged(true);
+	SetIndMatrixChanged(0);
+	SetIndMatrixChanged(1);
+	SetIndMatrixChanged(2);
+	SetZTextureTypeChanged();
+	SetTexCoordChanged(0);
+	SetTexCoordChanged(1);
+	SetTexCoordChanged(2);
+	SetTexCoordChanged(3);
+	SetTexCoordChanged(4);
+	SetTexCoordChanged(5);
+	SetTexCoordChanged(6);
+	SetTexCoordChanged(7);
+	SetFogColorChanged();
+	SetFogParamChanged();
+}
+
+void ConstantManager::Shutdown()
+{
+
+}
+
+void ConstantManager::SetConstants(u32 components)
+{
+	if (s_bFogRangeAdjustChanged)
+	{
+		// set by two components, so keep changed flag here
+		// TODO: try to split both registers and move this logic to the shader
+		if(!g_ActiveConfig.bDisableFog && bpmem.fogRange.Base.Enabled == 1)
+		{
+			//bpmem.fogRange.Base.Center : center of the viewport in x axis. observation: bpmem.fogRange.Base.Center = realcenter + 342;
+			int center = ((u32)bpmem.fogRange.Base.Center) - 342;
+			// normalize center to make calculations easy
+			float ScreenSpaceCenter = center / (2.0f * xfregs.viewport.wd);
+			ScreenSpaceCenter = (ScreenSpaceCenter * 2.0f) - 1.0f;
+			//bpmem.fogRange.K seems to be  a table of precalculated coefficients for the adjust factor
+			//observations: bpmem.fogRange.K[0].LO appears to be the lowest value and bpmem.fogRange.K[4].HI the largest
+			// they always seems to be larger than 256 so my theory is :
+			// they are the coefficients from the center to the border of the screen
+			// so to simplify I use the hi coefficient as K in the shader taking 256 as the scale
+			constants.fog[2][0] = ScreenSpaceCenter;
+			constants.fog[2][1] = Renderer::EFBToScaledX((int)(2.0f * xfregs.viewport.wd));
+			constants.fog[2][2] = bpmem.fogRange.K[4].HI / 256.0f;
+		}
+		else
+		{
+			constants.fog[2][0] = 0;
+			constants.fog[2][1] = 1;
+			constants.fog[2][2] = 1;
+		}
+		dirty = true;
+
+		s_bFogRangeAdjustChanged = false;
+	}
+	
+	if (nTransformMatricesChanged[0] >= 0)
+	{
+		int startn = nTransformMatricesChanged[0] / 4;
+		int endn = (nTransformMatricesChanged[1] + 3) / 4;
+		memcpy(constants.transformmatrices[startn], &xfmem[startn * 4], (endn - startn) * 16);
+		dirty = true;
+		nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
+	}
+
+	if (nNormalMatricesChanged[0] >= 0)
+	{
+		int startn = nNormalMatricesChanged[0] / 3;
+		int endn = (nNormalMatricesChanged[1] + 2) / 3;
+		for(int i=startn; i<endn; i++)
+		{
+			memcpy(constants.normalmatrices[i], &xfmem[XFMEM_NORMALMATRICES + 3*i], 12);
+		}
+		dirty = true;
+		nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1;
+	}
+
+	if (nPostTransformMatricesChanged[0] >= 0)
+	{
+		int startn = nPostTransformMatricesChanged[0] / 4;
+		int endn = (nPostTransformMatricesChanged[1] + 3 ) / 4;
+		memcpy(constants.posttransformmatrices[startn], &xfmem[XFMEM_POSTMATRICES + startn * 4], (endn - startn) * 16);
+		dirty = true;
+		nPostTransformMatricesChanged[0] = nPostTransformMatricesChanged[1] = -1;
+	}
+
+	if (nLightsChanged[0] >= 0)
+	{
+		// lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats
+		int istart = nLightsChanged[0] / 0x10;
+		int iend = (nLightsChanged[1] + 15) / 0x10;
+		const float* xfmemptr = (const float*)&xfmem[0x10 * istart + XFMEM_LIGHTS];
+
+		for (int i = istart; i < iend; ++i)
+		{
+			u32 color = *(const u32*)(xfmemptr + 3);
+			constants.lights[5*i][0] = ((color >> 24) & 0xFF) / 255.0f;
+			constants.lights[5*i][1] = ((color >> 16) & 0xFF) / 255.0f;
+			constants.lights[5*i][2] = ((color >> 8)  & 0xFF) / 255.0f;
+			constants.lights[5*i][3] = ((color)       & 0xFF) / 255.0f;
+			xfmemptr += 4;
+
+			for (int j = 0; j < 4; ++j, xfmemptr += 3)
+			{
+				if (j == 1 &&
+					fabs(xfmemptr[0]) < 0.00001f &&
+					fabs(xfmemptr[1]) < 0.00001f &&
+					fabs(xfmemptr[2]) < 0.00001f)
+				{
+					// dist attenuation, make sure not equal to 0!!!
+					constants.lights[5*i+j+1][0] = 0.00001f;
+				}
+				else
+					constants.lights[5*i+j+1][0] = xfmemptr[0];
+				constants.lights[5*i+j+1][1] = xfmemptr[1];
+				constants.lights[5*i+j+1][2] = xfmemptr[2];
+			}
+		}
+		dirty = true;
+
+		nLightsChanged[0] = nLightsChanged[1] = -1;
+	}
+
+	if (bPosNormalMatrixChanged)
+	{
+		bPosNormalMatrixChanged = false;
+
+		const float *pos = (const float *)xfmem + MatrixIndexA.PosNormalMtxIdx * 4;
+		const float *norm = (const float *)xfmem + XFMEM_NORMALMATRICES + 3 * (MatrixIndexA.PosNormalMtxIdx & 31);
+
+		memcpy(constants.posnormalmatrix, pos, 3*16);
+		memcpy(constants.posnormalmatrix[3], norm, 12);
+		memcpy(constants.posnormalmatrix[4], norm+3, 12);
+		memcpy(constants.posnormalmatrix[5], norm+6, 12);
+		dirty = true;
+	}
+
+	if (bTexMatricesChanged[0])
+	{
+		bTexMatricesChanged[0] = false;
+		const float *fptrs[] =
+		{
+			(const float *)xfmem + MatrixIndexA.Tex0MtxIdx * 4, (const float *)xfmem + MatrixIndexA.Tex1MtxIdx * 4,
+			(const float *)xfmem + MatrixIndexA.Tex2MtxIdx * 4, (const float *)xfmem + MatrixIndexA.Tex3MtxIdx * 4
+		};
+
+		for (int i = 0; i < 4; ++i)
+		{
+			memcpy(constants.texmatrices[3*i], fptrs[i], 3*16);
+		}
+		dirty = true;
+	}
+
+	if (bTexMatricesChanged[1])
+	{
+		bTexMatricesChanged[1] = false;
+		const float *fptrs[] = {
+			(const float *)xfmem + MatrixIndexB.Tex4MtxIdx * 4, (const float *)xfmem + MatrixIndexB.Tex5MtxIdx * 4,
+			(const float *)xfmem + MatrixIndexB.Tex6MtxIdx * 4, (const float *)xfmem + MatrixIndexB.Tex7MtxIdx * 4
+		};
+
+		for (int i = 0; i < 4; ++i)
+		{
+			memcpy(constants.texmatrices[3*i+12], fptrs[i], 3*16);
+		}
+		dirty = true;
+	}
+
+	if (bViewportChanged)
+	{
+		bViewportChanged = false;
+		constants.depthparams[0] = xfregs.viewport.farZ / 16777216.0f;
+		constants.depthparams[1] = xfregs.viewport.zRange / 16777216.0f;
+		constants.zbias[1][0] = xfregs.viewport.farZ / 16777216.0f;
+		constants.zbias[1][1] = xfregs.viewport.zRange / 16777216.0f;
+		
+		dirty = true;
+		// This is so implementation-dependent that we can't have it here.
+		UpdateViewport();
+		
+		// Update projection if the viewport isn't 1:1 useable
+		if(!g_ActiveConfig.backend_info.bSupportsOversizedViewports)
+		{
+			ViewportCorrectionMatrix(s_viewportCorrection);
+			bProjectionChanged = true;			
+		}
+	}
+
+	if (bProjectionChanged)
+	{
+		bProjectionChanged = false;
+
+		float *rawProjection = xfregs.projection.rawProjection;
+
+		switch(xfregs.projection.type)
+		{
+		case GX_PERSPECTIVE:
+
+			g_fProjectionMatrix[0] = rawProjection[0] * g_ActiveConfig.fAspectRatioHackW;
+			g_fProjectionMatrix[1] = 0.0f;
+			g_fProjectionMatrix[2] = rawProjection[1];
+			g_fProjectionMatrix[3] = 0.0f;
+
+			g_fProjectionMatrix[4] = 0.0f;
+			g_fProjectionMatrix[5] = rawProjection[2] * g_ActiveConfig.fAspectRatioHackH;
+			g_fProjectionMatrix[6] = rawProjection[3];
+			g_fProjectionMatrix[7] = 0.0f;
+
+			g_fProjectionMatrix[8] = 0.0f;
+			g_fProjectionMatrix[9] = 0.0f;
+			g_fProjectionMatrix[10] = rawProjection[4];
+
+			g_fProjectionMatrix[11] = rawProjection[5];
+
+			g_fProjectionMatrix[12] = 0.0f;
+			g_fProjectionMatrix[13] = 0.0f;
+			// donkopunchstania: GC GPU rounds differently?
+			// -(1 + epsilon) so objects are clipped as they are on the real HW
+			g_fProjectionMatrix[14] = -1.00000011921f;
+			g_fProjectionMatrix[15] = 0.0f;
+
+			SETSTAT_FT(stats.gproj_0, g_fProjectionMatrix[0]);
+			SETSTAT_FT(stats.gproj_1, g_fProjectionMatrix[1]);
+			SETSTAT_FT(stats.gproj_2, g_fProjectionMatrix[2]);
+			SETSTAT_FT(stats.gproj_3, g_fProjectionMatrix[3]);
+			SETSTAT_FT(stats.gproj_4, g_fProjectionMatrix[4]);
+			SETSTAT_FT(stats.gproj_5, g_fProjectionMatrix[5]);
+			SETSTAT_FT(stats.gproj_6, g_fProjectionMatrix[6]);
+			SETSTAT_FT(stats.gproj_7, g_fProjectionMatrix[7]);
+			SETSTAT_FT(stats.gproj_8, g_fProjectionMatrix[8]);
+			SETSTAT_FT(stats.gproj_9, g_fProjectionMatrix[9]);
+			SETSTAT_FT(stats.gproj_10, g_fProjectionMatrix[10]);
+			SETSTAT_FT(stats.gproj_11, g_fProjectionMatrix[11]);
+			SETSTAT_FT(stats.gproj_12, g_fProjectionMatrix[12]);
+			SETSTAT_FT(stats.gproj_13, g_fProjectionMatrix[13]);
+			SETSTAT_FT(stats.gproj_14, g_fProjectionMatrix[14]);
+			SETSTAT_FT(stats.gproj_15, g_fProjectionMatrix[15]);
+			break;
+
+		case GX_ORTHOGRAPHIC:
+
+			g_fProjectionMatrix[0] = rawProjection[0];
+			g_fProjectionMatrix[1] = 0.0f;
+			g_fProjectionMatrix[2] = 0.0f;
+			g_fProjectionMatrix[3] = rawProjection[1];
+
+			g_fProjectionMatrix[4] = 0.0f;
+			g_fProjectionMatrix[5] = rawProjection[2];
+			g_fProjectionMatrix[6] = 0.0f;
+			g_fProjectionMatrix[7] = rawProjection[3];
+
+			g_fProjectionMatrix[8] = 0.0f;
+			g_fProjectionMatrix[9] = 0.0f;
+			g_fProjectionMatrix[10] = (g_ProjHack1.value + rawProjection[4]) * ((g_ProjHack1.sign == 0) ? 1.0f : g_ProjHack1.sign);
+			g_fProjectionMatrix[11] = (g_ProjHack2.value + rawProjection[5]) * ((g_ProjHack2.sign == 0) ? 1.0f : g_ProjHack2.sign);
+
+			g_fProjectionMatrix[12] = 0.0f;
+			g_fProjectionMatrix[13] = 0.0f;
+
+			/*
+			projection hack for metroid other m...attempt to remove black projection layer from cut scenes.
+			g_fProjectionMatrix[15] = 1.0f was the default setting before
+			this hack was added...setting g_fProjectionMatrix[14] to -1 might make the hack more stable, needs more testing.
+			Only works for OGL and DX9...this is not helping DX11
+			*/
+
+			g_fProjectionMatrix[14] = 0.0f;
+			g_fProjectionMatrix[15] = (g_ProjHack3 && rawProjection[0] == 2.0f ? 0.0f : 1.0f);  //causes either the efb copy or bloom layer not to show if proj hack enabled
+
+			SETSTAT_FT(stats.g2proj_0, g_fProjectionMatrix[0]);
+			SETSTAT_FT(stats.g2proj_1, g_fProjectionMatrix[1]);
+			SETSTAT_FT(stats.g2proj_2, g_fProjectionMatrix[2]);
+			SETSTAT_FT(stats.g2proj_3, g_fProjectionMatrix[3]);
+			SETSTAT_FT(stats.g2proj_4, g_fProjectionMatrix[4]);
+			SETSTAT_FT(stats.g2proj_5, g_fProjectionMatrix[5]);
+			SETSTAT_FT(stats.g2proj_6, g_fProjectionMatrix[6]);
+			SETSTAT_FT(stats.g2proj_7, g_fProjectionMatrix[7]);
+			SETSTAT_FT(stats.g2proj_8, g_fProjectionMatrix[8]);
+			SETSTAT_FT(stats.g2proj_9, g_fProjectionMatrix[9]);
+			SETSTAT_FT(stats.g2proj_10, g_fProjectionMatrix[10]);
+			SETSTAT_FT(stats.g2proj_11, g_fProjectionMatrix[11]);
+			SETSTAT_FT(stats.g2proj_12, g_fProjectionMatrix[12]);
+			SETSTAT_FT(stats.g2proj_13, g_fProjectionMatrix[13]);
+			SETSTAT_FT(stats.g2proj_14, g_fProjectionMatrix[14]);
+			SETSTAT_FT(stats.g2proj_15, g_fProjectionMatrix[15]);
+			SETSTAT_FT(stats.proj_0, rawProjection[0]);
+			SETSTAT_FT(stats.proj_1, rawProjection[1]);
+			SETSTAT_FT(stats.proj_2, rawProjection[2]);
+			SETSTAT_FT(stats.proj_3, rawProjection[3]);
+			SETSTAT_FT(stats.proj_4, rawProjection[4]);
+			SETSTAT_FT(stats.proj_5, rawProjection[5]);
+			break;
+
+		default:
+			ERROR_LOG(VIDEO, "Unknown projection type: %d", xfregs.projection.type);
+		}
+
+		PRIM_LOG("Projection: %f %f %f %f %f %f\n", rawProjection[0], rawProjection[1], rawProjection[2], rawProjection[3], rawProjection[4], rawProjection[5]);
+
+		if ((g_ActiveConfig.bFreeLook || g_ActiveConfig.bAnaglyphStereo ) && xfregs.projection.type == GX_PERSPECTIVE)
+		{
+			Matrix44 mtxA;
+			Matrix44 mtxB;
+			Matrix44 viewMtx;
+
+			Matrix44::Translate(mtxA, s_fViewTranslationVector);
+			Matrix44::LoadMatrix33(mtxB, s_viewRotationMatrix);
+			Matrix44::Multiply(mtxB, mtxA, viewMtx); // view = rotation x translation
+			Matrix44::Set(mtxB, g_fProjectionMatrix);
+			Matrix44::Multiply(mtxB, viewMtx, mtxA); // mtxA = projection x view
+			Matrix44::Multiply(s_viewportCorrection, mtxA, mtxB); // mtxB = viewportCorrection x mtxA
+			memcpy(constants.projection, mtxB.data, 4*16);
+		}
+		else
+		{
+			Matrix44 projMtx;
+			Matrix44::Set(projMtx, g_fProjectionMatrix);
+
+			Matrix44 correctedMtx;
+			Matrix44::Multiply(s_viewportCorrection, projMtx, correctedMtx);
+			memcpy(constants.projection, correctedMtx.data, 4*16);
+		}
+		dirty = true;
+	}
+}
+
+// This one is high in profiles (0.5%).
+// TODO: Move conversion out, only store the raw color value
+// and update it when the shader constant is set, only.
+// TODO: Conversion should be checked in the context of tev_fixes..
+void ConstantManager::SetColorChanged(int type, int num)
+{
+	float4* c = type ? constants.kcolors : constants.colors;
+	c[num][0] = bpmem.tevregs[num].low.a / 255.0f;
+	c[num][3] = bpmem.tevregs[num].low.b / 255.0f;
+	c[num][2] = bpmem.tevregs[num].high.a / 255.0f;
+	c[num][1] = bpmem.tevregs[num].high.b / 255.0f;
+	dirty = true;
+
+	PRIM_LOG("pixel %scolor%d: %f %f %f %f\n", type?"k":"", num, c[num][0], c[num][1], c[num][2], c[num][3]);
+}
+
+void ConstantManager::SetAlpha()
+{
+	constants.alpha[0] = bpmem.alpha_test.ref0 / 255.0f;
+	constants.alpha[1] = bpmem.alpha_test.ref1 / 255.0f;
+	dirty = true;
+}
+
+void ConstantManager::SetDestAlpha()
+{
+	constants.alpha[3] = bpmem.dstalpha.alpha / 255.0f;
+	dirty = true;
+}
+
+void ConstantManager::SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt)
+{
+	// TODO: move this check out to callee. There we could just call this function on texture changes
+	// or better, use textureSize() in glsl
+	if(constants.texdims[texmapid][0] != 1.0f/width || constants.texdims[texmapid][1] != 1.0f/height)
+		dirty = true;
+
+	constants.texdims[texmapid][0] = 1.0f/width;
+	constants.texdims[texmapid][1] = 1.0f/height;
+}
+
+void ConstantManager::SetZTextureBias()
+{
+	constants.zbias[1][3] = bpmem.ztex1.bias/16777215.0f;
+	dirty = true;
+}
+
+void ConstantManager::SetViewportChanged()
+{
+	bViewportChanged = true;
+	s_bFogRangeAdjustChanged = true; // TODO: Shouldn't be necessary with an accurate fog range adjust implementation
+}
+
+void ConstantManager::SetIndTexScaleChanged(bool high)
+{
+	constants.indtexscale[high][0] = bpmem.texscale[high].getScaleS(0);
+	constants.indtexscale[high][1] = bpmem.texscale[high].getScaleT(0);
+	constants.indtexscale[high][2] = bpmem.texscale[high].getScaleS(1);
+	constants.indtexscale[high][3] = bpmem.texscale[high].getScaleT(1);
+	dirty = true;
+}
+
+void ConstantManager::SetIndMatrixChanged(int matrixidx)
+{
+	int scale = ((u32)bpmem.indmtx[matrixidx].col0.s0 << 0) |
+			((u32)bpmem.indmtx[matrixidx].col1.s1 << 2) |
+			((u32)bpmem.indmtx[matrixidx].col2.s2 << 4);
+	float fscale = powf(2.0f, (float)(scale - 17)) / 1024.0f;
+
+	// xyz - static matrix
+	// TODO w - dynamic matrix scale / 256...... somehow / 4 works better
+	// rev 2972 - now using / 256.... verify that this works
+	constants.indtexmtx[2*matrixidx][0] = bpmem.indmtx[matrixidx].col0.ma * fscale;
+	constants.indtexmtx[2*matrixidx][1] = bpmem.indmtx[matrixidx].col1.mc * fscale;
+	constants.indtexmtx[2*matrixidx][2] = bpmem.indmtx[matrixidx].col2.me * fscale;
+	constants.indtexmtx[2*matrixidx][3] = fscale * 4.0f;
+	constants.indtexmtx[2*matrixidx+1][0] = bpmem.indmtx[matrixidx].col0.mb * fscale;
+	constants.indtexmtx[2*matrixidx+1][1] = bpmem.indmtx[matrixidx].col1.md * fscale;
+	constants.indtexmtx[2*matrixidx+1][2] = bpmem.indmtx[matrixidx].col2.mf * fscale;
+	constants.indtexmtx[2*matrixidx+1][3] = fscale * 4.0f;
+	dirty = true;
+
+	PRIM_LOG("indmtx%d: scale=%f, mat=(%f %f %f; %f %f %f)\n",
+			matrixidx, 1024.0f*fscale,
+			bpmem.indmtx[matrixidx].col0.ma * fscale, bpmem.indmtx[matrixidx].col1.mc * fscale, bpmem.indmtx[matrixidx].col2.me * fscale,
+		bpmem.indmtx[matrixidx].col0.mb * fscale, bpmem.indmtx[matrixidx].col1.md * fscale, bpmem.indmtx[matrixidx].col2.mf * fscale);
+
+}
+
+void ConstantManager::SetZTextureTypeChanged()
+{
+	switch (bpmem.ztex2.type)
+	{
+		case TEV_ZTEX_TYPE_U8:
+			constants.zbias[0][0] = 0;
+			constants.zbias[0][1] = 0;
+			constants.zbias[0][2] = 0;
+			constants.zbias[0][3] = 255.0f/16777215.0f;
+			break;
+		case TEV_ZTEX_TYPE_U16:
+			constants.zbias[0][0] = 255.0f/16777215.0f;
+			constants.zbias[0][1] = 0;
+			constants.zbias[0][2] = 0;
+			constants.zbias[0][3] = 65280.0f/16777215.0f;
+			break;
+		case TEV_ZTEX_TYPE_U24:
+			constants.zbias[0][0] = 16711680.0f/16777215.0f;
+			constants.zbias[0][1] = 65280.0f/16777215.0f;
+			constants.zbias[0][2] = 255.0f/16777215.0f;
+			constants.zbias[0][3] = 0;
+			break;
+		default:
+			break;
+        }
+        dirty = true;
+}
+
+void ConstantManager::SetTexCoordChanged(u8 texmapid)
+{
+	TCoordInfo& tc = bpmem.texcoords[texmapid];
+        constants.texdims[texmapid][2] = tc.s.scale_minus_1 + 1;
+	constants.texdims[texmapid][3] = tc.t.scale_minus_1 + 1;
+	dirty = true;
+}
+
+void ConstantManager::SetFogColorChanged()
+{
+	constants.fog[0][0] = bpmem.fog.color.r / 255.0f;
+	constants.fog[0][1] = bpmem.fog.color.g / 255.0f;
+	constants.fog[0][2] = bpmem.fog.color.b / 255.0f;
+	dirty = true;
+}
+
+void ConstantManager::SetFogParamChanged()
+{
+	if(!g_ActiveConfig.bDisableFog)
+	{
+		constants.fog[1][0] = bpmem.fog.a.GetA();
+		constants.fog[1][1] = (float)bpmem.fog.b_magnitude / 0xFFFFFF;
+		constants.fog[1][2] = bpmem.fog.c_proj_fsel.GetC();
+		constants.fog[1][3] = 1 << bpmem.fog.b_shift;
+	}
+	else
+	{
+		constants.fog[1][0] = 0;
+		constants.fog[1][1] = 1;
+		constants.fog[1][2] = 0;
+		constants.fog[1][3] = 1;
+	}
+	dirty = true;
+}
+
+void ConstantManager::SetFogRangeAdjustChanged()
+{
+	s_bFogRangeAdjustChanged = true;
+}
+
+void ConstantManager::InvalidateXFRange(int start, int end)
+{
+	if (((u32)start >= (u32)MatrixIndexA.PosNormalMtxIdx * 4 &&
+		 (u32)start <  (u32)MatrixIndexA.PosNormalMtxIdx * 4 + 12) ||
+		((u32)start >= XFMEM_NORMALMATRICES + ((u32)MatrixIndexA.PosNormalMtxIdx & 31) * 3 &&
+		 (u32)start <  XFMEM_NORMALMATRICES + ((u32)MatrixIndexA.PosNormalMtxIdx & 31) * 3 + 9))
+	{
+		bPosNormalMatrixChanged = true;
+	}
+
+	if (((u32)start >= (u32)MatrixIndexA.Tex0MtxIdx*4 && (u32)start < (u32)MatrixIndexA.Tex0MtxIdx*4+12) ||
+		((u32)start >= (u32)MatrixIndexA.Tex1MtxIdx*4 && (u32)start < (u32)MatrixIndexA.Tex1MtxIdx*4+12) ||
+		((u32)start >= (u32)MatrixIndexA.Tex2MtxIdx*4 && (u32)start < (u32)MatrixIndexA.Tex2MtxIdx*4+12) ||
+		((u32)start >= (u32)MatrixIndexA.Tex3MtxIdx*4 && (u32)start < (u32)MatrixIndexA.Tex3MtxIdx*4+12))
+	{
+		bTexMatricesChanged[0] = true;
+	}
+
+	if (((u32)start >= (u32)MatrixIndexB.Tex4MtxIdx*4 && (u32)start < (u32)MatrixIndexB.Tex4MtxIdx*4+12) ||
+		((u32)start >= (u32)MatrixIndexB.Tex5MtxIdx*4 && (u32)start < (u32)MatrixIndexB.Tex5MtxIdx*4+12) ||
+		((u32)start >= (u32)MatrixIndexB.Tex6MtxIdx*4 && (u32)start < (u32)MatrixIndexB.Tex6MtxIdx*4+12) ||
+		((u32)start >= (u32)MatrixIndexB.Tex7MtxIdx*4 && (u32)start < (u32)MatrixIndexB.Tex7MtxIdx*4+12))
+	{
+		bTexMatricesChanged[1] = true;
+	}
+
+	if (start < XFMEM_POSMATRICES_END)
+	{
+		if (nTransformMatricesChanged[0] == -1)
+		{
+			nTransformMatricesChanged[0] = start;
+			nTransformMatricesChanged[1] = end>XFMEM_POSMATRICES_END?XFMEM_POSMATRICES_END:end;
+		}
+		else
+		{
+			if (nTransformMatricesChanged[0] > start) nTransformMatricesChanged[0] = start;
+			if (nTransformMatricesChanged[1] < end) nTransformMatricesChanged[1] = end>XFMEM_POSMATRICES_END?XFMEM_POSMATRICES_END:end;
+		}
+	}
+
+	if (start < XFMEM_NORMALMATRICES_END && end > XFMEM_NORMALMATRICES)
+	{
+		int _start = start < XFMEM_NORMALMATRICES ? 0 : start-XFMEM_NORMALMATRICES;
+		int _end = end < XFMEM_NORMALMATRICES_END ? end-XFMEM_NORMALMATRICES : XFMEM_NORMALMATRICES_END-XFMEM_NORMALMATRICES;
+
+		if (nNormalMatricesChanged[0] == -1)
+		{
+			nNormalMatricesChanged[0] = _start;
+			nNormalMatricesChanged[1] = _end;
+		}
+		else
+		{
+			if (nNormalMatricesChanged[0] > _start) nNormalMatricesChanged[0] = _start;
+			if (nNormalMatricesChanged[1] < _end) nNormalMatricesChanged[1] = _end;
+		}
+	}
+
+	if (start < XFMEM_POSTMATRICES_END && end > XFMEM_POSTMATRICES)
+	{
+		int _start = start < XFMEM_POSTMATRICES ? XFMEM_POSTMATRICES : start-XFMEM_POSTMATRICES;
+		int _end = end < XFMEM_POSTMATRICES_END ? end-XFMEM_POSTMATRICES : XFMEM_POSTMATRICES_END-XFMEM_POSTMATRICES;
+
+		if (nPostTransformMatricesChanged[0] == -1)
+		{
+			nPostTransformMatricesChanged[0] = _start;
+			nPostTransformMatricesChanged[1] = _end;
+		}
+		else
+		{
+			if (nPostTransformMatricesChanged[0] > _start) nPostTransformMatricesChanged[0] = _start;
+			if (nPostTransformMatricesChanged[1] < _end) nPostTransformMatricesChanged[1] = _end;
+		}
+	}
+
+	if (start < XFMEM_LIGHTS_END && end > XFMEM_LIGHTS)
+	{
+		int _start = start < XFMEM_LIGHTS ? XFMEM_LIGHTS : start-XFMEM_LIGHTS;
+		int _end = end < XFMEM_LIGHTS_END ? end-XFMEM_LIGHTS : XFMEM_LIGHTS_END-XFMEM_LIGHTS;
+
+		if (nLightsChanged[0] == -1 )
+		{
+			nLightsChanged[0] = _start;
+			nLightsChanged[1] = _end;
+		}
+		else
+		{
+			if (nLightsChanged[0] > _start) nLightsChanged[0] = _start;
+			if (nLightsChanged[1] < _end)   nLightsChanged[1] = _end;
+		}
+	}
+}
+
+void ConstantManager::SetTexMatrixChangedA(u32 Value)
+{
+	if (MatrixIndexA.Hex != Value)
+	{
+		VertexManager::Flush();
+		if (MatrixIndexA.PosNormalMtxIdx != (Value&0x3f))
+			bPosNormalMatrixChanged = true;
+		bTexMatricesChanged[0] = true;
+		MatrixIndexA.Hex = Value;
+	}
+}
+
+void ConstantManager::SetTexMatrixChangedB(u32 Value)
+{
+	if (MatrixIndexB.Hex != Value)
+	{
+		VertexManager::Flush();
+		bTexMatricesChanged[1] = true;
+		MatrixIndexB.Hex = Value;
+	}
+}
+void ConstantManager::SetProjectionChanged()
+{
+	bProjectionChanged = true;
+}
+
+void ConstantManager::TranslateView(float x, float y, float z)
+{
+	float result[3];
+	float vector[3] = { x,z,y };
+
+	Matrix33::Multiply(s_viewInvRotationMatrix, vector, result);
+
+	for (int i = 0; i < 3; i++)
+		s_fViewTranslationVector[i] += result[i];
+
+	bProjectionChanged = true;
+}
+
+void ConstantManager::RotateView(float x, float y)
+{
+	s_fViewRotation[0] += x;
+	s_fViewRotation[1] += y;
+
+	Matrix33 mx;
+	Matrix33 my;
+	Matrix33::RotateX(mx, s_fViewRotation[1]);
+	Matrix33::RotateY(my, s_fViewRotation[0]);
+	Matrix33::Multiply(mx, my, s_viewRotationMatrix);
+
+	// reverse rotation
+	Matrix33::RotateX(mx, -s_fViewRotation[1]);
+	Matrix33::RotateY(my, -s_fViewRotation[0]);
+	Matrix33::Multiply(my, mx, s_viewInvRotationMatrix);
+
+	bProjectionChanged = true;
+}
+
+void ConstantManager::ResetView()
+{
+	memset(s_fViewTranslationVector, 0, sizeof(s_fViewTranslationVector));
+	Matrix33::LoadIdentity(s_viewRotationMatrix);
+	Matrix33::LoadIdentity(s_viewInvRotationMatrix);
+	s_fViewRotation[0] = s_fViewRotation[1] = 0.0f;
+
+	bProjectionChanged = true;
+}
+
+
+void ConstantManager::SetMaterialColorChanged(int index, u32 color)
+{
+	constants.materials[index][0] = ((color >> 24) & 0xFF) / 255.0f;
+	constants.materials[index][1] = ((color >> 16) & 0xFF) / 255.0f;
+	constants.materials[index][2] = ((color >>  8) & 0xFF) / 255.0f;
+	constants.materials[index][3] = ( color        & 0xFF) / 255.0f;
+	dirty = true;
+}
+
+void ConstantManager::DoState(PointerWrap &p)
+{
+	p.Do(g_fProjectionMatrix);
+	p.Do(s_viewportCorrection);
+	p.Do(s_viewRotationMatrix);
+	p.Do(s_viewInvRotationMatrix);
+	p.Do(s_fViewTranslationVector);
+	p.Do(s_fViewRotation);
+	p.Do(constants);
+	p.Do(dirty);
+
+	if (p.GetMode() == PointerWrap::MODE_READ)
+	{
+		Dirty();
+	}
+}
diff --git a/Source/Core/VideoCommon/Src/ConstantManager.h b/Source/Core/VideoCommon/Src/ConstantManager.h
index 3c09c20..41713ff 100644
--- a/Source/Core/VideoCommon/Src/ConstantManager.h
+++ b/Source/Core/VideoCommon/Src/ConstantManager.h
@@ -10,7 +10,7 @@ typedef float float4[4];
 typedef u32 uint4[4];
 typedef s32 int4[4];
 
-struct PixelShaderConstants
+struct Constants
 {
 	float4 colors[4];
 	float4 kcolors[4];
@@ -20,14 +20,7 @@ struct PixelShaderConstants
 	float4 indtexscale[2];
 	float4 indtexmtx[6];
 	float4 fog[3];
-
-	// For pixel lighting
-	float4 plights[40];
-	float4 pmaterials[4];
-};
-
-struct VertexShaderConstants
-{
+	
 	float4 posnormalmatrix[6];
 	float4 projection[4];
 	float4 materials[4];
@@ -39,4 +32,90 @@ struct VertexShaderConstants
 	float4 depthparams;
 };
 
+// shader variables
+#define I_COLORS      "color"
+#define I_KCOLORS     "k"
+#define I_ALPHA       "alphaRef"
+#define I_TEXDIMS     "texdim"
+#define I_ZBIAS       "czbias"
+#define I_INDTEXSCALE "cindscale"
+#define I_INDTEXMTX   "cindmtx"
+#define I_FOG         "cfog"
+
+#define I_POSNORMALMATRIX       "cpnmtx"
+#define I_PROJECTION            "cproj"
+#define I_MATERIALS             "cmtrl"
+#define I_LIGHTS                "clights"
+#define I_TEXMATRICES           "ctexmtx"
+#define I_TRANSFORMMATRICES     "ctrmtx"
+#define I_NORMALMATRICES        "cnmtx"
+#define I_POSTTRANSFORMMATRICES "cpostmtx"
+#define I_DEPTHPARAMS           "cDepth" // farZ, zRange
+
+// TODO: get rid of them as they aren't used
+#define C_COLORMATRIX           0				// 0
+#define C_COLORS                0				// 0
+#define C_KCOLORS               (C_COLORS + 4)			// 4
+#define C_ALPHA                 (C_KCOLORS + 4)			// 8
+#define C_TEXDIMS               (C_ALPHA + 1)			// 9
+#define C_ZBIAS                 (C_TEXDIMS + 8)			//17
+#define C_INDTEXSCALE           (C_ZBIAS + 2)			//19
+#define C_INDTEXMTX             (C_INDTEXSCALE + 2)		//21
+#define C_FOG                   (C_INDTEXMTX + 6)		//27
+
+#define C_POSNORMALMATRIX       (C_FOG + 3)			//30
+#define C_PROJECTION            (C_POSNORMALMATRIX + 6)		//36
+#define C_MATERIALS             (C_PROJECTION + 4)		//40
+#define C_LIGHTS                (C_MATERIALS + 4)		//44
+#define C_TEXMATRICES           (C_LIGHTS + 40)			//84
+#define C_TRANSFORMMATRICES     (C_TEXMATRICES + 24)		//108
+#define C_NORMALMATRICES        (C_TRANSFORMMATRICES + 64)	//172
+#define C_POSTTRANSFORMMATRICES (C_NORMALMATRICES + 32)		//204
+#define C_DEPTHPARAMS           (C_POSTTRANSFORMMATRICES + 64)	//268
+#define C_VENVCONST_END         (C_DEPTHPARAMS + 1)
+
+class ConstantManager
+{
+public:
+	static void Init();
+	static void Dirty();
+	static void Shutdown();
+	static void DoState(PointerWrap &p);
+
+	static void SetConstants(u32 components); // sets pixel shader constants
+
+	// constant management, should be called after memory is committed
+	static void SetColorChanged(int type, int index);
+	static void SetAlpha();
+	static void SetDestAlpha();
+	static void SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt);
+	static void SetZTextureBias();
+	static void SetIndMatrixChanged(int matrixidx);
+	static void SetTevKSelChanged(int id);
+	static void SetZTextureTypeChanged();
+	static void SetIndTexScaleChanged(bool high);
+	static void SetTexCoordChanged(u8 texmapid);
+	static void SetFogColorChanged();
+	static void SetFogParamChanged();
+	static void SetFogRangeAdjustChanged();
+	
+	static void InvalidateXFRange(int start, int end);
+	static void SetTexMatrixChangedA(u32 value);
+	static void SetTexMatrixChangedB(u32 value);
+	static void SetViewportChanged();
+	static void SetProjectionChanged();
+	static void SetMaterialColorChanged(int index, u32 color);
+
+	static void TranslateView(float x, float y, float z = 0.0f);
+	static void RotateView(float x, float y);
+	static void ResetView();
+
+	static Constants constants;
+	static bool dirty;
+};
+
+
+// WTF does this here?
+void UpdateProjectionHack(int iParams[], std::string sParams[]);
+
 #endif
\ No newline at end of file
diff --git a/Source/Core/VideoCommon/Src/EmuWindow.cpp b/Source/Core/VideoCommon/Src/EmuWindow.cpp
index 9b8cde5..43cc6cb 100644
--- a/Source/Core/VideoCommon/Src/EmuWindow.cpp
+++ b/Source/Core/VideoCommon/Src/EmuWindow.cpp
@@ -7,7 +7,7 @@
 #include "VideoConfig.h"
 #include "EmuWindow.h"
 #include "Fifo.h"
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 #include "VideoBackendBase.h"
 #include "Core.h"
 #include "Host.h"
@@ -54,7 +54,7 @@ void FreeLookInput( UINT iMsg, WPARAM wParam )
 		if (mouseLookEnabled)
 		{
 			GetCursorPos(&point);
-			VertexShaderManager::RotateView((point.x - lastMouse[0]) / 200.0f, (point.y - lastMouse[1]) / 200.0f);
+			ConstantManager::RotateView((point.x - lastMouse[0]) / 200.0f, (point.y - lastMouse[1]) / 200.0f);
 			lastMouse[0] = (float)point.x;
 			lastMouse[1] = (float)point.y;
 		}
@@ -62,7 +62,7 @@ void FreeLookInput( UINT iMsg, WPARAM wParam )
 		if (mouseMoveEnabled)
 		{
 			GetCursorPos(&point);
-			VertexShaderManager::TranslateView((point.x - lastMouse[0]) / 50.0f, (point.y - lastMouse[1]) / 50.0f);
+			ConstantManager::TranslateView((point.x - lastMouse[0]) / 50.0f, (point.y - lastMouse[1]) / 50.0f);
 			lastMouse[0] = (float)point.x;
 			lastMouse[1] = (float)point.y;
 		}
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
index 442cfc1..613caf3 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
@@ -16,6 +16,7 @@
 #include "BPMemory.h"
 #include "VideoConfig.h"
 #include "NativeVertexFormat.h"
+#include "ConstantManager.h"
 
 
 //   old tev->pixelshader notes
@@ -284,7 +285,7 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
 	out.Write("\n");
 
 	if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
-		out.Write("layout(std140) uniform PSBlock {\n");
+		out.Write("layout(std140) uniform CBlock {\n");
 
 	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_COLORS, "float4", I_COLORS"[4]");
 	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_KCOLORS, "float4", I_KCOLORS"[4]");
@@ -295,9 +296,15 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
 	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_INDTEXMTX, "float4", I_INDTEXMTX"[6]");
 	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_FOG, "float4", I_FOG"[3]");
 
-	// For pixel lighting - TODO: Should only be defined when per pixel lighting is enabled!
-	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_PLIGHTS, "float4", I_PLIGHTS"[40]");
-	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_PMATERIALS, "float4", I_PMATERIALS"[4]");
+	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_POSNORMALMATRIX, "float4", I_POSNORMALMATRIX"[6]");
+	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_PROJECTION, "float4", I_PROJECTION"[4]");
+	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_MATERIALS, "float4", I_MATERIALS"[4]");
+	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_LIGHTS,  "float4", I_LIGHTS"[40]");
+	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_TEXMATRICES, "float4", I_TEXMATRICES"[24]");
+	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_TRANSFORMMATRICES, "float4", I_TRANSFORMMATRICES"[64]");
+	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_NORMALMATRICES, "float4", I_NORMALMATRICES"[32]");
+	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_POSTTRANSFORMMATRICES, "float4", I_POSTTRANSFORMMATRICES"[64]");
+	DeclareUniform(out, ApiType, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_DEPTHPARAMS, "float4", I_DEPTHPARAMS);
 
 	if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
 		out.Write("};\n");
@@ -411,10 +418,10 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T
 				"\tfloat3 ldir, h;\n"
 				"\tfloat dist, dist2, attn;\n");
 
-		out.SetConstantsUsed(C_PLIGHTS, C_PLIGHTS+39); // TODO: Can be optimized further
-		out.SetConstantsUsed(C_PMATERIALS, C_PMATERIALS+3);
+		out.SetConstantsUsed(C_LIGHTS, C_LIGHTS+39); // TODO: Can be optimized further
+		out.SetConstantsUsed(C_MATERIALS, C_MATERIALS+3);
 		uid_data.components = components;
-		GenerateLightingShader<T>(out, uid_data.lighting, components, I_PMATERIALS, I_PLIGHTS, "colors_", "colors_");
+		GenerateLightingShader<T>(out, uid_data.lighting, components, I_MATERIALS, I_LIGHTS, "colors_", "colors_");
 	}
 
 	out.Write("\tclipPos = float4(rawpos.x, rawpos.y, clipPos.z, clipPos.w);\n");
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h
index 983e304..3613e64 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.h
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h
@@ -10,32 +10,6 @@
 #include "BPMemory.h"
 #include "LightingShaderGen.h"
 
-#define I_COLORS      "color"
-#define I_KCOLORS     "k"
-#define I_ALPHA       "alphaRef"
-#define I_TEXDIMS     "texdim"
-#define I_ZBIAS       "czbias"
-#define I_INDTEXSCALE "cindscale"
-#define I_INDTEXMTX   "cindmtx"
-#define I_FOG         "cfog"
-#define I_PLIGHTS     "cPLights"
-#define I_PMATERIALS  "cPmtrl"
-
-// TODO: get rid of them as they aren't used
-#define C_COLORMATRIX	0						// 0
-#define C_COLORS		0						// 0
-#define C_KCOLORS		(C_COLORS + 4)			// 4
-#define C_ALPHA			(C_KCOLORS + 4)			// 8
-#define C_TEXDIMS		(C_ALPHA + 1)			// 9
-#define C_ZBIAS			(C_TEXDIMS + 8)			//17
-#define C_INDTEXSCALE	(C_ZBIAS + 2)			//19
-#define C_INDTEXMTX		(C_INDTEXSCALE + 2)		//21
-#define C_FOG			(C_INDTEXMTX + 6)		//27
-
-#define C_PLIGHTS		(C_FOG + 3)
-#define C_PMATERIALS	(C_PLIGHTS + 40)
-#define C_PENVCONST_END (C_PMATERIALS + 4)
-
 // Different ways to achieve rendering with destination alpha
 enum DSTALPHA_MODE
 {
diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp
deleted file mode 100644
index b999ada..0000000
--- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp
+++ /dev/null
@@ -1,344 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#include <cmath>
-
-#include "Common.h"
-#include "Statistics.h"
-#include "PixelShaderManager.h"
-#include "VideoCommon.h"
-#include "VideoConfig.h"
-
-#include "RenderBase.h"
-static bool s_bFogRangeAdjustChanged;
-static bool s_bViewPortChanged;
-static int nLightsChanged[2]; // min,max
-
-PixelShaderConstants PixelShaderManager::constants;
-bool PixelShaderManager::dirty;
-
-void PixelShaderManager::Init()
-{
-	memset(&constants, 0, sizeof(constants));
-	Dirty();
-}
-
-void PixelShaderManager::Dirty()
-{
-	s_bFogRangeAdjustChanged = true;
-	s_bViewPortChanged = true;
-	nLightsChanged[0] = 0; nLightsChanged[1] = 0x80;
-
-	SetColorChanged(0, 0);
-	SetColorChanged(0, 1);
-	SetColorChanged(0, 2);
-	SetColorChanged(0, 3);
-	SetColorChanged(1, 0);
-	SetColorChanged(1, 1);
-	SetColorChanged(1, 2);
-	SetColorChanged(1, 3);
-	SetAlpha();
-	SetDestAlpha();
-	SetZTextureBias();
-	SetViewportChanged();
-	SetIndTexScaleChanged(false);
-	SetIndTexScaleChanged(true);
-	SetIndMatrixChanged(0);
-	SetIndMatrixChanged(1);
-	SetIndMatrixChanged(2);
-	SetZTextureTypeChanged();
-	SetTexCoordChanged(0);
-	SetTexCoordChanged(1);
-	SetTexCoordChanged(2);
-	SetTexCoordChanged(3);
-	SetTexCoordChanged(4);
-	SetTexCoordChanged(5);
-	SetTexCoordChanged(6);
-	SetTexCoordChanged(7);
-	SetFogColorChanged();
-	SetFogParamChanged();
-}
-
-void PixelShaderManager::Shutdown()
-{
-
-}
-
-void PixelShaderManager::SetConstants(u32 components)
-{
-	if (s_bFogRangeAdjustChanged)
-	{
-		// set by two components, so keep changed flag here
-		// TODO: try to split both registers and move this logic to the shader
-		if(!g_ActiveConfig.bDisableFog && bpmem.fogRange.Base.Enabled == 1)
-		{
-			//bpmem.fogRange.Base.Center : center of the viewport in x axis. observation: bpmem.fogRange.Base.Center = realcenter + 342;
-			int center = ((u32)bpmem.fogRange.Base.Center) - 342;
-			// normalize center to make calculations easy
-			float ScreenSpaceCenter = center / (2.0f * xfregs.viewport.wd);
-			ScreenSpaceCenter = (ScreenSpaceCenter * 2.0f) - 1.0f;
-			//bpmem.fogRange.K seems to be  a table of precalculated coefficients for the adjust factor
-			//observations: bpmem.fogRange.K[0].LO appears to be the lowest value and bpmem.fogRange.K[4].HI the largest
-			// they always seems to be larger than 256 so my theory is :
-			// they are the coefficients from the center to the border of the screen
-			// so to simplify I use the hi coefficient as K in the shader taking 256 as the scale
-			constants.fog[2][0] = ScreenSpaceCenter;
-			constants.fog[2][1] = Renderer::EFBToScaledX((int)(2.0f * xfregs.viewport.wd));
-			constants.fog[2][2] = bpmem.fogRange.K[4].HI / 256.0f;
-		}
-		else
-		{
-			constants.fog[2][0] = 0;
-			constants.fog[2][1] = 1;
-			constants.fog[2][2] = 1;
-		}
-		dirty = true;
-
-		s_bFogRangeAdjustChanged = false;
-	}
-
-	if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)  // config check added because the code in here was crashing for me inside SetPSConstant4f
-	{
-		if (nLightsChanged[0] >= 0)
-		{
-			// lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats
-			int istart = nLightsChanged[0] / 0x10;
-			int iend = (nLightsChanged[1] + 15) / 0x10;
-			const float* xfmemptr = (const float*)&xfmem[0x10 * istart + XFMEM_LIGHTS];
-
-			for (int i = istart; i < iend; ++i)
-			{
-				u32 color = *(const u32*)(xfmemptr + 3);
-				constants.plights[5*i][0] = ((color >> 24) & 0xFF) / 255.0f;
-				constants.plights[5*i][1] = ((color >> 16) & 0xFF) / 255.0f;
-				constants.plights[5*i][2] = ((color >> 8)  & 0xFF) / 255.0f;
-				constants.plights[5*i][3] = ((color)       & 0xFF) / 255.0f;
-				xfmemptr += 4;
-
-				for (int j = 0; j < 4; ++j, xfmemptr += 3)
-				{
-					if (j == 1 &&
-						fabs(xfmemptr[0]) < 0.00001f &&
-						fabs(xfmemptr[1]) < 0.00001f &&
-						fabs(xfmemptr[2]) < 0.00001f)
-						// dist attenuation, make sure not equal to 0!!!
-						constants.plights[5*i+j+1][0] = 0.00001f;
-					else
-						constants.plights[5*i+j+1][0] = xfmemptr[0];
-					constants.plights[5*i+j+1][1] = xfmemptr[1];
-					constants.plights[5*i+j+1][2] = xfmemptr[2];
-				}
-			}
-			dirty = true;
-
-			nLightsChanged[0] = nLightsChanged[1] = -1;
-		}
-	}
-
-	if(s_bViewPortChanged)
-	{
-		constants.zbias[1][0] = xfregs.viewport.farZ / 16777216.0f;
-		constants.zbias[1][1] = xfregs.viewport.zRange / 16777216.0f;
-		dirty = true;
-	}
-}
-
-// This one is high in profiles (0.5%).
-// TODO: Move conversion out, only store the raw color value
-// and update it when the shader constant is set, only.
-// TODO: Conversion should be checked in the context of tev_fixes..
-void PixelShaderManager::SetColorChanged(int type, int num)
-{
-	float4* c = type ? constants.kcolors : constants.colors;
-	c[num][0] = bpmem.tevregs[num].low.a / 255.0f;
-	c[num][3] = bpmem.tevregs[num].low.b / 255.0f;
-	c[num][2] = bpmem.tevregs[num].high.a / 255.0f;
-	c[num][1] = bpmem.tevregs[num].high.b / 255.0f;
-	dirty = true;
-
-	PRIM_LOG("pixel %scolor%d: %f %f %f %f\n", type?"k":"", num, c[num][0], c[num][1], c[num][2], c[num][3]);
-}
-
-void PixelShaderManager::SetAlpha()
-{
-	constants.alpha[0] = bpmem.alpha_test.ref0 / 255.0f;
-	constants.alpha[1] = bpmem.alpha_test.ref1 / 255.0f;
-	dirty = true;
-}
-
-void PixelShaderManager::SetDestAlpha()
-{
-	constants.alpha[3] = bpmem.dstalpha.alpha / 255.0f;
-	dirty = true;
-}
-
-void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt)
-{
-	// TODO: move this check out to callee. There we could just call this function on texture changes
-	// or better, use textureSize() in glsl
-	if(constants.texdims[texmapid][0] != 1.0f/width || constants.texdims[texmapid][1] != 1.0f/height)
-		dirty = true;
-
-	constants.texdims[texmapid][0] = 1.0f/width;
-	constants.texdims[texmapid][1] = 1.0f/height;
-}
-
-void PixelShaderManager::SetZTextureBias()
-{
-	constants.zbias[1][3] = bpmem.ztex1.bias/16777215.0f;
-	dirty = true;
-}
-
-void PixelShaderManager::SetViewportChanged()
-{
-	s_bViewPortChanged = true;
-	s_bFogRangeAdjustChanged = true; // TODO: Shouldn't be necessary with an accurate fog range adjust implementation
-}
-
-void PixelShaderManager::SetIndTexScaleChanged(bool high)
-{
-	constants.indtexscale[high][0] = bpmem.texscale[high].getScaleS(0);
-	constants.indtexscale[high][1] = bpmem.texscale[high].getScaleT(0);
-	constants.indtexscale[high][2] = bpmem.texscale[high].getScaleS(1);
-	constants.indtexscale[high][3] = bpmem.texscale[high].getScaleT(1);
-	dirty = true;
-}
-
-void PixelShaderManager::SetIndMatrixChanged(int matrixidx)
-{
-	int scale = ((u32)bpmem.indmtx[matrixidx].col0.s0 << 0) |
-			((u32)bpmem.indmtx[matrixidx].col1.s1 << 2) |
-			((u32)bpmem.indmtx[matrixidx].col2.s2 << 4);
-	float fscale = powf(2.0f, (float)(scale - 17)) / 1024.0f;
-
-	// xyz - static matrix
-	// TODO w - dynamic matrix scale / 256...... somehow / 4 works better
-	// rev 2972 - now using / 256.... verify that this works
-	constants.indtexmtx[2*matrixidx][0] = bpmem.indmtx[matrixidx].col0.ma * fscale;
-	constants.indtexmtx[2*matrixidx][1] = bpmem.indmtx[matrixidx].col1.mc * fscale;
-	constants.indtexmtx[2*matrixidx][2] = bpmem.indmtx[matrixidx].col2.me * fscale;
-	constants.indtexmtx[2*matrixidx][3] = fscale * 4.0f;
-	constants.indtexmtx[2*matrixidx+1][0] = bpmem.indmtx[matrixidx].col0.mb * fscale;
-	constants.indtexmtx[2*matrixidx+1][1] = bpmem.indmtx[matrixidx].col1.md * fscale;
-	constants.indtexmtx[2*matrixidx+1][2] = bpmem.indmtx[matrixidx].col2.mf * fscale;
-	constants.indtexmtx[2*matrixidx+1][3] = fscale * 4.0f;
-	dirty = true;
-
-	PRIM_LOG("indmtx%d: scale=%f, mat=(%f %f %f; %f %f %f)\n",
-			matrixidx, 1024.0f*fscale,
-			bpmem.indmtx[matrixidx].col0.ma * fscale, bpmem.indmtx[matrixidx].col1.mc * fscale, bpmem.indmtx[matrixidx].col2.me * fscale,
-		bpmem.indmtx[matrixidx].col0.mb * fscale, bpmem.indmtx[matrixidx].col1.md * fscale, bpmem.indmtx[matrixidx].col2.mf * fscale);
-
-}
-
-void PixelShaderManager::SetZTextureTypeChanged()
-{
-	switch (bpmem.ztex2.type)
-	{
-		case TEV_ZTEX_TYPE_U8:
-			constants.zbias[0][0] = 0;
-			constants.zbias[0][1] = 0;
-			constants.zbias[0][2] = 0;
-			constants.zbias[0][3] = 255.0f/16777215.0f;
-			break;
-		case TEV_ZTEX_TYPE_U16:
-			constants.zbias[0][0] = 255.0f/16777215.0f;
-			constants.zbias[0][1] = 0;
-			constants.zbias[0][2] = 0;
-			constants.zbias[0][3] = 65280.0f/16777215.0f;
-			break;
-		case TEV_ZTEX_TYPE_U24:
-			constants.zbias[0][0] = 16711680.0f/16777215.0f;
-			constants.zbias[0][1] = 65280.0f/16777215.0f;
-			constants.zbias[0][2] = 255.0f/16777215.0f;
-			constants.zbias[0][3] = 0;
-			break;
-		default:
-			break;
-        }
-        dirty = true;
-}
-
-void PixelShaderManager::SetTexCoordChanged(u8 texmapid)
-{
-	TCoordInfo& tc = bpmem.texcoords[texmapid];
-        constants.texdims[texmapid][2] = tc.s.scale_minus_1 + 1;
-	constants.texdims[texmapid][3] = tc.t.scale_minus_1 + 1;
-	dirty = true;
-}
-
-void PixelShaderManager::SetFogColorChanged()
-{
-	constants.fog[0][0] = bpmem.fog.color.r / 255.0f;
-	constants.fog[0][1] = bpmem.fog.color.g / 255.0f;
-	constants.fog[0][2] = bpmem.fog.color.b / 255.0f;
-	dirty = true;
-}
-
-void PixelShaderManager::SetFogParamChanged()
-{
-	if(!g_ActiveConfig.bDisableFog)
-	{
-		constants.fog[1][0] = bpmem.fog.a.GetA();
-		constants.fog[1][1] = (float)bpmem.fog.b_magnitude / 0xFFFFFF;
-		constants.fog[1][2] = bpmem.fog.c_proj_fsel.GetC();
-		constants.fog[1][3] = 1 << bpmem.fog.b_shift;
-	}
-	else
-	{
-		constants.fog[1][0] = 0;
-		constants.fog[1][1] = 1;
-		constants.fog[1][2] = 0;
-		constants.fog[1][3] = 1;
-	}
-	dirty = true;
-}
-
-void PixelShaderManager::SetFogRangeAdjustChanged()
-{
-	s_bFogRangeAdjustChanged = true;
-}
-
-void PixelShaderManager::InvalidateXFRange(int start, int end)
-{
-	if (start < XFMEM_LIGHTS_END && end > XFMEM_LIGHTS)
-	{
-		int _start = start < XFMEM_LIGHTS ? XFMEM_LIGHTS : start-XFMEM_LIGHTS;
-		int _end = end < XFMEM_LIGHTS_END ? end-XFMEM_LIGHTS : XFMEM_LIGHTS_END-XFMEM_LIGHTS;
-
-		if (nLightsChanged[0] == -1 )
-		{
-			nLightsChanged[0] = _start;
-			nLightsChanged[1] = _end;
-		}
-		else
-		{
-			if (nLightsChanged[0] > _start) nLightsChanged[0] = _start;
-			if (nLightsChanged[1] < _end)   nLightsChanged[1] = _end;
-		}
-	}
-}
-
-void PixelShaderManager::SetMaterialColorChanged(int index, u32 color)
-{
-	if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
-	{
-		constants.pmaterials[index][0] = ((color >> 24) & 0xFF) / 255.0f;
-		constants.pmaterials[index][1] = ((color >> 16) & 0xFF) / 255.0f;
-		constants.pmaterials[index][2] = ((color >>  8) & 0xFF) / 255.0f;
-		constants.pmaterials[index][3] = ( color        & 0xFF) / 255.0f;
-		dirty = true;
-	}
-}
-
-void PixelShaderManager::DoState(PointerWrap &p)
-{
-	p.Do(constants);
-	p.Do(dirty);
-
-	if (p.GetMode() == PointerWrap::MODE_READ)
-	{
-		Dirty();
-	}
-}
diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.h b/Source/Core/VideoCommon/Src/PixelShaderManager.h
deleted file mode 100644
index d0c3509..0000000
--- a/Source/Core/VideoCommon/Src/PixelShaderManager.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#ifndef _PIXELSHADERMANAGER_H
-#define _PIXELSHADERMANAGER_H
-
-#include "BPMemory.h"
-#include "XFMemory.h"
-#include "PixelShaderGen.h"
-#include "ConstantManager.h"
-
-class PointerWrap;
-
-
-
-// The non-API dependent parts.
-class PixelShaderManager
-{
-public:
-	static void Init();
-	static void Dirty();
-	static void Shutdown();
-	static void DoState(PointerWrap &p);
-
-	static void SetConstants(u32 components); // sets pixel shader constants
-
-	// constant management, should be called after memory is committed
-	static void SetColorChanged(int type, int index);
-	static void SetAlpha();
-	static void SetDestAlpha();
-	static void SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt);
-	static void SetZTextureBias();
-	static void SetViewportChanged();
-	static void SetIndMatrixChanged(int matrixidx);
-	static void SetTevKSelChanged(int id);
-	static void SetZTextureTypeChanged();
-	static void SetIndTexScaleChanged(bool high);
-	static void SetTexCoordChanged(u8 texmapid);
-	static void SetFogColorChanged();
-	static void SetFogParamChanged();
-	static void SetFogRangeAdjustChanged();
-	static void InvalidateXFRange(int start, int end);
-	static void SetMaterialColorChanged(int index, u32 color);
-
-	static PixelShaderConstants constants;
-	static bool dirty;
-};
-
-
-#endif // _PIXELSHADERMANAGER_H
diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
index 99e9f70..eb63035 100644
--- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
+++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
@@ -16,6 +16,7 @@
 #include "BPMemory.h"
 #include "RenderBase.h"
 #include "VideoConfig.h"
+#include "ConstantManager.h"
 
 #define WRITE p+=sprintf
 
diff --git a/Source/Core/VideoCommon/Src/VertexLoaderManager.cpp b/Source/Core/VideoCommon/Src/VertexLoaderManager.cpp
index 9ad3e01..e25f736 100644
--- a/Source/Core/VideoCommon/Src/VertexLoaderManager.cpp
+++ b/Source/Core/VideoCommon/Src/VertexLoaderManager.cpp
@@ -9,7 +9,7 @@
 #include "VideoCommon.h"
 #include "Statistics.h"
 
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 #include "VertexLoader.h"
 #include "VertexLoaderManager.h"
 #include "HW/Memmap.h"
@@ -148,11 +148,11 @@ void LoadCPReg(u32 sub_cmd, u32 value)
 	switch (sub_cmd & 0xF0)
 	{
 	case 0x30:
-		VertexShaderManager::SetTexMatrixChangedA(value);
+		ConstantManager::SetTexMatrixChangedA(value);
 		break;
 
 	case 0x40:
-		VertexShaderManager::SetTexMatrixChangedB(value);
+		ConstantManager::SetTexMatrixChangedB(value);
 		break;
 
 	case 0x50:
diff --git a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp
index b586ad1..851d51b 100644
--- a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp
+++ b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp
@@ -4,8 +4,7 @@
 #include "Statistics.h"
 #include "OpcodeDecoding.h"
 #include "IndexGenerator.h"
-#include "VertexShaderManager.h"
-#include "PixelShaderManager.h"
+#include "ConstantManager.h"
 #include "NativeVertexFormat.h"
 #include "TextureCacheBase.h"
 #include "RenderBase.h"
@@ -217,7 +216,7 @@ void VertexManager::Flush()
 			if (tentry)
 			{
 				// 0s are probably for no manual wrapping needed.
-				PixelShaderManager::SetTexDims(i, tentry->nativeW, tentry->nativeH, 0, 0);
+				ConstantManager::SetTexDims(i, tentry->nativeW, tentry->nativeH, 0, 0);
 			}
 			else
 			{
@@ -227,8 +226,7 @@ void VertexManager::Flush()
 	}
 
 	// set global constants
-	VertexShaderManager::SetConstants();
-	PixelShaderManager::SetConstants();
+	ConstantManager::SetConstants();
 
 	// finally bind
 	if (false == PixelShaderCache::SetShader(false, g_nativeVertexFmt->m_components))
diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
index f36f857..26c47a8 100644
--- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
@@ -16,6 +16,7 @@
 #include "LightingShaderGen.h"
 #include "VertexShaderGen.h"
 #include "VideoConfig.h"
+#include "ConstantManager.h"
 
 static char text[16768];
 
@@ -84,7 +85,16 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
 
 	// uniforms
 	if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
-		out.Write("layout(std140) uniform VSBlock {\n");
+		out.Write("layout(std140) uniform CBlock {\n");
+
+	DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_COLORS, "float4", I_COLORS"[4]");
+	DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_KCOLORS, "float4", I_KCOLORS"[4]");
+	DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_ALPHA, "float4", I_ALPHA"[1]");  // TODO: Why is this an array...-.-
+	DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_TEXDIMS, "float4", I_TEXDIMS"[8]");
+	DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_ZBIAS, "float4", I_ZBIAS"[2]");
+	DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_INDTEXSCALE, "float4", I_INDTEXSCALE"[2]");
+	DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_INDTEXMTX, "float4", I_INDTEXMTX"[6]");
+	DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_FOG, "float4", I_FOG"[3]");
 
 	DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_POSNORMALMATRIX, "float4", I_POSNORMALMATRIX"[6]");
 	DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_PROJECTION, "float4", I_PROJECTION"[4]");
diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h
index 378f2cd..71a2ce8 100644
--- a/Source/Core/VideoCommon/Src/VertexShaderGen.h
+++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h
@@ -28,31 +28,6 @@
 #define SHADER_TEXTURE6_ATTRIB  14
 #define SHADER_TEXTURE7_ATTRIB  15
 
-
-
-// shader variables
-#define I_POSNORMALMATRIX       "cpnmtx"
-#define I_PROJECTION            "cproj"
-#define I_MATERIALS             "cmtrl"
-#define I_LIGHTS                "clights"
-#define I_TEXMATRICES           "ctexmtx"
-#define I_TRANSFORMMATRICES     "ctrmtx"
-#define I_NORMALMATRICES        "cnmtx"
-#define I_POSTTRANSFORMMATRICES "cpostmtx"
-#define I_DEPTHPARAMS           "cDepth" // farZ, zRange
-
-//TODO: get rid of them, they aren't used at all
-#define C_POSNORMALMATRIX        0
-#define C_PROJECTION            (C_POSNORMALMATRIX + 6)
-#define C_MATERIALS             (C_PROJECTION + 4)
-#define C_LIGHTS                (C_MATERIALS + 4)
-#define C_TEXMATRICES           (C_LIGHTS + 40)
-#define C_TRANSFORMMATRICES     (C_TEXMATRICES + 24)
-#define C_NORMALMATRICES        (C_TRANSFORMMATRICES + 64)
-#define C_POSTTRANSFORMMATRICES (C_NORMALMATRICES + 32)
-#define C_DEPTHPARAMS           (C_POSTTRANSFORMMATRICES + 64)
-#define C_VENVCONST_END			(C_DEPTHPARAMS + 1)
-
 #pragma pack(1)
 
 struct vertex_shader_uid_data
diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp
deleted file mode 100644
index 5ec371a..0000000
--- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp
+++ /dev/null
@@ -1,710 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#include "Common.h"
-#include "VideoConfig.h"
-#include "MathUtil.h"
-
-#include <cmath>
-#include <sstream>
-
-#include "Statistics.h"
-
-#include "VertexShaderGen.h"
-#include "VertexShaderManager.h"
-#include "BPMemory.h"
-#include "CPMemory.h"
-#include "XFMemory.h"
-#include "VideoCommon.h"
-#include "VertexManagerBase.h"
-
-#include "RenderBase.h"
-float GC_ALIGNED16(g_fProjectionMatrix[16]);
-
-// track changes
-static bool bTexMatricesChanged[2], bPosNormalMatrixChanged, bProjectionChanged, bViewportChanged;
-static int nMaterialsChanged;
-static int nTransformMatricesChanged[2]; // min,max
-static int nNormalMatricesChanged[2]; // min,max
-static int nPostTransformMatricesChanged[2]; // min,max
-static int nLightsChanged[2]; // min,max
-
-static Matrix44 s_viewportCorrection;
-static Matrix33 s_viewRotationMatrix;
-static Matrix33 s_viewInvRotationMatrix;
-static float s_fViewTranslationVector[3];
-static float s_fViewRotation[2];
-
-VertexShaderConstants VertexShaderManager::constants;
-bool VertexShaderManager::dirty;
-
-struct ProjectionHack
-{
-	float sign;
-	float value;
-	ProjectionHack() { }
-	ProjectionHack(float new_sign, float new_value)
-		: sign(new_sign), value(new_value) {}
-};
-
-namespace
-{
-// Control Variables
-static ProjectionHack g_ProjHack1;
-static ProjectionHack g_ProjHack2;
-static bool g_ProjHack3;
-} // Namespace
-
-float PHackValue(std::string sValue)
-{
-	float f = 0;
-	bool fp = false;
-	const char *cStr = sValue.c_str();
-	char *c = new char[strlen(cStr)+1];
-	std::istringstream sTof("");
-
-	for (unsigned int i=0; i<=strlen(cStr); ++i)
-	{
-		if (i == 20)
-		{
-			c[i] = '\0';
-			break;
-		}
-
-		c[i] = (cStr[i] == ',') ? '.' : *(cStr+i);
-		if (c[i] == '.')
-			fp = true;
-	}
-
-	cStr = c;
-	sTof.str(cStr);
-	sTof >> f;
-
-	if (!fp)
-		f /= 0xF4240;
-
-	delete [] c;
-	return f;
-}
-
-void UpdateProjectionHack(int iPhackvalue[], std::string sPhackvalue[])
-{
-	float fhackvalue1 = 0, fhackvalue2 = 0;
-	float fhacksign1 = 1.0, fhacksign2 = 1.0;
-	bool bProjHack3 = false;
-	const char *sTemp[2];
-
-	if (iPhackvalue[0] == 1)
-	{
-		NOTICE_LOG(VIDEO, "\t\t--- Orthographic Projection Hack ON ---");
-
-		fhacksign1 *= (iPhackvalue[1] == 1) ? -1.0f : fhacksign1;
-		sTemp[0] = (iPhackvalue[1] == 1) ? " * (-1)" : "";
-		fhacksign2 *= (iPhackvalue[2] == 1) ? -1.0f : fhacksign2;
-		sTemp[1] = (iPhackvalue[2] == 1) ? " * (-1)" : "";
-
-		fhackvalue1 = PHackValue(sPhackvalue[0]);
-		NOTICE_LOG(VIDEO, "- zNear Correction = (%f + zNear)%s", fhackvalue1, sTemp[0]);
-
-		fhackvalue2 = PHackValue(sPhackvalue[1]);
-		NOTICE_LOG(VIDEO, "- zFar Correction =  (%f + zFar)%s", fhackvalue2, sTemp[1]);
-
-		sTemp[0] = "DISABLED";
-		bProjHack3 = (iPhackvalue[3] == 1) ? true : bProjHack3;
-		if (bProjHack3)
-			sTemp[0] = "ENABLED";
-		NOTICE_LOG(VIDEO, "- Extra Parameter: %s", sTemp[0]);
-	}
-
-	// Set the projections hacks
-	g_ProjHack1 = ProjectionHack(fhacksign1, fhackvalue1);
-	g_ProjHack2 = ProjectionHack(fhacksign2, fhackvalue2);
-	g_ProjHack3 = bProjHack3;
-}
-
-
-// Viewport correction:
-// In D3D, the viewport rectangle must fit within the render target.
-// Say you want a viewport at (ix, iy) with size (iw, ih),
-// but your viewport must be clamped at (ax, ay) with size (aw, ah).
-// Just multiply the projection matrix with the following to get the same
-// effect:
-// [   (iw/aw)         0     0    ((iw - 2*(ax-ix)) / aw - 1)   ]
-// [         0   (ih/ah)     0   ((-ih + 2*(ay-iy)) / ah + 1)   ]
-// [         0         0     1                              0   ]
-// [         0         0     0                              1   ]
-static void ViewportCorrectionMatrix(Matrix44& result)
-{
-	int scissorXOff = bpmem.scissorOffset.x * 2;
-	int scissorYOff = bpmem.scissorOffset.y * 2;
-
-	// TODO: ceil, floor or just cast to int?
-	// TODO: Directly use the floats instead of rounding them?
-	float intendedX = xfregs.viewport.xOrig - xfregs.viewport.wd - scissorXOff;
-	float intendedY = xfregs.viewport.yOrig + xfregs.viewport.ht - scissorYOff;
-	float intendedWd = 2.0f * xfregs.viewport.wd;
-	float intendedHt = -2.0f * xfregs.viewport.ht;
-	
-        if (intendedWd < 0.f)
-        {
-                intendedX += intendedWd;
-                intendedWd = -intendedWd;
-        }
-        if (intendedHt < 0.f)
-        {
-                intendedY += intendedHt;
-                intendedHt = -intendedHt;
-        }
-
-	// fit to EFB size
-        float X = (intendedX >= 0.f) ? intendedX : 0.f;
-        float Y = (intendedY >= 0.f) ? intendedY : 0.f;
-        float Wd = (X + intendedWd <= EFB_WIDTH) ? intendedWd : (EFB_WIDTH - X);
-        float Ht = (Y + intendedHt <= EFB_HEIGHT) ? intendedHt : (EFB_HEIGHT - Y);
-	
-	Matrix44::LoadIdentity(result);
-	if (Wd == 0 || Ht == 0)
-		return;
-	
-	result.data[4*0+0] = intendedWd / Wd;
-	result.data[4*0+3] = (intendedWd - 2.f * (X - intendedX)) / Wd - 1.f;
-	result.data[4*1+1] = intendedHt / Ht;
-	result.data[4*1+3] = (-intendedHt + 2.f * (Y - intendedY)) / Ht + 1.f;
-}
-
-void UpdateViewport();
-
-void VertexShaderManager::Init()
-{
-	Dirty();
-
-	memset(&xfregs, 0, sizeof(xfregs));
-	memset(xfmem, 0, sizeof(xfmem));
-	memset(&constants, 0 , sizeof(constants));
-	ResetView();
-
-	// TODO: should these go inside ResetView()?
-	Matrix44::LoadIdentity(s_viewportCorrection);
-	memset(g_fProjectionMatrix, 0, sizeof(g_fProjectionMatrix));
-	for (int i = 0; i < 4; ++i)
-		g_fProjectionMatrix[i*5] = 1.0f;
-}
-
-void VertexShaderManager::Shutdown()
-{
-}
-
-void VertexShaderManager::Dirty()
-{
-	nTransformMatricesChanged[0] = 0;
-	nTransformMatricesChanged[1] = 256;
-
-	nNormalMatricesChanged[0] = 0;
-	nNormalMatricesChanged[1] = 96;
-
-	nPostTransformMatricesChanged[0] = 0;
-	nPostTransformMatricesChanged[1] = 256;
-
-	nLightsChanged[0] = 0;
-	nLightsChanged[1] = 0x80;
-
-	bPosNormalMatrixChanged = true;
-	bTexMatricesChanged[0] = true;
-	bTexMatricesChanged[1] = true;
-
-	bProjectionChanged = true;
-
-	nMaterialsChanged = 15;
-
-	dirty = true;
-}
-
-// Syncs the shader constant buffers with xfmem
-// TODO: A cleaner way to control the matrices without making a mess in the parameters field
-void VertexShaderManager::SetConstants()
-{
-	if (nTransformMatricesChanged[0] >= 0)
-	{
-		int startn = nTransformMatricesChanged[0] / 4;
-		int endn = (nTransformMatricesChanged[1] + 3) / 4;
-		memcpy(constants.transformmatrices[startn], &xfmem[startn * 4], (endn - startn) * 16);
-		dirty = true;
-		nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
-	}
-
-	if (nNormalMatricesChanged[0] >= 0)
-	{
-		int startn = nNormalMatricesChanged[0] / 3;
-		int endn = (nNormalMatricesChanged[1] + 2) / 3;
-		for(int i=startn; i<endn; i++)
-		{
-			memcpy(constants.normalmatrices[i], &xfmem[XFMEM_NORMALMATRICES + 3*i], 12);
-		}
-		dirty = true;
-		nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1;
-	}
-
-	if (nPostTransformMatricesChanged[0] >= 0)
-	{
-		int startn = nPostTransformMatricesChanged[0] / 4;
-		int endn = (nPostTransformMatricesChanged[1] + 3 ) / 4;
-		memcpy(constants.posttransformmatrices[startn], &xfmem[XFMEM_POSTMATRICES + startn * 4], (endn - startn) * 16);
-		dirty = true;
-		nPostTransformMatricesChanged[0] = nPostTransformMatricesChanged[1] = -1;
-	}
-
-	if (nLightsChanged[0] >= 0)
-	{
-		// lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats
-		int istart = nLightsChanged[0] / 0x10;
-		int iend = (nLightsChanged[1] + 15) / 0x10;
-		const float* xfmemptr = (const float*)&xfmem[0x10 * istart + XFMEM_LIGHTS];
-
-		for (int i = istart; i < iend; ++i)
-		{
-			u32 color = *(const u32*)(xfmemptr + 3);
-			constants.lights[5*i][0] = ((color >> 24) & 0xFF) / 255.0f;
-			constants.lights[5*i][1] = ((color >> 16) & 0xFF) / 255.0f;
-			constants.lights[5*i][2] = ((color >> 8)  & 0xFF) / 255.0f;
-			constants.lights[5*i][3] = ((color)       & 0xFF) / 255.0f;
-			xfmemptr += 4;
-
-			for (int j = 0; j < 4; ++j, xfmemptr += 3)
-			{
-				if (j == 1 &&
-					fabs(xfmemptr[0]) < 0.00001f &&
-					fabs(xfmemptr[1]) < 0.00001f &&
-					fabs(xfmemptr[2]) < 0.00001f)
-				{
-					// dist attenuation, make sure not equal to 0!!!
-					constants.lights[5*i+j+1][0] = 0.00001f;
-				}
-				else
-					constants.lights[5*i+j+1][0] = xfmemptr[0];
-				constants.lights[5*i+j+1][1] = xfmemptr[1];
-				constants.lights[5*i+j+1][2] = xfmemptr[2];
-			}
-		}
-		dirty = true;
-
-		nLightsChanged[0] = nLightsChanged[1] = -1;
-	}
-
-	if (nMaterialsChanged)
-	{
-		for (int i = 0; i < 2; ++i)
-		{
-			if (nMaterialsChanged & (1 << i))
-			{
-				u32 data = *(xfregs.ambColor + i);
-				constants.materials[i][0] = ((data >> 24) & 0xFF) / 255.0f;
-				constants.materials[i][1] = ((data >> 16) & 0xFF) / 255.0f;
-				constants.materials[i][2] = ((data >>  8) & 0xFF) / 255.0f;
-				constants.materials[i][3] = ( data        & 0xFF) / 255.0f;
-			}
-		}
-
-		for (int i = 0; i < 2; ++i)
-		{
-			if (nMaterialsChanged & (1 << (i + 2)))
-			{
-				u32 data = *(xfregs.matColor + i);
-				constants.materials[i+2][0] = ((data >> 24) & 0xFF) / 255.0f;
-				constants.materials[i+2][1] = ((data >> 16) & 0xFF) / 255.0f;
-				constants.materials[i+2][2] = ((data >>  8) & 0xFF) / 255.0f;
-				constants.materials[i+2][3] = ( data        & 0xFF) / 255.0f;
-			}
-		}
-		dirty = true;
-
-		nMaterialsChanged = 0;
-	}
-
-	if (bPosNormalMatrixChanged)
-	{
-		bPosNormalMatrixChanged = false;
-
-		const float *pos = (const float *)xfmem + MatrixIndexA.PosNormalMtxIdx * 4;
-		const float *norm = (const float *)xfmem + XFMEM_NORMALMATRICES + 3 * (MatrixIndexA.PosNormalMtxIdx & 31);
-
-		memcpy(constants.posnormalmatrix, pos, 3*16);
-		memcpy(constants.posnormalmatrix[3], norm, 12);
-		memcpy(constants.posnormalmatrix[4], norm+3, 12);
-		memcpy(constants.posnormalmatrix[5], norm+6, 12);
-		dirty = true;
-	}
-
-	if (bTexMatricesChanged[0])
-	{
-		bTexMatricesChanged[0] = false;
-		const float *fptrs[] =
-		{
-			(const float *)xfmem + MatrixIndexA.Tex0MtxIdx * 4, (const float *)xfmem + MatrixIndexA.Tex1MtxIdx * 4,
-			(const float *)xfmem + MatrixIndexA.Tex2MtxIdx * 4, (const float *)xfmem + MatrixIndexA.Tex3MtxIdx * 4
-		};
-
-		for (int i = 0; i < 4; ++i)
-		{
-			memcpy(constants.texmatrices[3*i], fptrs[i], 3*16);
-		}
-		dirty = true;
-	}
-
-	if (bTexMatricesChanged[1])
-	{
-		bTexMatricesChanged[1] = false;
-		const float *fptrs[] = {
-			(const float *)xfmem + MatrixIndexB.Tex4MtxIdx * 4, (const float *)xfmem + MatrixIndexB.Tex5MtxIdx * 4,
-			(const float *)xfmem + MatrixIndexB.Tex6MtxIdx * 4, (const float *)xfmem + MatrixIndexB.Tex7MtxIdx * 4
-		};
-
-		for (int i = 0; i < 4; ++i)
-		{
-			memcpy(constants.texmatrices[3*i+12], fptrs[i], 3*16);
-		}
-		dirty = true;
-	}
-
-	if (bViewportChanged)
-	{
-		bViewportChanged = false;
-		constants.depthparams[0] = xfregs.viewport.farZ / 16777216.0f;
-		constants.depthparams[1] = xfregs.viewport.zRange / 16777216.0f;
-		dirty = true;
-		// This is so implementation-dependent that we can't have it here.
-		UpdateViewport();
-		
-		// Update projection if the viewport isn't 1:1 useable
-		if(!g_ActiveConfig.backend_info.bSupportsOversizedViewports)
-		{
-			ViewportCorrectionMatrix(s_viewportCorrection);
-			bProjectionChanged = true;			
-		}
-	}
-
-	if (bProjectionChanged)
-	{
-		bProjectionChanged = false;
-
-		float *rawProjection = xfregs.projection.rawProjection;
-
-		switch(xfregs.projection.type)
-		{
-		case GX_PERSPECTIVE:
-
-			g_fProjectionMatrix[0] = rawProjection[0] * g_ActiveConfig.fAspectRatioHackW;
-			g_fProjectionMatrix[1] = 0.0f;
-			g_fProjectionMatrix[2] = rawProjection[1];
-			g_fProjectionMatrix[3] = 0.0f;
-
-			g_fProjectionMatrix[4] = 0.0f;
-			g_fProjectionMatrix[5] = rawProjection[2] * g_ActiveConfig.fAspectRatioHackH;
-			g_fProjectionMatrix[6] = rawProjection[3];
-			g_fProjectionMatrix[7] = 0.0f;
-
-			g_fProjectionMatrix[8] = 0.0f;
-			g_fProjectionMatrix[9] = 0.0f;
-			g_fProjectionMatrix[10] = rawProjection[4];
-
-			g_fProjectionMatrix[11] = rawProjection[5];
-
-			g_fProjectionMatrix[12] = 0.0f;
-			g_fProjectionMatrix[13] = 0.0f;
-			// donkopunchstania: GC GPU rounds differently?
-			// -(1 + epsilon) so objects are clipped as they are on the real HW
-			g_fProjectionMatrix[14] = -1.00000011921f;
-			g_fProjectionMatrix[15] = 0.0f;
-
-			SETSTAT_FT(stats.gproj_0, g_fProjectionMatrix[0]);
-			SETSTAT_FT(stats.gproj_1, g_fProjectionMatrix[1]);
-			SETSTAT_FT(stats.gproj_2, g_fProjectionMatrix[2]);
-			SETSTAT_FT(stats.gproj_3, g_fProjectionMatrix[3]);
-			SETSTAT_FT(stats.gproj_4, g_fProjectionMatrix[4]);
-			SETSTAT_FT(stats.gproj_5, g_fProjectionMatrix[5]);
-			SETSTAT_FT(stats.gproj_6, g_fProjectionMatrix[6]);
-			SETSTAT_FT(stats.gproj_7, g_fProjectionMatrix[7]);
-			SETSTAT_FT(stats.gproj_8, g_fProjectionMatrix[8]);
-			SETSTAT_FT(stats.gproj_9, g_fProjectionMatrix[9]);
-			SETSTAT_FT(stats.gproj_10, g_fProjectionMatrix[10]);
-			SETSTAT_FT(stats.gproj_11, g_fProjectionMatrix[11]);
-			SETSTAT_FT(stats.gproj_12, g_fProjectionMatrix[12]);
-			SETSTAT_FT(stats.gproj_13, g_fProjectionMatrix[13]);
-			SETSTAT_FT(stats.gproj_14, g_fProjectionMatrix[14]);
-			SETSTAT_FT(stats.gproj_15, g_fProjectionMatrix[15]);
-			break;
-
-		case GX_ORTHOGRAPHIC:
-
-			g_fProjectionMatrix[0] = rawProjection[0];
-			g_fProjectionMatrix[1] = 0.0f;
-			g_fProjectionMatrix[2] = 0.0f;
-			g_fProjectionMatrix[3] = rawProjection[1];
-
-			g_fProjectionMatrix[4] = 0.0f;
-			g_fProjectionMatrix[5] = rawProjection[2];
-			g_fProjectionMatrix[6] = 0.0f;
-			g_fProjectionMatrix[7] = rawProjection[3];
-
-			g_fProjectionMatrix[8] = 0.0f;
-			g_fProjectionMatrix[9] = 0.0f;
-			g_fProjectionMatrix[10] = (g_ProjHack1.value + rawProjection[4]) * ((g_ProjHack1.sign == 0) ? 1.0f : g_ProjHack1.sign);
-			g_fProjectionMatrix[11] = (g_ProjHack2.value + rawProjection[5]) * ((g_ProjHack2.sign == 0) ? 1.0f : g_ProjHack2.sign);
-
-			g_fProjectionMatrix[12] = 0.0f;
-			g_fProjectionMatrix[13] = 0.0f;
-
-			/*
-			projection hack for metroid other m...attempt to remove black projection layer from cut scenes.
-			g_fProjectionMatrix[15] = 1.0f was the default setting before
-			this hack was added...setting g_fProjectionMatrix[14] to -1 might make the hack more stable, needs more testing.
-			Only works for OGL and DX9...this is not helping DX11
-			*/
-
-			g_fProjectionMatrix[14] = 0.0f;
-			g_fProjectionMatrix[15] = (g_ProjHack3 && rawProjection[0] == 2.0f ? 0.0f : 1.0f);  //causes either the efb copy or bloom layer not to show if proj hack enabled
-
-			SETSTAT_FT(stats.g2proj_0, g_fProjectionMatrix[0]);
-			SETSTAT_FT(stats.g2proj_1, g_fProjectionMatrix[1]);
-			SETSTAT_FT(stats.g2proj_2, g_fProjectionMatrix[2]);
-			SETSTAT_FT(stats.g2proj_3, g_fProjectionMatrix[3]);
-			SETSTAT_FT(stats.g2proj_4, g_fProjectionMatrix[4]);
-			SETSTAT_FT(stats.g2proj_5, g_fProjectionMatrix[5]);
-			SETSTAT_FT(stats.g2proj_6, g_fProjectionMatrix[6]);
-			SETSTAT_FT(stats.g2proj_7, g_fProjectionMatrix[7]);
-			SETSTAT_FT(stats.g2proj_8, g_fProjectionMatrix[8]);
-			SETSTAT_FT(stats.g2proj_9, g_fProjectionMatrix[9]);
-			SETSTAT_FT(stats.g2proj_10, g_fProjectionMatrix[10]);
-			SETSTAT_FT(stats.g2proj_11, g_fProjectionMatrix[11]);
-			SETSTAT_FT(stats.g2proj_12, g_fProjectionMatrix[12]);
-			SETSTAT_FT(stats.g2proj_13, g_fProjectionMatrix[13]);
-			SETSTAT_FT(stats.g2proj_14, g_fProjectionMatrix[14]);
-			SETSTAT_FT(stats.g2proj_15, g_fProjectionMatrix[15]);
-			SETSTAT_FT(stats.proj_0, rawProjection[0]);
-			SETSTAT_FT(stats.proj_1, rawProjection[1]);
-			SETSTAT_FT(stats.proj_2, rawProjection[2]);
-			SETSTAT_FT(stats.proj_3, rawProjection[3]);
-			SETSTAT_FT(stats.proj_4, rawProjection[4]);
-			SETSTAT_FT(stats.proj_5, rawProjection[5]);
-			break;
-
-		default:
-			ERROR_LOG(VIDEO, "Unknown projection type: %d", xfregs.projection.type);
-		}
-
-		PRIM_LOG("Projection: %f %f %f %f %f %f\n", rawProjection[0], rawProjection[1], rawProjection[2], rawProjection[3], rawProjection[4], rawProjection[5]);
-
-		if ((g_ActiveConfig.bFreeLook || g_ActiveConfig.bAnaglyphStereo ) && xfregs.projection.type == GX_PERSPECTIVE)
-		{
-			Matrix44 mtxA;
-			Matrix44 mtxB;
-			Matrix44 viewMtx;
-
-			Matrix44::Translate(mtxA, s_fViewTranslationVector);
-			Matrix44::LoadMatrix33(mtxB, s_viewRotationMatrix);
-			Matrix44::Multiply(mtxB, mtxA, viewMtx); // view = rotation x translation
-			Matrix44::Set(mtxB, g_fProjectionMatrix);
-			Matrix44::Multiply(mtxB, viewMtx, mtxA); // mtxA = projection x view
-			Matrix44::Multiply(s_viewportCorrection, mtxA, mtxB); // mtxB = viewportCorrection x mtxA
-			memcpy(constants.projection, mtxB.data, 4*16);
-		}
-		else
-		{
-			Matrix44 projMtx;
-			Matrix44::Set(projMtx, g_fProjectionMatrix);
-
-			Matrix44 correctedMtx;
-			Matrix44::Multiply(s_viewportCorrection, projMtx, correctedMtx);
-			memcpy(constants.projection, correctedMtx.data, 4*16);
-		}
-		dirty = true;
-	}
-}
-
-void VertexShaderManager::InvalidateXFRange(int start, int end)
-{
-	if (((u32)start >= (u32)MatrixIndexA.PosNormalMtxIdx * 4 &&
-		 (u32)start <  (u32)MatrixIndexA.PosNormalMtxIdx * 4 + 12) ||
-		((u32)start >= XFMEM_NORMALMATRICES + ((u32)MatrixIndexA.PosNormalMtxIdx & 31) * 3 &&
-		 (u32)start <  XFMEM_NORMALMATRICES + ((u32)MatrixIndexA.PosNormalMtxIdx & 31) * 3 + 9))
-	{
-		bPosNormalMatrixChanged = true;
-	}
-
-	if (((u32)start >= (u32)MatrixIndexA.Tex0MtxIdx*4 && (u32)start < (u32)MatrixIndexA.Tex0MtxIdx*4+12) ||
-		((u32)start >= (u32)MatrixIndexA.Tex1MtxIdx*4 && (u32)start < (u32)MatrixIndexA.Tex1MtxIdx*4+12) ||
-		((u32)start >= (u32)MatrixIndexA.Tex2MtxIdx*4 && (u32)start < (u32)MatrixIndexA.Tex2MtxIdx*4+12) ||
-		((u32)start >= (u32)MatrixIndexA.Tex3MtxIdx*4 && (u32)start < (u32)MatrixIndexA.Tex3MtxIdx*4+12))
-	{
-		bTexMatricesChanged[0] = true;
-	}
-
-	if (((u32)start >= (u32)MatrixIndexB.Tex4MtxIdx*4 && (u32)start < (u32)MatrixIndexB.Tex4MtxIdx*4+12) ||
-		((u32)start >= (u32)MatrixIndexB.Tex5MtxIdx*4 && (u32)start < (u32)MatrixIndexB.Tex5MtxIdx*4+12) ||
-		((u32)start >= (u32)MatrixIndexB.Tex6MtxIdx*4 && (u32)start < (u32)MatrixIndexB.Tex6MtxIdx*4+12) ||
-		((u32)start >= (u32)MatrixIndexB.Tex7MtxIdx*4 && (u32)start < (u32)MatrixIndexB.Tex7MtxIdx*4+12))
-	{
-		bTexMatricesChanged[1] = true;
-	}
-
-	if (start < XFMEM_POSMATRICES_END)
-	{
-		if (nTransformMatricesChanged[0] == -1)
-		{
-			nTransformMatricesChanged[0] = start;
-			nTransformMatricesChanged[1] = end>XFMEM_POSMATRICES_END?XFMEM_POSMATRICES_END:end;
-		}
-		else
-		{
-			if (nTransformMatricesChanged[0] > start) nTransformMatricesChanged[0] = start;
-			if (nTransformMatricesChanged[1] < end) nTransformMatricesChanged[1] = end>XFMEM_POSMATRICES_END?XFMEM_POSMATRICES_END:end;
-		}
-	}
-
-	if (start < XFMEM_NORMALMATRICES_END && end > XFMEM_NORMALMATRICES)
-	{
-		int _start = start < XFMEM_NORMALMATRICES ? 0 : start-XFMEM_NORMALMATRICES;
-		int _end = end < XFMEM_NORMALMATRICES_END ? end-XFMEM_NORMALMATRICES : XFMEM_NORMALMATRICES_END-XFMEM_NORMALMATRICES;
-
-		if (nNormalMatricesChanged[0] == -1)
-		{
-			nNormalMatricesChanged[0] = _start;
-			nNormalMatricesChanged[1] = _end;
-		}
-		else
-		{
-			if (nNormalMatricesChanged[0] > _start) nNormalMatricesChanged[0] = _start;
-			if (nNormalMatricesChanged[1] < _end) nNormalMatricesChanged[1] = _end;
-		}
-	}
-
-	if (start < XFMEM_POSTMATRICES_END && end > XFMEM_POSTMATRICES)
-	{
-		int _start = start < XFMEM_POSTMATRICES ? XFMEM_POSTMATRICES : start-XFMEM_POSTMATRICES;
-		int _end = end < XFMEM_POSTMATRICES_END ? end-XFMEM_POSTMATRICES : XFMEM_POSTMATRICES_END-XFMEM_POSTMATRICES;
-
-		if (nPostTransformMatricesChanged[0] == -1)
-		{
-			nPostTransformMatricesChanged[0] = _start;
-			nPostTransformMatricesChanged[1] = _end;
-		}
-		else
-		{
-			if (nPostTransformMatricesChanged[0] > _start) nPostTransformMatricesChanged[0] = _start;
-			if (nPostTransformMatricesChanged[1] < _end) nPostTransformMatricesChanged[1] = _end;
-		}
-	}
-
-	if (start < XFMEM_LIGHTS_END && end > XFMEM_LIGHTS)
-	{
-		int _start = start < XFMEM_LIGHTS ? XFMEM_LIGHTS : start-XFMEM_LIGHTS;
-		int _end = end < XFMEM_LIGHTS_END ? end-XFMEM_LIGHTS : XFMEM_LIGHTS_END-XFMEM_LIGHTS;
-
-		if (nLightsChanged[0] == -1 )
-		{
-			nLightsChanged[0] = _start;
-			nLightsChanged[1] = _end;
-		}
-		else
-		{
-			if (nLightsChanged[0] > _start) nLightsChanged[0] = _start;
-			if (nLightsChanged[1] < _end)   nLightsChanged[1] = _end;
-		}
-	}
-}
-
-void VertexShaderManager::SetTexMatrixChangedA(u32 Value)
-{
-	if (MatrixIndexA.Hex != Value)
-	{
-		VertexManager::Flush();
-		if (MatrixIndexA.PosNormalMtxIdx != (Value&0x3f))
-			bPosNormalMatrixChanged = true;
-		bTexMatricesChanged[0] = true;
-		MatrixIndexA.Hex = Value;
-	}
-}
-
-void VertexShaderManager::SetTexMatrixChangedB(u32 Value)
-{
-	if (MatrixIndexB.Hex != Value)
-	{
-		VertexManager::Flush();
-		bTexMatricesChanged[1] = true;
-		MatrixIndexB.Hex = Value;
-	}
-}
-
-void VertexShaderManager::SetViewportChanged()
-{
-	bViewportChanged = true;
-}
-
-void VertexShaderManager::SetProjectionChanged()
-{
-	bProjectionChanged = true;
-}
-
-void VertexShaderManager::SetMaterialColorChanged(int index, u32 color)
-{
-	nMaterialsChanged  |= (1 << index);
-}
-
-void VertexShaderManager::TranslateView(float x, float y, float z)
-{
-	float result[3];
-	float vector[3] = { x,z,y };
-
-	Matrix33::Multiply(s_viewInvRotationMatrix, vector, result);
-
-	for (int i = 0; i < 3; i++)
-		s_fViewTranslationVector[i] += result[i];
-
-	bProjectionChanged = true;
-}
-
-void VertexShaderManager::RotateView(float x, float y)
-{
-	s_fViewRotation[0] += x;
-	s_fViewRotation[1] += y;
-
-	Matrix33 mx;
-	Matrix33 my;
-	Matrix33::RotateX(mx, s_fViewRotation[1]);
-	Matrix33::RotateY(my, s_fViewRotation[0]);
-	Matrix33::Multiply(mx, my, s_viewRotationMatrix);
-
-	// reverse rotation
-	Matrix33::RotateX(mx, -s_fViewRotation[1]);
-	Matrix33::RotateY(my, -s_fViewRotation[0]);
-	Matrix33::Multiply(my, mx, s_viewInvRotationMatrix);
-
-	bProjectionChanged = true;
-}
-
-void VertexShaderManager::ResetView()
-{
-	memset(s_fViewTranslationVector, 0, sizeof(s_fViewTranslationVector));
-	Matrix33::LoadIdentity(s_viewRotationMatrix);
-	Matrix33::LoadIdentity(s_viewInvRotationMatrix);
-	s_fViewRotation[0] = s_fViewRotation[1] = 0.0f;
-
-	bProjectionChanged = true;
-}
-
-void VertexShaderManager::DoState(PointerWrap &p)
-{
-	p.Do(g_fProjectionMatrix);
-	p.Do(s_viewportCorrection);
-	p.Do(s_viewRotationMatrix);
-	p.Do(s_viewInvRotationMatrix);
-	p.Do(s_fViewTranslationVector);
-	p.Do(s_fViewRotation);
-	p.Do(constants);
-	p.Do(dirty);
-
-	if (p.GetMode() == PointerWrap::MODE_READ)
-	{
-		Dirty();
-	}
-}
diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.h b/Source/Core/VideoCommon/Src/VertexShaderManager.h
deleted file mode 100644
index 93287ff..0000000
--- a/Source/Core/VideoCommon/Src/VertexShaderManager.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2013 Dolphin Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#ifndef _VERTEXSHADERMANAGER_H
-#define _VERTEXSHADERMANAGER_H
-
-#include "VertexShaderGen.h"
-#include "ConstantManager.h"
-
-class PointerWrap;
-
-void UpdateProjectionHack(int iParams[], std::string sParams[]);
-
-// The non-API dependent parts.
-class VertexShaderManager
-{
-public:
-	static void Init();
-	static void Dirty();
-	static void Shutdown();
-	static void DoState(PointerWrap &p);
-
-	// constant management
-	static void SetConstants();
-
-	static void InvalidateXFRange(int start, int end);
-	static void SetTexMatrixChangedA(u32 value);
-	static void SetTexMatrixChangedB(u32 value);
-	static void SetViewportChanged();
-	static void SetProjectionChanged();
-	static void SetMaterialColorChanged(int index, u32 color);
-
-	static void TranslateView(float x, float y, float z = 0.0f);
-	static void RotateView(float x, float y);
-	static void ResetView();
-
-	static VertexShaderConstants constants;
-	static bool dirty;
-};
-
-#endif // _VERTEXSHADERMANAGER_H
diff --git a/Source/Core/VideoCommon/Src/VideoState.cpp b/Source/Core/VideoCommon/Src/VideoState.cpp
index 9bfbeea..32795dd 100644
--- a/Source/Core/VideoCommon/Src/VideoState.cpp
+++ b/Source/Core/VideoCommon/Src/VideoState.cpp
@@ -11,8 +11,7 @@
 #include "Fifo.h"
 #include "CommandProcessor.h"
 #include "PixelEngine.h"
-#include "PixelShaderManager.h"
-#include "VertexShaderManager.h"
+#include "ConstantManager.h"
 #include "VertexManagerBase.h"
 
 static void DoState(PointerWrap &p)
@@ -50,11 +49,8 @@ static void DoState(PointerWrap &p)
 	p.DoMarker("PixelEngine");
 
 	// the old way of replaying current bpmem as writes to push side effects to pixel shader manager doesn't really work.
-	PixelShaderManager::DoState(p);
-	p.DoMarker("PixelShaderManager");
-
-	VertexShaderManager::DoState(p);
-	p.DoMarker("VertexShaderManager");
+	ConstantManager::DoState(p);
+	p.DoMarker("ConstantManager");
 
 	VertexManager::DoState(p);
 	p.DoMarker("VertexManager");
diff --git a/Source/Core/VideoCommon/Src/XFStructs.cpp b/Source/Core/VideoCommon/Src/XFStructs.cpp
index 2b9e0d4..ec3c755 100644
--- a/Source/Core/VideoCommon/Src/XFStructs.cpp
+++ b/Source/Core/VideoCommon/Src/XFStructs.cpp
@@ -7,15 +7,13 @@
 #include "XFMemory.h"
 #include "CPMemory.h"
 #include "VertexManagerBase.h"
-#include "VertexShaderManager.h"
-#include "PixelShaderManager.h"
+#include "ConstantManager.h"
 #include "HW/Memmap.h"
 
 void XFMemWritten(u32 transferSize, u32 baseAddress)
 {
 	VertexManager::Flush();
-	VertexShaderManager::InvalidateXFRange(baseAddress, baseAddress + transferSize);
-	PixelShaderManager::InvalidateXFRange(baseAddress, baseAddress + transferSize);
+	ConstantManager::InvalidateXFRange(baseAddress, baseAddress + transferSize);
 }
 
 void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
@@ -60,8 +58,7 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
 				if (xfregs.ambColor[chan] != newValue)
 				{
 					VertexManager::Flush();
-					VertexShaderManager::SetMaterialColorChanged(chan, newValue);
-					PixelShaderManager::SetMaterialColorChanged(chan, newValue);
+					ConstantManager::SetMaterialColorChanged(chan, newValue);
 				}
 				break;
 			}
@@ -73,8 +70,7 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
 				if (xfregs.matColor[chan] != newValue)
 				{
 					VertexManager::Flush();
-					VertexShaderManager::SetMaterialColorChanged(chan + 2, newValue);
-					PixelShaderManager::SetMaterialColorChanged(chan + 2, newValue);
+					ConstantManager::SetMaterialColorChanged(chan + 2, newValue);
 				}
 				break;
 			}
@@ -95,11 +91,11 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
 
 		case XFMEM_SETMATRIXINDA:
 			//_assert_msg_(GX_XF, 0, "XF matrixindex0");
-			VertexShaderManager::SetTexMatrixChangedA(newValue);
+			ConstantManager::SetTexMatrixChangedA(newValue);
 			break;
 		case XFMEM_SETMATRIXINDB:
 			//_assert_msg_(GX_XF, 0, "XF matrixindex1");
-			VertexShaderManager::SetTexMatrixChangedB(newValue);
+			ConstantManager::SetTexMatrixChangedB(newValue);
 			break;
 
 		case XFMEM_SETVIEWPORT:
@@ -109,8 +105,7 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
 		case XFMEM_SETVIEWPORT+4:
 		case XFMEM_SETVIEWPORT+5:
 			VertexManager::Flush();
-			VertexShaderManager::SetViewportChanged();
-			PixelShaderManager::SetViewportChanged();
+			ConstantManager::SetViewportChanged();
 
 			nextAddress = XFMEM_SETVIEWPORT + 6;
 			break;
@@ -123,7 +118,7 @@ void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
 		case XFMEM_SETPROJECTION+5:
 		case XFMEM_SETPROJECTION+6:
 			VertexManager::Flush();
-			VertexShaderManager::SetProjectionChanged();
+			ConstantManager::SetProjectionChanged();
 
 			nextAddress = XFMEM_SETPROJECTION + 7;
 			break;
diff --git a/Source/Core/VideoCommon/VideoCommon.vcxproj b/Source/Core/VideoCommon/VideoCommon.vcxproj
index dd8bbc6..c4e05c8 100644
--- a/Source/Core/VideoCommon/VideoCommon.vcxproj
+++ b/Source/Core/VideoCommon/VideoCommon.vcxproj
@@ -67,7 +67,7 @@
     <ClCompile Include="Src\PerfQueryBase.cpp" />
     <ClCompile Include="Src\PixelEngine.cpp" />
     <ClCompile Include="Src\PixelShaderGen.cpp" />
-    <ClCompile Include="Src\PixelShaderManager.cpp" />
+    <ClCompile Include="Src\ConstantManager.cpp" />
     <ClCompile Include="Src\RenderBase.cpp" />
     <ClCompile Include="Src\Statistics.cpp" />
     <ClCompile Include="Src\stdafx.cpp">
@@ -83,7 +83,6 @@
     <ClCompile Include="Src\VertexLoader_TextCoord.cpp" />
     <ClCompile Include="Src\VertexManagerBase.cpp" />
     <ClCompile Include="Src\VertexShaderGen.cpp" />
-    <ClCompile Include="Src\VertexShaderManager.cpp" />
     <ClCompile Include="Src\VideoBackendBase.cpp" />
     <ClCompile Include="Src\VideoConfig.cpp" />
     <ClCompile Include="Src\VideoState.cpp" />
@@ -121,7 +120,7 @@
     <ClInclude Include="Src\PerfQueryBase.h" />
     <ClInclude Include="Src\PixelEngine.h" />
     <ClInclude Include="Src\PixelShaderGen.h" />
-    <ClInclude Include="Src\PixelShaderManager.h" />
+    <ClInclude Include="Src\ConstantManager.h" />
     <ClInclude Include="Src\RenderBase.h" />
     <ClInclude Include="Src\ShaderGenCommon.h" />
     <ClInclude Include="Src\Statistics.h" />
@@ -137,7 +136,6 @@
     <ClInclude Include="Src\VertexLoader_TextCoord.h" />
     <ClInclude Include="Src\VertexManagerBase.h" />
     <ClInclude Include="Src\VertexShaderGen.h" />
-    <ClInclude Include="Src\VertexShaderManager.h" />
     <ClInclude Include="Src\VideoBackendBase.h" />
     <ClInclude Include="Src\VideoCommon.h" />
     <ClInclude Include="Src\VideoConfig.h" />
@@ -162,4 +160,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/Source/Core/VideoCommon/VideoCommon.vcxproj.filters b/Source/Core/VideoCommon/VideoCommon.vcxproj.filters
index 7d9534f..b9898c3 100644
--- a/Source/Core/VideoCommon/VideoCommon.vcxproj.filters
+++ b/Source/Core/VideoCommon/VideoCommon.vcxproj.filters
@@ -99,10 +99,7 @@
     <ClCompile Include="Src\VertexShaderGen.cpp">
       <Filter>Shader Generators</Filter>
     </ClCompile>
-    <ClCompile Include="Src\PixelShaderManager.cpp">
-      <Filter>Shader Managers</Filter>
-    </ClCompile>
-    <ClCompile Include="Src\VertexShaderManager.cpp">
+    <ClCompile Include="Src\ConstantManager.cpp">
       <Filter>Shader Managers</Filter>
     </ClCompile>
     <ClCompile Include="Src\AVIDump.cpp">
@@ -232,10 +229,7 @@
     <ClInclude Include="Src\VertexShaderGen.h">
       <Filter>Shader Generators</Filter>
     </ClInclude>
-    <ClInclude Include="Src\PixelShaderManager.h">
-      <Filter>Shader Managers</Filter>
-    </ClInclude>
-    <ClInclude Include="Src\VertexShaderManager.h">
+    <ClInclude Include="Src\ConstantManager.h">
       <Filter>Shader Managers</Filter>
     </ClInclude>
     <ClInclude Include="Src\AVIDump.h">
@@ -294,4 +288,4 @@
   <ItemGroup>
     <Text Include="CMakeLists.txt" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>