diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index fb40705279..692bf36e51 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1138,7 +1138,7 @@ void Renderer::SetViewport() auto iceilf = [](float f) { return static_cast(ceilf(f)); }; glViewport(iceilf(X), iceilf(Y), iceilf(Width), iceilf(Height)); } - glDepthRangef(0.0f, 16777215.0f / 16777216.0f); + glDepthRangef(16777215.0f / 16777216.0f, 0.0f); } void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 518c75244c..9110cbfe99 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -405,7 +405,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da // We have to handle the depth range in the vertex shader, because some games will use a depth range beyond // the normal depth range of 0..1. - out.Write("o.pos.z = o.pos.w * " I_PIXELCENTERCORRECTION".w + o.pos.z * " I_PIXELCENTERCORRECTION".z;\n"); + out.Write("o.pos.z = o.pos.w * " I_PIXELCENTERCORRECTION".w - o.pos.z * " I_PIXELCENTERCORRECTION".z;\n"); // write the true depth value, if the game uses depth textures pixel shaders will override with // the correct values @@ -414,7 +414,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da { // this results in a scale from -1..0 to -1..1 after perspective // divide - out.Write("o.pos.z = o.pos.z * -2.0 - o.pos.w;\n"); + out.Write("o.pos.z = o.pos.z * 2.0 - o.pos.w;\n"); // the next steps of the OGL pipeline are: // (x_c,y_c,z_c,w_c) = o.pos //switch to OGL spec terminology diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 83600463e9..dabc7870fd 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -387,9 +387,12 @@ void VertexShaderManager::SetConstants() constants.pixelcentercorrection[0] = pixel_center_correction * pixel_size_x; constants.pixelcentercorrection[1] = pixel_center_correction * pixel_size_y; - // The depth range is handled in the vertex shader. + // The depth range is handled in the vertex shader. We need to reverse + // the far value to get a reversed depth range mapping. This is necessary + // because we have the most precision at the near plane, while the console + // has the most percision at the far plane. constants.pixelcentercorrection[2] = xfmem.viewport.zRange / 16777215.0f; - constants.pixelcentercorrection[3] = xfmem.viewport.farZ / 16777215.0f; + constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f; dirty = true; // This is so implementation-dependent that we can't have it here.