summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2016-09-01 15:28:09 +0200
committerGitHub <noreply@github.com>2016-09-01 15:28:09 +0200
commit50984d85b0bbef3ba97d7833ccc126c5f6a90c4a (patch)
treeca3fb24ff61f4e37c6209edccdaf5313bc03193c /Source/Core/VideoCommon
parentb7933c49b62c3d00a7f8f9d9a89d5b499accefee (diff)
parentdebaf63fe8abc4d534c0cac7540eb8607e2c5c91 (diff)
Merge pull request #4164 from Armada651/sonic-clipping
VertexShaderGen: Move the sonic epsilon hack to the vertex shader.
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/VertexShaderGen.cpp7
-rw-r--r--Source/Core/VideoCommon/VertexShaderManager.cpp7
2 files changed, 7 insertions, 7 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp
index ba7fc3a02e..8376d6b8ea 100644
--- a/Source/Core/VideoCommon/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/VertexShaderGen.cpp
@@ -420,8 +420,11 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da
// Since we're adjusting z for the depth range before the perspective divide, we have to do our
// own clipping. We want to clip so that -w <= z <= 0, which matches the console -1..0 range.
- out.Write("o.clipDist0 = o.pos.z + o.pos.w;\n"); // Near: z < -w
- out.Write("o.clipDist1 = -o.pos.z;\n"); // Far: z > 0
+ // We adjust our depth value for clipping purposes to match the perspective projection in the
+ // software backend, which is a hack to fix Sonic Adventure and Unleashed games.
+ out.Write("float clipDepth = o.pos.z * (1.0 - 1e-7);\n");
+ out.Write("o.clipDist0 = clipDepth + o.pos.w;\n"); // Near: z < -w
+ out.Write("o.clipDist1 = -clipDepth;\n"); // Far: z > 0
// Adjust z for the depth range. We're using an equation which incorperates a depth inversion,
// so we can map the console -1..0 range to the 0..1 range used in the depth buffer.
diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp
index e8f82d0bf5..11f5be0ab5 100644
--- a/Source/Core/VideoCommon/VertexShaderManager.cpp
+++ b/Source/Core/VideoCommon/VertexShaderManager.cpp
@@ -454,8 +454,7 @@ void VertexShaderManager::SetConstants()
g_fProjectionMatrix[12] = 0.0f;
g_fProjectionMatrix[13] = 0.0f;
- // Hack to fix depth clipping precision issues (such as Sonic Adventure UI)
- g_fProjectionMatrix[14] = -(1.0f + FLT_EPSILON);
+ g_fProjectionMatrix[14] = -1.0f;
g_fProjectionMatrix[15] = 0.0f;
// Heuristic to detect if a GameCube game is in 16:9 anamorphic widescreen mode.
@@ -511,9 +510,7 @@ void VertexShaderManager::SetConstants()
g_fProjectionMatrix[13] = 0.0f;
g_fProjectionMatrix[14] = 0.0f;
-
- // Hack to fix depth clipping precision issues (such as Sonic Unleashed UI)
- g_fProjectionMatrix[15] = 1.0f + FLT_EPSILON;
+ g_fProjectionMatrix[15] = 1.0f;
SETSTAT_FT(stats.g2proj_0, g_fProjectionMatrix[0]);
SETSTAT_FT(stats.g2proj_1, g_fProjectionMatrix[1]);