From 2ea8a9ac1fa06a955290928f11770964fa7798cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 3 Jun 2026 17:17:54 +0200 Subject: [PATCH] Revert "Remove unnecessary scaling and then un-scaling of through-mode Z coordinates" Didn't mean to commit this, it was supposed to go in a PR. This reverts commit 6d4c70c67d7ccc3fdd3f6210349ab43e5ab19550. --- GPU/Common/VertexDecoderCommon.h | 10 ++++++++-- GPU/Common/VertexShaderGenerator.cpp | 10 +++++++--- GPU/Software/TransformUnit.cpp | 3 ++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/GPU/Common/VertexDecoderCommon.h b/GPU/Common/VertexDecoderCommon.h index f819ea363c..696eee018d 100644 --- a/GPU/Common/VertexDecoderCommon.h +++ b/GPU/Common/VertexDecoderCommon.h @@ -134,7 +134,7 @@ public: pos[2] = f[2]; } else { // Integer value passed in a float. Clamped to 0, 65535. - pos[2] = (int)f[2]; + pos[2] = (int)f[2] * (1.0f / 65535.0f); } } @@ -144,7 +144,7 @@ public: pos[0] = f[0]; pos[1] = f[1]; // Integer value passed in a float. Clamped to 0, 65535. - pos[2] = (int)f[2]; + pos[2] = (int)f[2] * (1.0f / 65535.0f); } void ReadPosNonThrough(float pos[3]) const { @@ -153,6 +153,12 @@ public: memcpy(pos, f, 12); } + void ReadPosThroughZ16(float pos[3]) const { + // Only DEC_FLOAT_3 is supported. + const float *f = (const float *)(data_ + decFmt_.posoff); + memcpy(pos, f, 12); + } + void ReadNrm(float nrm[3]) const { switch (decFmt_.nrmfmt) { case DEC_FLOAT_3: diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index b4694db13b..0170593798 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -760,9 +760,13 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag } } WRITE(p, " %sv_fogdepth = fog;\n", compat.vsOutPrefix); - - // If non-through, the viewport has already been applied here. - WRITE(p, " vec4 outPos = position;\n"); + if (isModeThrough) { + WRITE(p, " vec4 outPos = position;\n"); + WRITE(p, " outPos.z *= 65536.0;\n"); // TODO: This multiplication should be moved to the vertex decoders for through mode. + } else { + // The viewport has already been applied here, along with the division. + WRITE(p, " vec4 outPos = position;\n"); + } if (fsMinmaxDiscard || fsDepthClamp) { WRITE(p, " %sv_zw = vec2(outPos.z * outPos.w, outPos.w);\n", compat.vsOutPrefix); diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 92a8a6c1e6..853a3ce4a2 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -350,7 +350,8 @@ ClipVertexData TransformUnit::ReadVertex(const VertexReader &vreader, const Tran ClipVertexData vertex; ModelCoords pos; - vreader.ReadPosThrough(pos.AsArray()); + // VertexDecoder normally scales z, but we want it unscaled. + vreader.ReadPosThroughZ16(pos.AsArray()); static Vec3Packedf lastTC; if (state.readUV) {