From b940c8a8b7b8517703f2eadcb1cfa67f4fb9110d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 1 Aug 2022 15:45:05 +0200 Subject: [PATCH] Fix for D3D11 and GL, but not Vulkan for some weird reason --- GPU/Common/FragmentShaderGenerator.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index fe40acbeeb..e4bfdc84cf 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -1063,14 +1063,17 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu if (colorToDepth) { DepthScaleFactors factors = GetDepthScaleFactors(); - if (compat.bitwiseOps) { - WRITE(p, " highp float depthValue = float(uint(%s.x * 32.0) | (uint(%s.y * 64.0) << 5) | (uint(%s.z * 32.0) << 11)) / 65535.0;\n", "v", "v", "v"); // compat.fragColor0, compat.fragColor0, compat.fragColor0); + WRITE(p, " highp float depthValue = float(int(%s.x * 31.99) | (int(%s.y * 63.99) << 5) | (int(%s.z * 31.99) << 11)) / 65535.0;\n", "v", "v", "v"); // compat.fragColor0, compat.fragColor0, compat.fragColor0); } else { // D3D9-compatible alternative - WRITE(p, " highp float depthValue = (floor(%s.x * 32.0) + floor(%s.y * 64.0) * 32.0 + floor(%s.z * 32.0) * 2048.0) / 65535.0;\n", "v", "v", "v"); // compat.fragColor0, compat.fragColor0, compat.fragColor0); + WRITE(p, " highp float depthValue = (floor(%s.x * 31.99) + floor(%s.y * 63.99) * 32.0 + floor(%s.z * 31.99) * 2048.0) / 65535.0;\n", "v", "v", "v"); // compat.fragColor0, compat.fragColor0, compat.fragColor0); + } + if (factors.scale != 1.0 || factors.offset != 0.0) { + WRITE(p, " gl_FragDepth = (depthValue / %f) + %f;\n", factors.scale / 65535.0f, factors.offset); + } else { + WRITE(p, " gl_FragDepth = depthValue;\n"); } - WRITE(p, " gl_FragDepth = (depthValue / %f) + %f;\n", factors.scale / 65535.0f, factors.offset); } if (gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT)) {