diff --git a/Source/Core/Core/Config/GraphicsSettings.cpp b/Source/Core/Core/Config/GraphicsSettings.cpp index 6646cff79e..98a5c13bcf 100644 --- a/Source/Core/Core/Config/GraphicsSettings.cpp +++ b/Source/Core/Core/Config/GraphicsSettings.cpp @@ -107,6 +107,10 @@ const ConfigInfo GFX_ENHANCE_FORCE_TRUE_COLOR{{System::GFX, "Enhancements" true}; const ConfigInfo GFX_ENHANCE_DISABLE_COPY_FILTER{ {System::GFX, "Enhancements", "DisableCopyFilter"}, true}; +const ConfigInfo GFX_ENHANCE_ARBITRARY_MIPMAP_DETECTION{ + {System::GFX, "Enhancements", "ArbitraryMipmapDetection"}, true}; +const ConfigInfo GFX_ENHANCE_ARBITRARY_MIPMAP_DETECTION_THRESHOLD{ + {System::GFX, "Enhancements", "ArbitraryMipmapDetectionThreshold"}, 4.5f}; // Graphics.Stereoscopy diff --git a/Source/Core/Core/Config/GraphicsSettings.h b/Source/Core/Core/Config/GraphicsSettings.h index c0113ae83e..3e87298f85 100644 --- a/Source/Core/Core/Config/GraphicsSettings.h +++ b/Source/Core/Core/Config/GraphicsSettings.h @@ -85,6 +85,8 @@ extern const ConfigInfo GFX_ENHANCE_MAX_ANISOTROPY; // NOTE - this is x in extern const ConfigInfo GFX_ENHANCE_POST_SHADER; extern const ConfigInfo GFX_ENHANCE_FORCE_TRUE_COLOR; extern const ConfigInfo GFX_ENHANCE_DISABLE_COPY_FILTER; +extern const ConfigInfo GFX_ENHANCE_ARBITRARY_MIPMAP_DETECTION; +extern const ConfigInfo GFX_ENHANCE_ARBITRARY_MIPMAP_DETECTION_THRESHOLD; // Graphics.Stereoscopy diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index c1e112e69a..2ea772890a 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -500,11 +500,14 @@ public: if (levels.size() < 2) return false; + if (!g_ActiveConfig.bArbitraryMipmapDetection) + return false; + // This is the average per-pixel, per-channel difference in percent between what we // expect a normal blurred mipmap to look like and what we actually received // 4.5% was chosen because it's just below the lowest clearly-arbitrary texture // I found in my tests, the background clouds in Mario Galaxy's Observatory lobby. - constexpr auto THRESHOLD_PERCENT = 4.5f; + const auto threshold = g_ActiveConfig.fArbitraryMipmapDetectionThreshold; auto* src = downsample_buffer; auto* dst = downsample_buffer + levels[1].shape.row_length * levels[1].shape.height * 4; @@ -530,7 +533,7 @@ public: } auto all_levels = total_diff / (levels.size() - 1); - return all_levels > THRESHOLD_PERCENT; + return all_levels > threshold; } private: @@ -605,10 +608,14 @@ private: const auto* row2 = ptr2; for (u32 j = 0; j < shape.width; ++j, row1 += 4, row2 += 4) { - average_diff += std::abs(static_cast(row1[0]) - static_cast(row2[0])); - average_diff += std::abs(static_cast(row1[1]) - static_cast(row2[1])); - average_diff += std::abs(static_cast(row1[2]) - static_cast(row2[2])); - average_diff += std::abs(static_cast(row1[3]) - static_cast(row2[3])); + int pixel_diff = 0; + for (int channel = 0; channel < 4; channel++) + { + const int diff = static_cast(row1[channel]) - static_cast(row2[channel]); + const int diff_squared = diff * diff; + pixel_diff += diff_squared; + } + average_diff += pixel_diff; } ptr1 += shape.row_length; ptr2 += shape.row_length; diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index 2d7f958d8f..a0029df1e7 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -120,6 +120,9 @@ void VideoConfig::Refresh() sPostProcessingShader = Config::Get(Config::GFX_ENHANCE_POST_SHADER); bForceTrueColor = Config::Get(Config::GFX_ENHANCE_FORCE_TRUE_COLOR); bDisableCopyFilter = Config::Get(Config::GFX_ENHANCE_DISABLE_COPY_FILTER); + bArbitraryMipmapDetection = Config::Get(Config::GFX_ENHANCE_ARBITRARY_MIPMAP_DETECTION); + fArbitraryMipmapDetectionThreshold = + Config::Get(Config::GFX_ENHANCE_ARBITRARY_MIPMAP_DETECTION_THRESHOLD); stereo_mode = Config::Get(Config::GFX_STEREO_MODE); iStereoDepth = Config::Get(Config::GFX_STEREO_DEPTH); diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index c8a9e90638..ec5563de74 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -74,6 +74,8 @@ struct VideoConfig final std::string sPostProcessingShader; bool bForceTrueColor; bool bDisableCopyFilter; + bool bArbitraryMipmapDetection; + float fArbitraryMipmapDetectionThreshold; // Information bool bShowFPS;