From e1a6966863b4f8b038bbb7925391a817b2377211 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Sun, 17 Apr 2022 22:14:45 +0200 Subject: LibSoftGPU: Check for bottom edge in top-left rule in `Device` If a triangle edge is completely horizontal and moving in a positive X direction, we were erroneously treating it as a top edge. This adds a better check that accounts for those edges. :^) --- Userland/Libraries/LibSoftGPU/Device.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index 5f755d35dc..754520f91e 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -213,16 +213,15 @@ void Device::rasterize_triangle(Triangle const& triangle) // Zero is used in testing against edge values below, applying the "top-left rule". If a pixel // lies exactly on an edge shared by two triangles, we only render that pixel if the edge in - // question is a "top" or "left" edge. We can detect those easily by testing for Y2 <= Y1, - // since we know our vertices are in CCW order. By changing a float epsilon to 0, we - // effectively change the comparisons against the edge values below from "> 0" into ">= 0". + // question is a "top" or "left" edge. By changing a float epsilon to 0, we effectively change + // the comparisons against the edge values below from "> 0" into ">= 0". constexpr auto epsilon = NumericLimits::epsilon(); FloatVector3 zero { epsilon, epsilon, epsilon }; - if (v2.y() <= v1.y()) + if (v2.y() < v1.y() || (v2.y() == v1.y() && v2.x() < v1.x())) zero.set_x(0.f); - if (v0.y() <= v2.y()) + if (v0.y() < v2.y() || (v0.y() == v2.y() && v0.x() < v2.x())) zero.set_y(0.f); - if (v1.y() <= v0.y()) + if (v1.y() < v0.y() || (v1.y() == v0.y() && v1.x() < v0.x())) zero.set_z(0.f); // This function tests whether a point as identified by its 3 edge values lies within the triangle -- cgit v1.2.3