summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/VertexShaderGen.cpp
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2016-08-31 01:54:05 +0200
committerJules Blok <jules.blok@gmail.com>2016-09-01 01:14:14 +0200
commitdebaf63fe8abc4d534c0cac7540eb8607e2c5c91 (patch)
tree82c84d300b0cfc00429da042a86f3f1c3a030533 /Source/Core/VideoCommon/VertexShaderGen.cpp
parent081cad709a0896e7deafe5b235a5d728d84b24d0 (diff)
VertexShaderGen: Move the sonic epsilon hack to the vertex shader.
In the vertex shader we have control over the depth clipping planes, so we don't have to offset every floating point value and lose accuracy.
Diffstat (limited to 'Source/Core/VideoCommon/VertexShaderGen.cpp')
-rw-r--r--Source/Core/VideoCommon/VertexShaderGen.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp
index a42f090716..7c4f558225 100644
--- a/Source/Core/VideoCommon/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/VertexShaderGen.cpp
@@ -408,8 +408,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.