From ca4726866919aaf6b69d1863bdf59cbc5022797a Mon Sep 17 00:00:00 2001 From: "XTra.KrazzY" Date: Sat, 21 Feb 2009 17:17:24 +0000 Subject: [PATCH] Vertex Shading / Projection Matrix done right (D3D) git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2343 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../VideoCommon/Src/VertexShaderManager.cpp | 4 +- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 56 ++++++++++--------- .../Plugin_VideoDX9/Src/VertexShader.cpp | 7 +-- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index f083fac6eb..4d7eb3ed92 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -199,7 +199,7 @@ void VertexShaderManager::SetConstants(bool proj_hax_1, bool proj_hax_2) static float GC_ALIGNED16(g_fProjectionMatrix[16]); - if (xfregs.rawProjection[6] == 0) { + if (xfregs.rawProjection[6] == 0) { // Model View g_fProjectionMatrix[0] = xfregs.rawProjection[0]; g_fProjectionMatrix[1] = 0.0f; g_fProjectionMatrix[2] = xfregs.rawProjection[1]; @@ -252,7 +252,7 @@ void VertexShaderManager::SetConstants(bool proj_hax_1, bool proj_hax_2) SETSTAT_FT(stats.gproj_14, g_fProjectionMatrix[14]); SETSTAT_FT(stats.gproj_15, g_fProjectionMatrix[15]); } - else { + else { // Orthogonal g_fProjectionMatrix[0] = xfregs.rawProjection[0]; g_fProjectionMatrix[1] = 0.0f; g_fProjectionMatrix[2] = 0.0f; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index ac11f14e52..6b4aa533a4 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -337,48 +337,50 @@ void Renderer::SetScissorBox(RECT &rc) void Renderer::SetProjection(float* pMatrix, int constantIndex) { D3DXMATRIX mtx; - if (pMatrix[6] == 0) + if (pMatrix[6] == 0) // Model View { mtx.m[0][0] = pMatrix[0]; - mtx.m[1][0] = 0.0f; - mtx.m[2][0] = pMatrix[1]; - mtx.m[3][0] = -0.5f/m_width; - mtx.m[0][1] = 0.0f; + mtx.m[0][2] = pMatrix[1]; + mtx.m[0][3] = 0; // -0.5f/m_height; <-- fix d3d pixel center? + + mtx.m[1][0] = 0.0f; mtx.m[1][1] = pMatrix[2]; - mtx.m[2][1] = pMatrix[3]; - mtx.m[3][1] = +0.5f/m_height; + mtx.m[1][2] = pMatrix[3]; + mtx.m[1][3] = 0; // +0.5f/m_height; <-- fix d3d pixel center? - mtx.m[0][2] = 0.0f; - mtx.m[1][2] = 0.0f; - mtx.m[2][2] = -(1-pMatrix[4]); - mtx.m[3][2] = pMatrix[5]; + mtx.m[2][0] = 0.0f; + mtx.m[2][1] = 0.0f; + mtx.m[2][2] = -(1.0f - pMatrix[4]); + mtx.m[2][3] = pMatrix[5]; // Problematic in OGL - mtx.m[0][3] = 0.0f; - mtx.m[1][3] = 0.0f; - mtx.m[2][3] = -1.0f; + mtx.m[3][0] = 0.0f; + mtx.m[3][1] = 0.0f; + // donkopunchstania: GC GPU rounds differently? + // -(1 + epsilon) so objects are clipped as they are on the real HW + mtx.m[3][2] = -1.00000011921f; mtx.m[3][3] = 0.0f; } - else + else // Orthogonal { mtx.m[0][0] = pMatrix[0]; - mtx.m[1][0] = 0.0f; - mtx.m[2][0] = 0.0f; - mtx.m[3][0] = pMatrix[1]-0.5f/m_width; // fix d3d pixel center - mtx.m[0][1] = 0.0f; - mtx.m[1][1] = pMatrix[2]; - mtx.m[2][1] = 0.0f; - mtx.m[3][1] = pMatrix[3]+0.5f/m_height; // fix d3d pixel center - mtx.m[0][2] = 0.0f; + mtx.m[0][3] = pMatrix[1]; // -0.5f/m_width; <-- fix d3d pixel center? + + mtx.m[1][0] = 0.0f; + mtx.m[1][1] = pMatrix[2]; mtx.m[1][2] = 0.0f; + mtx.m[1][3] = pMatrix[3]; // +0.5f/m_height; <-- fix d3d pixel center? + + mtx.m[2][0] = 0.0f; + mtx.m[2][1] = 0.0f; mtx.m[2][2] = pMatrix[4]; - mtx.m[3][2] = -(-1 - pMatrix[5]); + mtx.m[2][3] = -(-1.0f - pMatrix[5]); - mtx.m[0][3] = 0; - mtx.m[1][3] = 0; - mtx.m[2][3] = 0.0f; + mtx.m[3][0] = 0; + mtx.m[3][1] = 0; + mtx.m[3][2] = 0.0f; mtx.m[3][3] = 1.0f; } D3D::dev->SetVertexShaderConstantF(constantIndex, mtx, 4); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexShader.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexShader.cpp index b24250adf5..b459eafb40 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexShader.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexShader.cpp @@ -27,7 +27,7 @@ struct VS_INPUT {\n\ float4 pos : POSITION;\n\ float3 normal : NORMAL;\n\ float4 colors[2] : COLOR0;\n\ -float3 uv[8] : TEXCOORD0;\n\ +float4 uv[5] : TEXCOORD0;\n\ };\n\ \n\ struct VS_OUTPUT {\n\ @@ -43,10 +43,9 @@ VS_OUTPUT main(const VS_INPUT input)\n\ {\n\ VS_OUTPUT output;\n\ \n\ -output.pos = mul(matWorldViewProj, input.pos);\n\ +output.pos = mul(input.pos, matWorldViewProj);\n\ // texgen\n\ -for (int i=0; i<5; i++)\n\ - output.uv[i] = float4(input.uv[i].xyz,1);\n\ +for (int i=0; i<5; i++)\n output.uv[i] = input.uv[i];\n\ \n\ for (int i=0; i<2; i++)\n output.colors[i] = input.colors[i];\n\ return output;\n\