Vertex Shading / Projection Matrix done right (D3D)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2343 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
XTra.KrazzY 2009-02-21 17:17:24 +00:00
parent 0c13bf4761
commit ca47268669
3 changed files with 34 additions and 33 deletions

View File

@ -199,7 +199,7 @@ void VertexShaderManager::SetConstants(bool proj_hax_1, bool proj_hax_2)
static float GC_ALIGNED16(g_fProjectionMatrix[16]); 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[0] = xfregs.rawProjection[0];
g_fProjectionMatrix[1] = 0.0f; g_fProjectionMatrix[1] = 0.0f;
g_fProjectionMatrix[2] = xfregs.rawProjection[1]; 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_14, g_fProjectionMatrix[14]);
SETSTAT_FT(stats.gproj_15, g_fProjectionMatrix[15]); SETSTAT_FT(stats.gproj_15, g_fProjectionMatrix[15]);
} }
else { else { // Orthogonal
g_fProjectionMatrix[0] = xfregs.rawProjection[0]; g_fProjectionMatrix[0] = xfregs.rawProjection[0];
g_fProjectionMatrix[1] = 0.0f; g_fProjectionMatrix[1] = 0.0f;
g_fProjectionMatrix[2] = 0.0f; g_fProjectionMatrix[2] = 0.0f;

View File

@ -337,48 +337,50 @@ void Renderer::SetScissorBox(RECT &rc)
void Renderer::SetProjection(float* pMatrix, int constantIndex) void Renderer::SetProjection(float* pMatrix, int constantIndex)
{ {
D3DXMATRIX mtx; D3DXMATRIX mtx;
if (pMatrix[6] == 0) if (pMatrix[6] == 0) // Model View
{ {
mtx.m[0][0] = pMatrix[0]; 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][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[1][1] = pMatrix[2];
mtx.m[2][1] = pMatrix[3]; mtx.m[1][2] = pMatrix[3];
mtx.m[3][1] = +0.5f/m_height; mtx.m[1][3] = 0; // +0.5f/m_height; <-- fix d3d pixel center?
mtx.m[0][2] = 0.0f; mtx.m[2][0] = 0.0f;
mtx.m[1][2] = 0.0f; mtx.m[2][1] = 0.0f;
mtx.m[2][2] = -(1-pMatrix[4]); mtx.m[2][2] = -(1.0f - pMatrix[4]);
mtx.m[3][2] = pMatrix[5]; mtx.m[2][3] = pMatrix[5]; // Problematic in OGL
mtx.m[0][3] = 0.0f; mtx.m[3][0] = 0.0f;
mtx.m[1][3] = 0.0f; mtx.m[3][1] = 0.0f;
mtx.m[2][3] = -1.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; mtx.m[3][3] = 0.0f;
} }
else else // Orthogonal
{ {
mtx.m[0][0] = pMatrix[0]; 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[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][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][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[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[3][0] = 0;
mtx.m[1][3] = 0; mtx.m[3][1] = 0;
mtx.m[2][3] = 0.0f; mtx.m[3][2] = 0.0f;
mtx.m[3][3] = 1.0f; mtx.m[3][3] = 1.0f;
} }
D3D::dev->SetVertexShaderConstantF(constantIndex, mtx, 4); D3D::dev->SetVertexShaderConstantF(constantIndex, mtx, 4);

View File

@ -27,7 +27,7 @@ struct VS_INPUT {\n\
float4 pos : POSITION;\n\ float4 pos : POSITION;\n\
float3 normal : NORMAL;\n\ float3 normal : NORMAL;\n\
float4 colors[2] : COLOR0;\n\ float4 colors[2] : COLOR0;\n\
float3 uv[8] : TEXCOORD0;\n\ float4 uv[5] : TEXCOORD0;\n\
};\n\ };\n\
\n\ \n\
struct VS_OUTPUT {\n\ struct VS_OUTPUT {\n\
@ -43,10 +43,9 @@ VS_OUTPUT main(const VS_INPUT input)\n\
{\n\ {\n\
VS_OUTPUT output;\n\ VS_OUTPUT output;\n\
\n\ \n\
output.pos = mul(matWorldViewProj, input.pos);\n\ output.pos = mul(input.pos, matWorldViewProj);\n\
// texgen\n\ // texgen\n\
for (int i=0; i<5; i++)\n\ for (int i=0; i<5; i++)\n output.uv[i] = input.uv[i];\n\
output.uv[i] = float4(input.uv[i].xyz,1);\n\
\n\ \n\
for (int i=0; i<2; i++)\n output.colors[i] = input.colors[i];\n\ for (int i=0; i<2; i++)\n output.colors[i] = input.colors[i];\n\
return output;\n\ return output;\n\