From f4bae5a5d5e5e11267660affd524f345cf9abdc7 Mon Sep 17 00:00:00 2001 From: Jaklyy <102590697+Jaklyy@users.noreply.github.com> Date: Sat, 10 Feb 2024 17:39:40 -0500 Subject: [PATCH] best approximation so far --- src/GPU3D_Soft.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/GPU3D_Soft.h b/src/GPU3D_Soft.h index 9cfdf9ad..51a87339 100644 --- a/src/GPU3D_Soft.h +++ b/src/GPU3D_Soft.h @@ -194,22 +194,23 @@ private: disp = z0 - z1, factor = xdiff - x; } - + /* if (dir) { - int shift = 0; - while (disp > 0x3FF) + return base + disp * factor / xdiff; + } + else*/ + { + u32 recip, recip2; + u32 shift = 0; + recip2 = recip = (factor << 16) / xdiff; + while (recip2 > 0x100) { - disp >>= 1; + recip2 >>= 1; shift++; } - - return base + ((((s64)disp * factor * xrecip_z) >> 22) << shift); - } - else - { - disp >>= 9; - return base + (((s64)disp * factor * xrecip_z) >> 13); + disp >>= shift; + return base + ((disp * recip) >> (16 - shift)); } } }