From 159247f4ad51e6b8dc911357ebe8d6327ebd5a37 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 4 Aug 2016 18:27:12 +0200 Subject: [PATCH] VertexShaderGen: Clamp to the console depth range. This fixes the Mii Channel among others. --- Source/Core/VideoCommon/VertexShaderGen.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index e23be6590c..0863e9f17f 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -403,6 +403,10 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da // the normal depth range of 0..1. out.Write("o.pos.z = o.pos.w * " I_PIXELCENTERCORRECTION".w + o.pos.z * " I_PIXELCENTERCORRECTION".z;\n"); + // We have to clamp to 2^24 - 1 here, because we map our depth range to 0..2^24 to prevent round-trip errors. + // Thus we test for values that will result in 2^24 or higher after the perspective divide. + out.Write("if (o.pos.z / o.pos.w >= 1.0) o.pos.z = 16777215.0 / 16777216.0 * o.pos.w;\n"); + // write the true depth value, if the game uses depth textures pixel shaders will override with // the correct values // if not early z culling will improve speed