From 2fc7f72d72c783e1737c18d9707ba0463d7340bc Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 20 Sep 2022 15:55:39 -0700 Subject: [PATCH] GPU: Clip clamped depth accounting for perspective. --- GPU/Common/VertexShaderGenerator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index 16cce87d0f8e..adce008676d3 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -1206,14 +1206,14 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag // Everywhere else, it's 0 -> 1, simpler. WRITE(p, " if (u_depthRange.y >= 1.0) {\n"); } - WRITE(p, " %sgl_ClipDistance%s = integerZ;\n", compat.vsOutPrefix, clip0); + WRITE(p, " %sgl_ClipDistance%s = integerZ * outPos.w;\n", compat.vsOutPrefix, clip0); WRITE(p, " } else {\n"); WRITE(p, " %sgl_ClipDistance%s = 0.0;\n", compat.vsOutPrefix, clip0); WRITE(p, " }\n"); // This is similar, but for maxz when it's below 65535.0. -1/0 don't matter here. WRITE(p, " if (u_depthRange.x + u_depthRange.y <= 65534.0) {\n"); - WRITE(p, " %sgl_ClipDistance%s = 65535.0 - integerZ;\n", compat.vsOutPrefix, clip1); + WRITE(p, " %sgl_ClipDistance%s = (65535.0 - integerZ) * outPos.w;\n", compat.vsOutPrefix, clip1); WRITE(p, " } else {\n"); WRITE(p, " %sgl_ClipDistance%s = 0.0;\n", compat.vsOutPrefix, clip1); WRITE(p, " }\n");