Replace the rest of the uses of DepthSliceFactor

This commit is contained in:
Henrik Rydgård 2023-02-11 14:45:01 +01:00
parent 99e6fd62f7
commit 547ecec074
3 changed files with 6 additions and 5 deletions

View file

@ -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);

View file

@ -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,

View file

@ -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 };