From 67c911d13fd14f8e42b71b731eebd1bb175cac87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 24 Aug 2022 17:13:12 +0200 Subject: [PATCH] Fix smoothed CLUT lookups. Shouldn't go beyond the mask's reach. Should help #15896 --- GPU/Common/DepalettizeShaderCommon.cpp | 5 ++--- GPU/Common/FragmentShaderGenerator.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/GPU/Common/DepalettizeShaderCommon.cpp b/GPU/Common/DepalettizeShaderCommon.cpp index 15906c616e..902b180510 100644 --- a/GPU/Common/DepalettizeShaderCommon.cpp +++ b/GPU/Common/DepalettizeShaderCommon.cpp @@ -288,7 +288,7 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config) { void GenerateDepalSmoothed(ShaderWriter &writer, const DepalConfig &config) { const char *sourceChannel = "error"; - float indexMultiplier = 32.0f; + float indexMultiplier = 31.0f; if (config.bufferFormat == GE_FORMAT_5551) { _dbg_assert_(config.mask == 0x1F); @@ -302,7 +302,7 @@ void GenerateDepalSmoothed(ShaderWriter &writer, const DepalConfig &config) { _dbg_assert_(config.mask == 0x1F || config.mask == 0x3F); switch (config.shift) { case 0: sourceChannel = "r"; break; - case 5: sourceChannel = "g"; indexMultiplier = 64.0f; break; + case 5: sourceChannel = "g"; indexMultiplier = 63.0f; break; case 11: sourceChannel = "b"; break; default: _dbg_assert_(false); } @@ -311,7 +311,6 @@ void GenerateDepalSmoothed(ShaderWriter &writer, const DepalConfig &config) { } writer.C(" float index = ").SampleTexture2D("tex", "v_texcoord").F(".%s * %0.1f;\n", sourceChannel, indexMultiplier); - float texturePixels = 256.f; if (config.clutFormat != GE_CMODE_32BIT_ABGR8888) { texturePixels = 512.f; diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index 35a0e9daf7..77c8042435 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -605,13 +605,15 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu // Restrictions on this are checked before setting the smoothed flag. // Only RGB565 and RGBA5551 are supported, and only the specific shifts hitting the // channels directly. + // Also, since we know the CLUT is smooth, we do not need to do the bilinear filter manually, we can just + // lookup with the filtered value once. WRITE(p, " vec4 t = %s(tex, %s.xy);\n", compat.texture, texcoord); WRITE(p, " uint depalShift = (u_depal_mask_shift_off_fmt >> 8) & 0xFFU;\n"); WRITE(p, " uint depalFmt = (u_depal_mask_shift_off_fmt >> 24) & 0x3U;\n"); WRITE(p, " float index0 = t.r;\n"); - WRITE(p, " float factor = 32.0 / 256.0;\n"); + WRITE(p, " float factor = 31.0 / 256.0;\n"); WRITE(p, " if (depalFmt == 0u) {\n"); // yes, different versions of Test Drive use different formats. Could do compile time by adding more compat flags but meh. - WRITE(p, " if (depalShift == 5u) { index0 = t.g; factor = 64.0 / 256.0; }\n"); + WRITE(p, " if (depalShift == 5u) { index0 = t.g; factor = 63.0 / 256.0; }\n"); WRITE(p, " else if (depalShift == 11u) { index0 = t.b; }\n"); WRITE(p, " } else {\n"); WRITE(p, " if (depalShift == 5u) { index0 = t.g; }\n");