Skip to content

Commit

Permalink
Hackfix for clipping in Gromiti
Browse files Browse the repository at this point in the history
  • Loading branch information
Pokechu22 committed Jul 18, 2021
1 parent 6e7698a commit 914297b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
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

0 comments on commit 914297b

Please sign in to comment.