diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/Clipper.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/Clipper.cpp index b97ad3795d..50dc4bfada 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/Clipper.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/Clipper.cpp @@ -62,7 +62,7 @@ namespace Clipper float m_ViewOffset[3]; OutputVertexData ClippedVertices[18]; OutputVertexData *Vertices[21]; - + void Init() { for (int i = 0; i < 18; ++i) @@ -339,6 +339,9 @@ namespace Clipper Vertices[0] = lineV0; Vertices[1] = lineV1; + // point to a valid vertex to store to when clipping + Vertices[2] = &ClippedVertices[17]; + ClipLine(indices); if(indices[0] != SKIP_FLAG) @@ -437,4 +440,4 @@ namespace Clipper screen.z = projected.z * wInverse + m_ViewOffset[2]; } -} +} diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/DebugUtil.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/DebugUtil.cpp index 05cb82ee06..53b7a0dc3e 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/DebugUtil.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/DebugUtil.cpp @@ -28,7 +28,7 @@ #include "StringUtil.h" #include "CommandProcessor.h" #include "../../../Core/VideoCommon/Src/ImageWrite.h" -#include "FileUtil.h" +#include "FileUtil.h" namespace DebugUtil { @@ -105,7 +105,7 @@ void DumpActiveTextures() u32 texmap = bpmem.tevindref.getTexMap(stageNum); s32 maxLod = GetMaxTextureLod(texmap); - for (s32 mip = 0; mip < maxLod; ++mip) + for (s32 mip = 0; mip <= maxLod; ++mip) { SaveTexture(StringFromFormat("%star%i_ind%i_map%i_mip%i.tga", File::GetUserPath(D_DUMPTEXTURES_IDX), stats.thisFrame.numDrawnObjects, stageNum, texmap, mip).c_str(), texmap, mip); } @@ -120,7 +120,7 @@ void DumpActiveTextures() int texmap = order.getTexMap(stageOdd); s32 maxLod = GetMaxTextureLod(texmap); - for (s32 mip = 0; mip < maxLod; ++mip) + for (s32 mip = 0; mip <= maxLod; ++mip) { SaveTexture(StringFromFormat("%star%i_stage%i_map%i_mip%i.tga", File::GetUserPath(D_DUMPTEXTURES_IDX), stats.thisFrame.numDrawnObjects, stageNum, texmap, mip).c_str(), texmap, mip); } @@ -198,7 +198,7 @@ void OnObjectEnd() if (!g_bSkipCurrentFrame) { if (g_Config.bDumpObjects && stats.thisFrame.numDrawnObjects >= g_Config.drawStart && stats.thisFrame.numDrawnObjects < g_Config.drawEnd) - DumpEfb(StringFromFormat("%sobject%i.tga", File::GetUserPath(D_DUMPFRAMES_IDX), stats.thisFrame.numDrawnObjects).c_str()); + DumpEfb(StringFromFormat("%sobject%i.tga", File::GetUserPath(D_DUMPFRAMES_IDX), stats.thisFrame.numDrawnObjects).c_str()); if (g_Config.bHwRasterizer) HwRasterizer::EndTriangles(); @@ -208,7 +208,7 @@ void OnObjectEnd() if (DrawnToBuffer[i]) { DrawnToBuffer[i] = false; - SaveTGA(StringFromFormat("%sobject%i_%s(%i).tga", File::GetUserPath(D_DUMPFRAMES_IDX), + SaveTGA(StringFromFormat("%sobject%i_%s(%i).tga", File::GetUserPath(D_DUMPFRAMES_IDX), stats.thisFrame.numDrawnObjects, ObjectBufferName[i], i).c_str(), EFB_WIDTH, EFB_HEIGHT, ObjectBuffer[i]); memset(ObjectBuffer[i], 0, sizeof(ObjectBuffer[i])); } @@ -224,10 +224,10 @@ void OnFrameEnd() { if (g_Config.bDumpFrames) { - DumpEfb(StringFromFormat("%sframe%i_color.tga", File::GetUserPath(D_DUMPFRAMES_IDX), stats.frameCount).c_str()); - DumpDepth(StringFromFormat("%sframe%i_depth.tga", File::GetUserPath(D_DUMPFRAMES_IDX), stats.frameCount).c_str()); + DumpEfb(StringFromFormat("%sframe%i_color.tga", File::GetUserPath(D_DUMPFRAMES_IDX), stats.frameCount).c_str()); + DumpDepth(StringFromFormat("%sframe%i_depth.tga", File::GetUserPath(D_DUMPFRAMES_IDX), stats.frameCount).c_str()); } } } -} +} diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/EfbCopy.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/EfbCopy.cpp index f5fdb7a076..0f4763cdbd 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/EfbCopy.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/EfbCopy.cpp @@ -105,4 +105,4 @@ namespace EfbCopy } } } -} +} diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/EfbInterface.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/EfbInterface.cpp index f99e94c155..0248c4cfb7 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/EfbInterface.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/EfbInterface.cpp @@ -542,4 +542,4 @@ namespace EfbInterface return pass; } -} +} diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/EfbInterface.h b/Source/Plugins/Plugin_VideoSoftware/Src/EfbInterface.h index 815d39355d..f6f3f3f3e3 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/EfbInterface.h +++ b/Source/Plugins/Plugin_VideoSoftware/Src/EfbInterface.h @@ -47,4 +47,4 @@ namespace EfbInterface extern u8 efbColorTexture[EFB_WIDTH*EFB_HEIGHT*4]; // rgba format } -#endif +#endif diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/HwRasterizer.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/HwRasterizer.cpp index 5975e0967b..91bcd7fd7f 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/HwRasterizer.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/HwRasterizer.cpp @@ -85,13 +85,13 @@ namespace HwRasterizer void DrawColorVertex(OutputVertexData *v) { glColor3ub(v->color[0][0], v->color[0][1], v->color[0][2]); - glVertex3f(v->screenPosition[0] / efbHalfWidth - 1.0f, 1.0f - v->screenPosition[1] / efbHalfHeight, v->screenPosition[2]); + glVertex3f(v->screenPosition.x / efbHalfWidth - 1.0f, 1.0f - v->screenPosition.y / efbHalfHeight, v->screenPosition.z); } void DrawTextureVertex(OutputVertexData *v) { - glTexCoord2f(v->texCoords[0][0] * texWidth, v->texCoords[0][1] * texHeight); - glVertex3f(v->screenPosition[0] / efbHalfWidth - 1.0f, 1.0f - v->screenPosition[1] / efbHalfHeight, v->screenPosition[2]); + glTexCoord2f(v->texCoords[0].x * texWidth, v->texCoords[0].y * texHeight); + glVertex3f(v->screenPosition.x / efbHalfWidth - 1.0f, 1.0f - v->screenPosition.y / efbHalfHeight, v->screenPosition.z); } void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2) diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/OpcodeDecoder.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/OpcodeDecoder.cpp index 43085c6ec3..232667cbfb 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/OpcodeDecoder.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/OpcodeDecoder.cpp @@ -294,4 +294,4 @@ void Run(u32 iBufferSize) currentFunction(iBufferSize); } -} +} diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.cpp index 22ecb1c6d5..c0b7ea2a9a 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.cpp @@ -49,6 +49,11 @@ Slope WSlope; Slope ColorSlopes[2][4]; Slope TexSlopes[8][3]; +s32 vertex0X; +s32 vertex0Y; +float vertexOffsetX; +float vertexOffsetY; + s32 scissorLeft = 0; s32 scissorTop = 0; s32 scissorRight = 0; @@ -108,7 +113,10 @@ inline void Draw(s32 x, s32 y, s32 xi, s32 yi) { INCSTAT(stats.thisFrame.rasterizedPixels); - float zFloat = 1.0f + ZSlope.GetValue(x, y); + float dx = vertexOffsetX + (float)(x - vertex0X); + float dy = vertexOffsetY + (float)(y - vertex0Y); + + float zFloat = 1.0f + ZSlope.GetValue(dx, dy); if (zFloat < 0.0f || zFloat > 1.0f) return; @@ -133,7 +141,7 @@ inline void Draw(s32 x, s32 y, s32 xi, s32 yi) for (unsigned int i = 0; i < bpmem.genMode.numcolchans; i++) { for(int comp = 0; comp < 4; comp++) - tev.Color[i][comp] = (u8)ColorSlopes[i][comp].GetValue(x, y); + tev.Color[i][comp] = (u8)ColorSlopes[i][comp].GetValue(dx, dy); } // tex coords @@ -159,9 +167,21 @@ inline void Draw(s32 x, s32 y, s32 xi, s32 yi) tev.Draw(); } -void InitSlope(Slope *slope, float f1, float f2, float f3, float DX31, float DX12, float DY12, float DY31, float X1, float Y1) +void InitTriangle(float X1, float Y1, s32 xi, s32 yi) { - float DF31 = f3 - f1; + vertex0X = xi; + vertex0Y = yi; + + // adjust a little less than 0.5 + const float adjust = 0.495f; + + vertexOffsetX = ((float)xi - X1) + adjust; + vertexOffsetY = ((float)yi - Y1) + adjust; +} + +void InitSlope(Slope *slope, float f1, float f2, float f3, float DX31, float DX12, float DY12, float DY31) +{ + float DF31 = f3 - f1; float DF21 = f2 - f1; float a = DF31 * -DY12 - DF21 * DY31; float b = DX31 * DF21 + DX12 * DF31; @@ -169,8 +189,6 @@ void InitSlope(Slope *slope, float f1, float f2, float f3, float DX31, float DX1 slope->dfdx = -a / c; slope->dfdy = -b / c; slope->f0 = f1; - slope->x0 = X1; - slope->y0 = Y1; } inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord) @@ -210,7 +228,7 @@ inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord) bias >>= 1; lod += bias; - linear = (lod >= 0 && (tm0.min_filter & 4) || lod < 0 && tm0.mag_filter); + linear = (lod > 0 && (tm0.min_filter & 4) || lod <= 0 && tm0.mag_filter); // order of checks matters // should be: @@ -227,10 +245,10 @@ void BuildBlock(s32 blockX, s32 blockY) { RasterBlockPixel& pixel = rasterBlock.Pixel[xi][yi]; - s32 x = xi + blockX; - s32 y = yi + blockY; + float dx = vertexOffsetX + (float)(xi + blockX - vertex0X); + float dy = vertexOffsetY + (float)(yi + blockY - vertex0Y); - float invW = 1.0f / WSlope.GetValue(x, y); + float invW = 1.0f / WSlope.GetValue(dx, dy); pixel.InvW = invW; // tex coords @@ -239,14 +257,14 @@ void BuildBlock(s32 blockX, s32 blockY) float projection; if (xfregs.texMtxInfo[i].projection) { - float q = TexSlopes[i][2].GetValue(x, y) * invW; + float q = TexSlopes[i][2].GetValue(dx, dy) * invW; projection = invW / q; } else projection = invW; - pixel.Uv[i][0] = TexSlopes[i][0].GetValue(x, y) * projection; - pixel.Uv[i][1] = TexSlopes[i][1].GetValue(x, y) * projection; + pixel.Uv[i][0] = TexSlopes[i][0].GetValue(dx, dy) * projection; + pixel.Uv[i][1] = TexSlopes[i][1].GetValue(dx, dy) * projection; } } } @@ -288,14 +306,15 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer // adapted from http://www.devmaster.net/forums/showthread.php?t=1884 - // 28.4 fixed-pou32 coordinates. rounded to nearest - const s32 Y1 = iround(16.0f * v0->screenPosition[1]); - const s32 Y2 = iround(16.0f * v1->screenPosition[1]); - const s32 Y3 = iround(16.0f * v2->screenPosition[1]); + // 28.4 fixed-pou32 coordinates. rounded to nearest and adjusted to match hardware output + // could also take floor and adjust -8 + const s32 Y1 = iround(16.0f * v0->screenPosition[1]) - 9; + const s32 Y2 = iround(16.0f * v1->screenPosition[1]) - 9; + const s32 Y3 = iround(16.0f * v2->screenPosition[1]) - 9; - const s32 X1 = iround(16.0f * v0->screenPosition[0]); - const s32 X2 = iround(16.0f * v1->screenPosition[0]); - const s32 X3 = iround(16.0f * v2->screenPosition[0]); + const s32 X1 = iround(16.0f * v0->screenPosition[0]) - 9; + const s32 X2 = iround(16.0f * v1->screenPosition[0]) - 9; + const s32 X3 = iround(16.0f * v2->screenPosition[0]) - 9; // Deltas const s32 DX12 = X1 - X2; @@ -331,28 +350,30 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer return; // Setup slopes - float fltx1 = v0->screenPosition[0]; - float flty1 = v0->screenPosition[1]; - float fltdx31 = v2->screenPosition[0] - fltx1; - float fltdx12 = fltx1 - v1->screenPosition[0]; - float fltdy12 = flty1 - v1->screenPosition[1]; - float fltdy31 = v2->screenPosition[1] - flty1; + float fltx1 = v0->screenPosition.x; + float flty1 = v0->screenPosition.y; + float fltdx31 = v2->screenPosition.x - fltx1; + float fltdx12 = fltx1 - v1->screenPosition.x; + float fltdy12 = flty1 - v1->screenPosition.y; + float fltdy31 = v2->screenPosition.y - flty1; + + InitTriangle(fltx1, flty1, (X1 + 0xF) >> 4, (Y1 + 0xF) >> 4); float w[3] = { 1.0f / v0->projectedPosition.w, 1.0f / v1->projectedPosition.w, 1.0f / v2->projectedPosition.w }; - InitSlope(&WSlope, w[0], w[1], w[2], fltdx31, fltdx12, fltdy12, fltdy31, fltx1, flty1); + InitSlope(&WSlope, w[0], w[1], w[2], fltdx31, fltdx12, fltdy12, fltdy31); - InitSlope(&ZSlope, v0->screenPosition[2], v1->screenPosition[2], v2->screenPosition[2], fltdx31, fltdx12, fltdy12, fltdy31, fltx1, flty1); + InitSlope(&ZSlope, v0->screenPosition[2], v1->screenPosition[2], v2->screenPosition[2], fltdx31, fltdx12, fltdy12, fltdy31); for(unsigned int i = 0; i < bpmem.genMode.numcolchans; i++) { for(int comp = 0; comp < 4; comp++) - InitSlope(&ColorSlopes[i][comp], v0->color[i][comp], v1->color[i][comp], v2->color[i][comp], fltdx31, fltdx12, fltdy12, fltdy31, fltx1, flty1); + InitSlope(&ColorSlopes[i][comp], v0->color[i][comp], v1->color[i][comp], v2->color[i][comp], fltdx31, fltdx12, fltdy12, fltdy31); } for(unsigned int i = 0; i < bpmem.genMode.numtexgens; i++) { for(int comp = 0; comp < 3; comp++) - InitSlope(&TexSlopes[i][comp], v0->texCoords[i][comp] * w[0], v1->texCoords[i][comp] * w[1], v2->texCoords[i][comp] * w[2], fltdx31, fltdx12, fltdy12, fltdy31, fltx1, flty1); + InitSlope(&TexSlopes[i][comp], v0->texCoords[i][comp] * w[0], v1->texCoords[i][comp] * w[1], v2->texCoords[i][comp] * w[2], fltdx31, fltdx12, fltdy12, fltdy31); } // Start in corner of 8x8 block diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.h b/Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.h index 403b0459ba..536cd7c358 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.h +++ b/Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.h @@ -35,9 +35,8 @@ namespace Rasterizer float dfdx; float dfdy; float f0; - float x0; - float y0; - float GetValue(s32 x, s32 y) { return f0 + (dfdx * (x - x0)) + (dfdy * (y - y0)); } + + float GetValue(float dx, float dy) { return f0 + (dfdx * dx) + (dfdy * dy); } }; struct RasterBlockPixel @@ -57,4 +56,4 @@ namespace Rasterizer } -#endif +#endif diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp index 680806e85a..00594ea3cf 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/Tev.cpp @@ -705,6 +705,57 @@ void Tev::Draw() Position[2] = ztex & 0x00ffffff; } + // fog + if (bpmem.fog.c_proj_fsel.fsel) + { + float ze; + + if (bpmem.fog.c_proj_fsel.proj == 0) + { + // perspective + // ze = A/(B - Zs) + s32 denom = bpmem.fog.b_magnitude - (Position[2] >> bpmem.fog.b_shift); + ze = bpmem.fog.a.GetA() / (float)denom; + } + else + { + // orthographic + // ze = a*Zs + ze = bpmem.fog.a.GetA() / (float)Position[2]; + } + + ze = (ze * (float)0xffffff) - bpmem.fog.c_proj_fsel.GetC(); + + // clamp 0 to 1 + float fog = (ze<0.0f) ? 0.0f : ((ze>1.0f) ? 1.0f : ze); + + switch (bpmem.fog.c_proj_fsel.fsel) + { + case 4: // exp + fog = 1.0f - pow(2.0f, -8.0f * fog); + break; + case 5: // exp2 + fog = 1.0f - pow(2.0f, -8.0f * fog * fog); + break; + case 6: // backward exp + fog = 1.0f - fog; + fog = 1.0f - pow(2.0f, -8.0f * fog); + break; + case 7: // backward exp2 + fog = 1.0f - fog; + fog = 1.0f - pow(2.0f, -8.0f * fog * fog); + break; + } + + // lerp from output to fog color + u32 fogInt = (u32)(fog * 256); + u32 invFog = 256 - fogInt; + + output[RED_C] = (output[RED_C] * invFog + fogInt * bpmem.fog.color.r) >> 8; + output[GRN_C] = (output[GRN_C] * invFog + fogInt * bpmem.fog.color.g) >> 8; + output[BLU_C] = (output[BLU_C] * invFog + fogInt * bpmem.fog.color.b) >> 8; + } + if (!bpmem.zcontrol.zcomploc && bpmem.zmode.testenable) { if (!EfbInterface::ZCompare(Position[0], Position[1], Position[2])) diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/TextureSampler.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/TextureSampler.cpp index 44878e262b..14b0b0a848 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/TextureSampler.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/TextureSampler.cpp @@ -157,13 +157,17 @@ void SampleMip(s32 s, s32 t, s32 mip, bool linear, u8 texmap, u8 *sample) } } - // integer part of sample location - int imageS = s >> 7; - int imageT = t >> 7; - if (linear) { - // linear sampling + // offset linear sampling + s -= 64; + t -= 64; + + // integer part of sample location + int imageS = s >> 7; + int imageT = t >> 7; + + // linear sampling int imageSPlus1 = imageS + 1; int fractS = s & 0x7f; @@ -197,6 +201,10 @@ void SampleMip(s32 s, s32 t, s32 mip, bool linear, u8 texmap, u8 *sample) } else { + // integer part of sample location + int imageS = s >> 7; + int imageT = t >> 7; + // nearest neighbor sampling WrapCoord(imageS, tm0.wrap_s, imageWidth); WrapCoord(imageT, tm0.wrap_t, imageHeight); diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/TransformUnit.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/TransformUnit.cpp index c614af8627..c8bf7648bb 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/TransformUnit.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/TransformUnit.cpp @@ -166,15 +166,9 @@ inline void TransformTexCoordRegular(const TexMtxInfo &texinfo, int coordNum, bo else { if (postInfo.normalize) - { - float length = sqrtf(dst[0] * dst[0] + dst[1] * dst[1] + dst[2] * dst[2]); - float invL = 1.0f / length; - tempCoord = *dst * invL; - } + tempCoord = dst->normalized(); else - { tempCoord = *dst; - } MultiplyVec3Mat34(tempCoord, postMat, *dst); } @@ -463,32 +457,35 @@ void TransformTexCoord(const InputVertexData *src, OutputVertexData *dst, bool s float d1 = ldir * dst->normal[1]; float d2 = ldir * dst->normal[2]; - dst->texCoords[coordNum][0] = dst->texCoords[texinfo.embosssourceshift][0] + d1; - dst->texCoords[coordNum][1] = dst->texCoords[texinfo.embosssourceshift][1] + d2; - dst->texCoords[coordNum][2] = dst->texCoords[texinfo.embosssourceshift][2]; + dst->texCoords[coordNum].x = dst->texCoords[texinfo.embosssourceshift].x + d1; + dst->texCoords[coordNum].y = dst->texCoords[texinfo.embosssourceshift].y + d2; + dst->texCoords[coordNum].z = dst->texCoords[texinfo.embosssourceshift].z; } break; case XF_TEXGEN_COLOR_STRGBC0: _assert_(texinfo.sourcerow == XF_SRCCOLORS_INROW); _assert_(texinfo.inputform == XF_TEXINPUT_AB11); - dst->texCoords[coordNum][0] = (float)dst->color[0][0] / 255.0f; - dst->texCoords[coordNum][1] = (float)dst->color[0][1] / 255.0f; - dst->texCoords[coordNum][2] = 1.0f; + dst->texCoords[coordNum].x = (float)dst->color[0][0] / 255.0f; + dst->texCoords[coordNum].y = (float)dst->color[0][1] / 255.0f; + dst->texCoords[coordNum].z = 1.0f; break; case XF_TEXGEN_COLOR_STRGBC1: _assert_(texinfo.sourcerow == XF_SRCCOLORS_INROW); _assert_(texinfo.inputform == XF_TEXINPUT_AB11); - dst->texCoords[coordNum][0] = (float)dst->color[1][0] / 255.0f; - dst->texCoords[coordNum][1] = (float)dst->color[1][1] / 255.0f; - dst->texCoords[coordNum][2] = 1.0f; + dst->texCoords[coordNum].x = (float)dst->color[1][0] / 255.0f; + dst->texCoords[coordNum].y = (float)dst->color[1][1] / 255.0f; + dst->texCoords[coordNum].z = 1.0f; break; default: - ERROR_LOG(VIDEO, "Bad tex gen type %i", texinfo.texgentype); + ERROR_LOG(VIDEO, "Bad tex gen type %i", texinfo.texgentype); } + } + for (u32 coordNum = 0; coordNum < xfregs.numTexGens; coordNum++) + { dst->texCoords[coordNum][0] *= (bpmem.texcoords[coordNum].s.scale_minus_1 + 1); dst->texCoords[coordNum][1] *= (bpmem.texcoords[coordNum].t.scale_minus_1 + 1); - } + } } } diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/XFMemLoader.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/XFMemLoader.cpp index 456b63aa61..336ad18be1 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/XFMemLoader.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/XFMemLoader.cpp @@ -35,6 +35,30 @@ void XFWritten(u32 transferSize, u32 baseAddress) if (baseAddress <= 0x1026 && topAddress >= 0x1020) Clipper::SetViewOffset(); + + // fix lights so invalid values don't trash the lighting computations + if (baseAddress <= 0x067f && topAddress >= 0x0604) + { + u32* x = xfregs.lights; + + // go through all lights + for (int light = 0; light < 8; light++) + { + // skip to floating point values + x += 4; + + for (int i = 0; i < 12; i++) + { + u32 xVal = *x; + + // if the exponent is 255 then the number is inf or nan + if ((xVal & 0x7f800000) == 0x7f800000) + *x = 0; + + x++; + } + } + } } void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData) @@ -66,8 +90,7 @@ void LoadIndexedXF(u32 val, int array) int size = ((val >> 12) & 0xF) + 1; //load stuff from array to address in xf mem - u32* xfmem = (u32*)&xfregs; + u32 *pData = (u32*)g_VideoInitialize.pGetMemoryPointer(arraybases[array] + arraystrides[array]*index); - for (int i = 0; i < size; i++) - xfmem[address + i] = Memory_Read_U32(arraybases[array] + arraystrides[array]*index + i*4); + LoadXFReg(size, address, pData); } diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/main.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/main.cpp index c53bb5c6a5..1e9bb02d47 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/main.cpp @@ -113,7 +113,6 @@ void Video_Prepare(void) // Run from the CPU thread (from VideoInterface.cpp) void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) { - g_VideoInitialize.pCopiedToXFB(true); } // Run from the CPU thread (from VideoInterface.cpp)