From 9979d5544db76dc0b92ce7228448541e66de7a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 27 May 2026 22:16:45 +0200 Subject: [PATCH] Round off Z for the min/max tests. Gets both Test Drive map and Wipeout Pure shadows working at the same time.. --- GPU/Common/VertexShaderGenerator.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index b5e826bf25..8807433ee8 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -1229,11 +1229,16 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag if (clipMinMax) { // We use clipping, where available, to implement min/max Z. // 1.0 is used to disable the clip plane (should we generate more shaders instead? how costly are they?) + // Note: outPos.z need to be multiplied by outPos.w to undo the division, which shouldn't be in effect here. // We should probably store the undivided outPos in a variable. - // We apply a small offset here, it's needed to break some ties, like in the map in Test Drive Unlimited. - WRITE(p, " %sgl_ClipDistance%s = u_minZmaxZ.x > 0.0 ? (outPos.z + 0.5 - u_minZmaxZ.x) * outPos.w : 1.0;\n", compat.vsOutPrefix, minZClipPlaneSuffix); - WRITE(p, " %sgl_ClipDistance%s = u_minZmaxZ.y < 65535.0 ? (u_minZmaxZ.y - (outPos.z + 0.5)) * outPos.w : 1.0;\n", compat.vsOutPrefix, maxZClipPlaneSuffix); + // We round to nearest 15-bit value for the check - this seems to match some of [Unknown]'s test, and PSP GPU floats + // often have a 15-bit mantissa. + + WRITE(p, " float clipZ = float(int(outPos.z + 1) & 0xFFFE);\n"); + + WRITE(p, " %sgl_ClipDistance%s = u_minZmaxZ.x > 0.0 ? (clipZ - u_minZmaxZ.x) * outPos.w : 1.0;\n", compat.vsOutPrefix, minZClipPlaneSuffix); + WRITE(p, " %sgl_ClipDistance%s = u_minZmaxZ.y < 65535.0 ? (u_minZmaxZ.y - clipZ) * outPos.w : 1.0;\n", compat.vsOutPrefix, maxZClipPlaneSuffix); } // Convert to NDC space, using the framebuffer offset and size stored in u_xywh.