aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-04-29 00:20:04 +0200
committerStapleButter <thetotalworm@gmail.com>2017-04-29 00:20:04 +0200
commitda31af92029af5f9db3c9fcc226414e3789f2682 (patch)
tree2556e529da79f631045053cb92297bafc74110b4 /src
parent2273bd2ea46c1d53a775d0f11bf902e1b3bb125b (diff)
fix Z-buffering. not really clean, and not perfectly accurate.
Diffstat (limited to 'src')
-rw-r--r--src/GPU3D.cpp2
-rw-r--r--src/GPU3D.h1
-rw-r--r--src/GPU3D_Soft.cpp16
3 files changed, 10 insertions, 9 deletions
diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp
index a63193f..72e7179 100644
--- a/src/GPU3D.cpp
+++ b/src/GPU3D.cpp
@@ -839,6 +839,7 @@ void SubmitPolygon()
poly->YTop = ytop; poly->YBottom = ybot;
poly->XTop = xtop; poly->XBottom = xbot;
poly->WShift = wshift;
+ poly->WBuffer = (FlushAttributes & 0x2);
for (int i = 0; i < nverts; i++)
{
@@ -849,7 +850,6 @@ void SubmitPolygon()
if (FlushAttributes & 0x2)
z = w << wshift;
else
- //z = vtx->Position[2]+0x7FFFFF;//((vtx->Position[2] + (w<<wshift)) * 0x1000) / (w<<(wshift+1));
z = (((s64)vtx->Position[2] * 0x800000) / (w << wshift)) + 0x7FFEFF;
// checkme
diff --git a/src/GPU3D.h b/src/GPU3D.h
index 79287f7..fdb85f8 100644
--- a/src/GPU3D.h
+++ b/src/GPU3D.h
@@ -46,6 +46,7 @@ typedef struct
s32 FinalZ[10];
s32 FinalW[10];
u8 WShift;
+ bool WBuffer;
u32 Attr;
u32 TexParam;
diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp
index 649f01f..55dd906 100644
--- a/src/GPU3D_Soft.cpp
+++ b/src/GPU3D_Soft.cpp
@@ -129,14 +129,14 @@ public:
return y0 + (((y1 - y0) * x) / xdiff);
}
- s32 InterpolateZ(s32 y0, s32 y1)
+ s32 InterpolateZ(s32 z0, s32 z1, bool wbuffer)
{
- if (xdiff == 0) return y0;
+ if (xdiff == 0) return z0;
- if (wdiff != 0)
- return y0 + (((s64)(y1 - y0) * yfactor) >> shift);
+ if ((wdiff != 0) && wbuffer)
+ return z0 + (((s64)(z1 - z0) * yfactor) >> shift);
else
- return y0 + (((s64)(y1 - y0) * x) / xdiff);
+ return z0 + (((s64)(z1 - z0) * x) / xdiff);
}
private:
@@ -806,8 +806,8 @@ void RenderPolygon(Polygon* polygon)
s32 wl = slopeL.Interp.Interpolate(polygon->FinalW[lcur], polygon->FinalW[lnext]);
s32 wr = slopeR.Interp.Interpolate(polygon->FinalW[rcur], polygon->FinalW[rnext]);
- s32 zl = slopeL.Interp.InterpolateZ(polygon->FinalZ[lcur], polygon->FinalZ[lnext]);
- s32 zr = slopeR.Interp.InterpolateZ(polygon->FinalZ[rcur], polygon->FinalZ[rnext]);
+ s32 zl = slopeL.Interp.InterpolateZ(polygon->FinalZ[lcur], polygon->FinalZ[lnext], polygon->WBuffer);
+ s32 zr = slopeR.Interp.InterpolateZ(polygon->FinalZ[rcur], polygon->FinalZ[rnext], polygon->WBuffer);
// if the left and right edges are swapped, render backwards.
// note: we 'forget' to swap the xmajor flags, on purpose
@@ -928,7 +928,7 @@ void RenderPolygon(Polygon* polygon)
interpX.SetX(x);
- s32 z = interpX.InterpolateZ(zl, zr);
+ s32 z = interpX.InterpolateZ(zl, zr, polygon->WBuffer);
if (polygon->IsShadowMask)
{