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

Hackfix for clipping in Gormiti #9914

Closed
Closed
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
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Software/Clipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static inline int CalcClipMask(const OutputVertexData* v)
if (pos.y + pos.w < 0)
cmask |= CLIP_NEG_Y_BIT;

if (pos.w * pos.z > 0)
if (pos.w * pos.z >= 0)
cmask |= CLIP_POS_Z_BIT;

if (pos.z + pos.w < 0)
Expand Down
8 changes: 7 additions & 1 deletion Source/Core/VideoCommon/UberShaderVertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
// own clipping. We want to clip so that -w <= z <= 0, which matches the console -1..0 range.
// 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("float clipDepth = (o.pos.z + 1e-7) * (1.0 - 2e-7);\n"
"float clipDist0 = clipDepth + o.pos.w;\n" // Near: z < -w
"float clipDist1 = -clipDepth;\n"); // Far: z > 0
if (host_config.backend_geometry_shaders)
Expand All @@ -278,6 +278,12 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
"o.clipDist1 = clipDist1;\n");
}
}
else
{
// Same depth adjustment for Sonic. Without depth clamping, it unfortunately
// affects non-clipping uses of depth too.
out.Write("o.pos.z = (o.pos.z + 1e-7) * (1.0 - 2e-7);\n");
}

// Write the true depth value. If the game uses depth textures, then the pixel shader will
// override it with the correct values if not then early z culling will improve speed.
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/VertexShaderGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
// own clipping. We want to clip so that -w <= z <= 0, which matches the console -1..0 range.
// 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("float clipDepth = (o.pos.z + 1e-7) * (1.0 - 2e-7);\n"
"float clipDist0 = clipDepth + o.pos.w;\n" // Near: z < -w
"float clipDist1 = -clipDepth;\n"); // Far: z > 0

Expand All @@ -498,7 +498,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
{
// Same depth adjustment for Sonic. Without depth clamping, it unfortunately
// affects non-clipping uses of depth too.
out.Write("o.pos.z = o.pos.z * (1.0 - 1e-7);\n");
out.Write("o.pos.z = (o.pos.z + 1e-7) * (1.0 - 2e-7);\n");
}

// Write the true depth value. If the game uses depth textures, then the pixel shader will
Expand Down