Flip a sign for consistency

This commit is contained in:
Henrik Rydgård committed 2023-02-11 13:27:44 +01:00
1 parent 116b3ba8cc
commit 9053d8ccc7
1 file changed
+4 -2
+4 -2
View File
@@ -62,7 +62,7 @@ void GenerateDepthDownloadFs(ShaderWriter &writer) {
writer.BeginFSMain(depthUniforms, varyings);
writer.C(" float depth = ").SampleTexture2D("tex", "v_texcoord").C(".r; \n");
// At this point, clamped maps [0, 1] to [0, 65535].
writer.C(" float clamped = clamp((depth + u_depthFactor.x) * u_depthFactor.y, 0.0, 1.0);\n");
writer.C(" float clamped = clamp((depth - u_depthFactor.x) * u_depthFactor.y, 0.0, 1.0);\n");
writer.C(" vec4 enc = u_depthShift * clamped;\n");
writer.C(" enc = floor(mod(enc, 256.0)) * u_depthTo8;\n");
writer.C(" vec4 outColor = enc.yzww;\n"); // Let's ignore the bits outside 16 bit precision.
@@ -228,9 +228,11 @@ bool FramebufferManagerCommon::ReadbackDepthbuffer(Draw::Framebuffer *fbo, int x
ub.u_depthFactor[1] = fudgeFactor;
} else {
const float factor = DepthSliceFactor(gstate_c.UseFlags());
ub.u_depthFactor[0] = -0.5f * (factor - 1.0f) * (1.0f / factor);
ub.u_depthFactor[0] = 0.5f * (factor - 1.0f) * (1.0f / factor);
ub.u_depthFactor[1] = factor * fudgeFactor;
}
// These are for packing a float in u8x4 colors. We should support more suitable readback formats on APIs that can do it.
static constexpr float shifts[] = { 16777215.0f, 16777215.0f / 256.0f, 16777215.0f / 65536.0f, 16777215.0f / 16777216.0f };
memcpy(ub.u_depthShift, shifts, sizeof(shifts));
static constexpr float to8[] = { 1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f };