diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index bde616deac..26f1c8cc21 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1115,12 +1115,6 @@ void Renderer::SetViewport() (float)scissorYOff); float Width = EFBToScaledXf(2.0f * xfmem.viewport.wd); float Height = EFBToScaledYf(-2.0f * xfmem.viewport.ht); - float GLNear = MathUtil::Clamp( - xfmem.viewport.farZ - - MathUtil::Clamp(xfmem.viewport.zRange, -16777216.0f, 16777216.0f), - 0.0f, 16777215.0f) / - 16777216.0f; - float GLFar = MathUtil::Clamp(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f; if (Width < 0) { X += Width; @@ -1142,7 +1136,7 @@ void Renderer::SetViewport() auto iceilf = [](float f) { return static_cast(ceilf(f)); }; glViewport(iceilf(X), iceilf(Y), iceilf(Width), iceilf(Height)); } - glDepthRangef(GLFar, GLNear); + glDepthRangef(0.0f, 1.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 aa69550bd8..e23be6590c 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -399,14 +399,14 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da out.Write("o.colors_1 = color1;\n"); } + // 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"); + // write the true depth value, if the game uses depth textures pixel shaders will override with // the correct values // if not early z culling will improve speed - if (g_ActiveConfig.backend_info.bSupportsClipControl) - { - out.Write("o.pos.z = -o.pos.z;\n"); - } - else // OGL + if (!g_ActiveConfig.backend_info.bSupportsClipControl) { // this results in a scale from -1..0 to -1..1 after perspective // divide diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 19fb1f371d..0fb784167d 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -386,6 +386,11 @@ void VertexShaderManager::SetConstants() const float pixel_size_y = 2.f / Renderer::EFBToScaledXf(2.f * xfmem.viewport.ht); 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. + constants.pixelcentercorrection[2] = (xfmem.viewport.zRange) / 16777216.0f; + constants.pixelcentercorrection[3] = (xfmem.viewport.farZ) / 16777216.0f; + dirty = true; // This is so implementation-dependent that we can't have it here. g_renderer->SetViewport();