Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VertexShaderGen: Move the sonic epsilon hack to the vertex shader. #4164

Merged
merged 1 commit into from
Sep 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Source/Core/VideoCommon/VertexShaderGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 2 additions & 5 deletions Source/Core/VideoCommon/VertexShaderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]);
Expand Down