aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-07-10 13:31:05 +0200
committerStapleButter <thetotalworm@gmail.com>2017-07-10 13:31:05 +0200
commit800540b710eaa0db23c42d603d844c809885e1a5 (patch)
treeb6689c607c53d3dd69f9c90792c545f230a29cad /src
parent8f031f698b4ff2841062537b931a1825247e8113 (diff)
attempt to fix interpolation when y0>y1
Diffstat (limited to 'src')
-rw-r--r--src/GPU3D_Soft.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp
index e7cf542..b377b73 100644
--- a/src/GPU3D_Soft.cpp
+++ b/src/GPU3D_Soft.cpp
@@ -199,20 +199,44 @@ public:
{
if (xdiff == 0) return y0;
+ s32 ybase, ydiff;
+ if (y1 < y0)
+ {
+ ybase = y0;
+ ydiff = y1 - y0 - 1;
+ }
+ else
+ {
+ ybase = y0;
+ ydiff = y1 - y0;
+ }
+
if (wdiff != 0)
- return y0 + (((y1 - y0) * yfactor) >> shift);
+ return ybase + ((ydiff * yfactor) >> shift);
else
- return y0 + (((y1 - y0) * x) / xdiff);
+ return ybase + ((ydiff * x) / xdiff);
}
s32 InterpolateZ(s32 z0, s32 z1, bool wbuffer)
{
if (xdiff == 0) return z0;
+ s32 zbase, zdiff;
+ if (z1 < z0)
+ {
+ zbase = z0;
+ zdiff = z1 - z0 - 1;
+ }
+ else
+ {
+ zbase = z0;
+ zdiff = z1 - z0;
+ }
+
if ((wdiff != 0) && wbuffer)
- return z0 + (((s64)(z1 - z0) * yfactor) >> shift);
+ return zbase + (((s64)zdiff * yfactor) >> shift);
else
- return z0 + (((s64)(z1 - z0) * x) / xdiff);
+ return zbase + (((s64)zdiff * x) / xdiff);
}
private: