diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-04-17 22:14:45 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-20 14:12:56 +0200 |
commit | e1a6966863b4f8b038bbb7925391a817b2377211 (patch) | |
tree | 3c07b614d456ce1de98e2c0c94c314d8e0ce6314 | |
parent | 838cee37a2b7ed14d417d53261374a975cd436ad (diff) | |
download | serenity-e1a6966863b4f8b038bbb7925391a817b2377211.zip |
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. :^)
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Device.cpp | 11 |
1 files 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<float>::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 |