aboutsummaryrefslogtreecommitdiff
path: root/src/GPU3D_Soft.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/GPU3D_Soft.cpp')
-rw-r--r--src/GPU3D_Soft.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp
index 56660c1..89f191f 100644
--- a/src/GPU3D_Soft.cpp
+++ b/src/GPU3D_Soft.cpp
@@ -222,24 +222,24 @@ public:
s32 InterpolateZ(s32 z0, s32 z1, bool wbuffer)
{
- if (xdiff == 0) return z0;
+ if (xdiff == 0 || z0 == z1) return z0;
- s32 zbase, zdiff;
- if (z1 < z0)
+ if ((wdiff != 0) && wbuffer)
{
- zbase = z0;
- zdiff = z1 - z0 - 1;
+ // perspective-correct approx. interpolation
+ if (z0 < z1)
+ return z0 + (((s64)(z1-z0) * yfactor) >> shift);
+ else
+ return z1 + (((s64)(z0-z1) * ((1<<shift)-yfactor)) >> shift);
}
else
{
- zbase = z0;
- zdiff = z1 - z0;
+ // linear interpolation
+ if (z0 < z1)
+ return z0 + (((s64)(z1-z0) * x) / xdiff);
+ else
+ return z1 + (((s64)(z0-z1) * (xdiff-x)) / xdiff);
}
-
- if ((wdiff != 0) && wbuffer)
- return zbase + (((s64)zdiff * yfactor) >> shift);
- else
- return zbase + (((s64)zdiff * x) / xdiff);
}
private: