From a66056217fe548d7a84d90d95c59d14a02c41fd3 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 13 Nov 2022 09:23:06 -0800 Subject: [PATCH] softgpu: Avoid splitting rectangles for fog. If the fog factor would result in the same amount of fog, we're just adding more work for no reason. --- GPU/Software/Clipper.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/GPU/Software/Clipper.cpp b/GPU/Software/Clipper.cpp index 11db812e1a..bae2be1881 100644 --- a/GPU/Software/Clipper.cpp +++ b/GPU/Software/Clipper.cpp @@ -203,7 +203,15 @@ void ProcessRect(const ClipVertexData &v0, const ClipVertexData &v1, BinManager else if (outsidePos >= 2 || outsideNeg >= 2) return; - if (v0.v.fogdepth != v1.v.fogdepth) { + bool splitFog = v0.v.fogdepth != v1.v.fogdepth; + if (splitFog) { + // If they match the same 1/255, we can consider the fog flat. Seen in Resistance. + // More efficient if we can avoid splitting. + static constexpr float foghalfstep = 0.5f / 255.0f; + if (v1.v.fogdepth - foghalfstep <= v0.v.fogdepth && v1.v.fogdepth + foghalfstep >= v0.v.fogdepth) + splitFog = false; + } + if (splitFog) { // Rectangles seem to always use nearest along X for fog depth, but reversed. // TODO: Check exactness of middle. VertexData vhalf0 = v1.v;