summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2016-08-03 02:01:36 +0200
committerJules Blok <jules.blok@gmail.com>2016-08-15 13:11:23 +0200
commitc223bd47b9b2a83ed53201964e4912e2faec3d66 (patch)
tree914c4ae4ca1f8c01fbccef8516024fcf2f86914e /Source
parent0015d2e86b76772a57fb4554c84c4b47adce341e (diff)
VideoCommon: Implement depth range equation in vertex shader.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/VideoBackends/OGL/Render.cpp8
-rw-r--r--Source/Core/VideoCommon/VertexShaderGen.cpp10
-rw-r--r--Source/Core/VideoCommon/VertexShaderManager.cpp5
3 files changed, 11 insertions, 12 deletions
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<float>(
- xfmem.viewport.farZ -
- MathUtil::Clamp<float>(xfmem.viewport.zRange, -16777216.0f, 16777216.0f),
- 0.0f, 16777215.0f) /
- 16777216.0f;
- float GLFar = MathUtil::Clamp<float>(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<GLint>(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();