From e7d49cd7d0087fb9a423f3e16491f6f973c34f32 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 13:29:40 -0700 Subject: [PATCH] softgpu: Allow almost flat rectangles to go fast. Improves transform rectangles used in Chains of Olympus, for example on the title screen. --- GPU/Software/RasterizerRectangle.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index 7408b1558b..79162dc607 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -333,10 +333,18 @@ static bool AreCoordsRectangleCompatible(const RasterizerState &state, const Ver if (!state.throughMode && !(data1.color1 == data0.color1)) return false; // Do we have to think about perspective correction or slope mip level? - if (state.enableTextures && data1.clippos.w != data0.clippos.w) - return false; - if (state.pixelID.applyFog && data1.fogdepth != data0.fogdepth) - return false; + if (state.enableTextures && data1.clippos.w != data0.clippos.w) { + // If the w is off by less than a factor of 1/512, it should be safe to treat as a rectangle. + static constexpr float halftexel = 0.5f / 512.0f; + if (data1.clippos.w - halftexel > data0.clippos.w || data1.clippos.w + halftexel < data0.clippos.w) + return false; + } + if (state.pixelID.applyFog && data1.fogdepth != data0.fogdepth) { + // Similar to w, this only matters if they're farther apart than 1/255. + static constexpr float foghalfstep = 0.5f / 255.0f; + if (data1.fogdepth - foghalfstep > data0.fogdepth || data1.fogdepth + foghalfstep < data0.fogdepth) + return false; + } } return true; }