From f339bc69c8cccca9cf975927ef025d4645f00d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?bl=C3=A5haj?= Date: Fri, 2 Apr 2021 15:12:30 +0200 Subject: [PATCH] VertexShaderGen: Sonic epsilon hack for OpenGL ES debaf63fe8abc4d534c0cac7540eb8607e2c5c91 moved the "Sonic epsilon hack" to vertex shaders. However, it was only done for targets with depth clamping. If this is not available, for example the target is OpenGL ES, the Sonic problem appears (https://bugs.dolphin-emu.org/issues/11897). A version of the "Sonic epsilon hack" is added for targets without depth clamping. --- Source/Core/VideoCommon/VertexShaderGen.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index cf400a21ba..28d1e78442 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -498,6 +498,12 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho "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 * (1.0 - 1e-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.