From 2c457de681c9c895e02c463c37e5098c5165b485 Mon Sep 17 00:00:00 2001 From: Jaklyy <102590697+Jaklyy@users.noreply.github.com> Date: Sat, 10 Feb 2024 20:54:35 -0500 Subject: [PATCH] rework to actually work --- src/GPU3D_Soft.h | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/GPU3D_Soft.h b/src/GPU3D_Soft.h index 51a87339..58313800 100644 --- a/src/GPU3D_Soft.h +++ b/src/GPU3D_Soft.h @@ -180,37 +180,40 @@ private: { // Z-buffering: linear interpolation // still doesn't quite match hardware... - s32 base = 0, disp = 0, factor = 0; + s32 disp = 0; if (z0 < z1) { - base = z0; disp = z1 - z0; - factor = x; } else { - base = z1; - disp = z0 - z1, - factor = xdiff - x; + disp = z0 - z1; } - /* - if (dir) + + /*if (dir) { - return base + disp * factor / xdiff; + if (z0 < z1) return z0 + ((z1 - z0) * x / xdiff); + else return z1 + ((z0 - z1) - ((z0 - z1) * x / xdiff)); + }*/ + + u32 recip, recip2; + u32 shift = 0; + recip2 = recip = (x << 16) / xdiff; + while (recip2 > 0x100) + { + recip2 >>= 1; + shift++; } - else*/ + disp >>= shift; + + if (z0 < z1) { - u32 recip, recip2; - u32 shift = 0; - recip2 = recip = (factor << 16) / xdiff; - while (recip2 > 0x100) - { - recip2 >>= 1; - shift++; - } - disp >>= shift; - return base + ((disp * recip) >> (16 - shift)); + return z0 + ((disp * recip) >> (16 - shift)); + } + else + { + return z1 + ((z0-z1) - ((disp * recip) >> (16 - shift))); } } }