From 852fe9c4bebb992aa91d7ba107ca15688ca87221 Mon Sep 17 00:00:00 2001 From: crudelios Date: Wed, 26 Oct 2011 01:19:10 +0100 Subject: Added proper Bounding Box support. Should fix most graphical issues with Paper Mario: TTYD and Super Paper Mario. Fixes issue 360. Since only those two games seem to require BBox support, and as per ector's suggestion, BBox is only enabled for those two games. BBoxes and Display List Caches don't get along too well, causing Paper Mario: TTYD to hang during certain effects where BBoxes are used. For now, I disabled DList Cache for the Paper Mario games, hopefully both will be compatible in the future. --- Source/Core/VideoCommon/Src/VertexLoader.cpp | 73 +++++++++++++++------------- 1 file changed, 39 insertions(+), 34 deletions(-) (limited to 'Source/Core/VideoCommon/Src/VertexLoader.cpp') diff --git a/Source/Core/VideoCommon/Src/VertexLoader.cpp b/Source/Core/VideoCommon/Src/VertexLoader.cpp index ce9e81219d..ee0538751a 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader.cpp @@ -101,7 +101,7 @@ void LOADERDECL PosMtx_Write() void LOADERDECL UpdateBoundingBox() { - if (!PixelEngine::bbox_active) + if (!PixelEngine::bbox_active) return; // Truly evil hack, reading backwards from the write pointer. If we were writing to write-only @@ -119,40 +119,46 @@ void LOADERDECL UpdateBoundingBox() t[1] = p[0] * world_matrix[4] + p[1] * world_matrix[5] + p[2] * world_matrix[6] + world_matrix[7]; t[2] = p[0] * world_matrix[8] + p[1] * world_matrix[9] + p[2] * world_matrix[10] + world_matrix[11]; - float o[4]; - o[2] = t[0] * proj_matrix[8] + t[1] * proj_matrix[9] + t[2] * proj_matrix[10] + proj_matrix[11]; - // Depth culling - if (o[2] < 0.0) { - // No pixels are likely to be drawn - don't update bounding box. - return; - } + float o[3]; o[0] = t[0] * proj_matrix[0] + t[1] * proj_matrix[1] + t[2] * proj_matrix[2] + proj_matrix[3]; o[1] = t[0] * proj_matrix[4] + t[1] * proj_matrix[5] + t[2] * proj_matrix[6] + proj_matrix[7]; - o[3] = t[0] * proj_matrix[12] + t[1] * proj_matrix[13] + t[2] * proj_matrix[14] + proj_matrix[15]; - - o[0] /= o[3]; - o[1] /= o[3]; + o[2] = t[0] * proj_matrix[12] + t[1] * proj_matrix[13] + t[2] * proj_matrix[14] + proj_matrix[15]; + + + o[0] /= o[2]; + o[1] /= o[2]; // should possibly adjust for viewport? - o[0] = (o[0] + 1.0f) * 320.0f; - o[1] = (o[1] + 1.0f) * 240.0f; - - if (o[0] < PixelEngine::bbox[0]) PixelEngine::bbox[0] = (u16)std::max(0.0f, o[0]); - if (o[0] > PixelEngine::bbox[1]) PixelEngine::bbox[1] = (u16)std::min(640.0f, o[0]); - if (o[1] < PixelEngine::bbox[2]) PixelEngine::bbox[2] = (u16)std::max(0.0f, o[1]); - if (o[1] > PixelEngine::bbox[3]) PixelEngine::bbox[3] = (u16)std::min(480.0f, o[1]); - - // Hardware tests bounding boxes in 2x2 blocks => left and top are even, right and bottom are odd - PixelEngine::bbox[0] &= ~1; - PixelEngine::bbox[1] |= 1; - PixelEngine::bbox[2] &= ~1; - PixelEngine::bbox[3] |= 1; - - /* - if (GetAsyncKeyState(VK_LSHIFT)) { - ERROR_LOG(VIDEO, "XForm: %f %f %f to %f %f", p[0], p[1], p[2], o[0], o[1]); - ERROR_LOG(VIDEO, "%i %i %i %i", g_VideoInitialize.pBBox[0], g_VideoInitialize.pBBox[1], g_VideoInitialize.pBBox[2], g_VideoInitialize.pBBox[3]); - }*/ + o[0] = (o[0] + 1.0f) * 304.0f; + o[1] = (1.0f - o[1]) * 240.0f; + + if (o[0] < PixelEngine::bbox[0]) + { + PixelEngine::bbox[0] = (u16) std::max(0.0f, o[0]); + + // Hardware tests bounding boxes in 2x2 blocks => left and top are even, right and bottom are odd + PixelEngine::bbox[0] &= ~1; + } + + if (o[0] > PixelEngine::bbox[1]) + { + PixelEngine::bbox[1] = (u16) std::min(608.0f, o[0]); + if(!(PixelEngine::bbox[1] & 1) && PixelEngine::bbox[1] != 0) + PixelEngine::bbox[1]--; + } + + if (o[1] < PixelEngine::bbox[2]) + { + PixelEngine::bbox[2] = (u16) std::max(0.0f, o[1]); + PixelEngine::bbox[2] &= ~1; + } + + if (o[1] > PixelEngine::bbox[3]) + { + PixelEngine::bbox[3] = (u16) std::min(480.0f, o[1]); + if(!(PixelEngine::bbox[3] & 1) && PixelEngine::bbox[3] != 0) + PixelEngine::bbox[3]--; + } } void LOADERDECL TexMtx_ReadDirect_UByte() @@ -290,9 +296,8 @@ void VertexLoader::CompileVertexTranslator() // OK, so we just got a point. Let's go back and read it for the bounding box. -#ifdef BBOX_SUPPORT - WriteCall(UpdateBoundingBox); -#endif + if(g_ActiveConfig.bUseBBox) + WriteCall(UpdateBoundingBox); // Normals vtx_decl.num_normals = 0; -- cgit v1.2.3 From dd551814c9c160c1dd33ed0f29e722e73fb43eca Mon Sep 17 00:00:00 2001 From: crudelios Date: Fri, 28 Oct 2011 21:12:12 +0100 Subject: Bounding Box bugfixes. - Fixes all (I hope) BBox-related unknown pointer crashes. - Fixes wrong BBox values with Frame Skip on (and the resulting unknown pointer crashes). - Fixes a small oversight on the change I made to the ISO Properties dialog. This should also be a (very very little) bit faster than the previous version. --- Source/Core/VideoCommon/Src/VertexLoader.cpp | 39 ++++++---------------------- 1 file changed, 8 insertions(+), 31 deletions(-) (limited to 'Source/Core/VideoCommon/Src/VertexLoader.cpp') diff --git a/Source/Core/VideoCommon/Src/VertexLoader.cpp b/Source/Core/VideoCommon/Src/VertexLoader.cpp index ee0538751a..fb34ce1bc1 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader.cpp @@ -111,7 +111,7 @@ void LOADERDECL UpdateBoundingBox() // Then convert to screen space and update the bounding box. float p[3] = {data[0], data[1], data[2]}; - const float *world_matrix = (float*)xfmem + MatrixIndexA.PosNormalMtxIdx * 4; + const float *world_matrix = (float*)xfmem + MatrixIndexA.PosNormalMtxIdx * 4; const float *proj_matrix = &g_fProjectionMatrix[0]; float t[3]; @@ -124,41 +124,18 @@ void LOADERDECL UpdateBoundingBox() o[1] = t[0] * proj_matrix[4] + t[1] * proj_matrix[5] + t[2] * proj_matrix[6] + proj_matrix[7]; o[2] = t[0] * proj_matrix[12] + t[1] * proj_matrix[13] + t[2] * proj_matrix[14] + proj_matrix[15]; - o[0] /= o[2]; o[1] /= o[2]; - // should possibly adjust for viewport? + // Max width seems to be 608, while max height is 480 + // Here height is set to 484 as BBox bottom always seems to be off by a few pixels o[0] = (o[0] + 1.0f) * 304.0f; - o[1] = (1.0f - o[1]) * 240.0f; - - if (o[0] < PixelEngine::bbox[0]) - { - PixelEngine::bbox[0] = (u16) std::max(0.0f, o[0]); + o[1] = (1.0f - o[1]) * 242.0f; - // Hardware tests bounding boxes in 2x2 blocks => left and top are even, right and bottom are odd - PixelEngine::bbox[0] &= ~1; - } - - if (o[0] > PixelEngine::bbox[1]) - { - PixelEngine::bbox[1] = (u16) std::min(608.0f, o[0]); - if(!(PixelEngine::bbox[1] & 1) && PixelEngine::bbox[1] != 0) - PixelEngine::bbox[1]--; - } - - if (o[1] < PixelEngine::bbox[2]) - { - PixelEngine::bbox[2] = (u16) std::max(0.0f, o[1]); - PixelEngine::bbox[2] &= ~1; - } - - if (o[1] > PixelEngine::bbox[3]) - { - PixelEngine::bbox[3] = (u16) std::min(480.0f, o[1]); - if(!(PixelEngine::bbox[3] & 1) && PixelEngine::bbox[3] != 0) - PixelEngine::bbox[3]--; - } + if (o[0] < PixelEngine::bbox[0]) PixelEngine::bbox[0] = (u16) std::max(0.0f, o[0]); + if (o[0] > PixelEngine::bbox[1]) PixelEngine::bbox[1] = (u16) o[0]; + if (o[1] < PixelEngine::bbox[2]) PixelEngine::bbox[2] = (u16) std::max(0.0f, o[1]); + if (o[1] > PixelEngine::bbox[3]) PixelEngine::bbox[3] = (u16) o[1]; } void LOADERDECL TexMtx_ReadDirect_UByte() -- cgit v1.2.3