diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-07-14 04:49:29 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-07-14 04:49:29 +0200 |
commit | cd6ecfc21ff6a8784f983503cb022514ad142bbe (patch) | |
tree | e5597d51878d89d5dfd4743a15c2d551e8ea9c6f | |
parent | e1926d6e97471ebb6fa92f6e96aa9743f6d614f9 (diff) |
apply the interpolation fix to Z interpolation.
more accurate conversion of Z values.
but this doesn't fix the horrendous Z-fighting in Pokémon B/W because of course it doesn't >_<
-rw-r--r-- | src/GPU3D.cpp | 2 | ||||
-rw-r--r-- | src/GPU3D_Soft.cpp | 24 |
2 files changed, 13 insertions, 13 deletions
diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp index f4de0c1..f08ee5d 100644 --- a/src/GPU3D.cpp +++ b/src/GPU3D.cpp @@ -882,7 +882,7 @@ void SubmitPolygon() if (FlushAttributes & 0x2) z = wshifted; else if (wshifted) - z = (((s64)vtx->Position[2] * 0x800000) / wshifted) + 0x7FFEFF; + z = ((((s64)vtx->Position[2] * 0x4000) / wshifted) * 0x200) + 0x7FFE00; else z = 0x7FFEFF; 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: |