diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index c6ee43f9ea..4cd163feab 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -1185,13 +1185,15 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu } if (gstate_c.Use(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT)) { - const double scale = DepthSliceFactor(gstate_c.UseFlags()) * 65535.0; + DepthScaleFactors depthScale = GetDepthScaleFactors(gstate_c.UseFlags()); + + const double scale = depthScale.ScaleU16(); WRITE(p, " highp float z = gl_FragCoord.z;\n"); if (gstate_c.Use(GPU_USE_ACCURATE_DEPTH)) { // We center the depth with an offset, but only its fraction matters. // When (DepthSliceFactor() - 1) is odd, it will be 0.5, otherwise 0. - if (((int)(DepthSliceFactor(gstate_c.UseFlags()) - 1.0f) & 1) == 1) { + if (((int)(depthScale.Scale() - 1.0f) & 1) == 1) { WRITE(p, " z = (floor((z * %f) - (1.0 / 2.0)) + (1.0 / 2.0)) * (1.0 / %f);\n", scale, scale); } else { WRITE(p, " z = floor(z * %f) * (1.0 / %f);\n", scale, scale); diff --git a/GPU/Common/GPUStateUtils.h b/GPU/Common/GPUStateUtils.h index ed021bbb83..a786190f60 100644 --- a/GPU/Common/GPUStateUtils.h +++ b/GPU/Common/GPUStateUtils.h @@ -120,9 +120,6 @@ private: DepthScaleFactors GetDepthScaleFactors(u32 useFlags); -// This will be replaced with just DepthScaleFactors. -float DepthSliceFactor(u32 useFlags); - // These are common to all modern APIs and can be easily converted with a lookup table. enum class BlendFactor : uint8_t { ZERO, diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index 5e5f6e8d63..fcbe56f282 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -797,6 +797,8 @@ static bool TestSmallDataConvert() { return true; } +float DepthSliceFactor(u32 useFlags); + static bool TestDepthMath() { // These are in normalized space. static const volatile float testValues[] = { 0.0f, 0.1f, 0.5f, M_PI / 4.0f, 0.9f, 1.0f };