diff --git a/dxvk.conf b/dxvk.conf index ba924e8a..1cce94d8 100644 --- a/dxvk.conf +++ b/dxvk.conf @@ -169,6 +169,16 @@ # d3d9.samplerAnisotropy = -1 +# Changes the mipmap LOD bias for all samplers. The given number will be +# added to the LOD bias provided by the application, rather than replacing +# it entirely. Positive values will reduce texture detail, while negative +# values may increase sharpness at the cost of shimmer. +# +# Supported values: Any number between -2.0 and 1.0 + +# d3d11.samplerLodBias = 0.0 + + # Declares vertex positions as invariant in order to solve # potential Z-fighting issues at a small performance cost. # diff --git a/src/d3d11/d3d11_options.cpp b/src/d3d11/d3d11_options.cpp index 5744a0bf..84d052bf 100644 --- a/src/d3d11/d3d11_options.cpp +++ b/src/d3d11/d3d11_options.cpp @@ -1,4 +1,4 @@ -#include +#include "../util/util_math.h" #include "d3d11_options.h" @@ -13,6 +13,7 @@ namespace dxvk { this->ignoreGraphicsBarriers = config.getOption("d3d11.ignoreGraphicsBarriers", false); this->maxTessFactor = config.getOption("d3d11.maxTessFactor", 0); this->samplerAnisotropy = config.getOption("d3d11.samplerAnisotropy", -1); + this->samplerLodBias = config.getOption("d3d11.samplerLodBias", 0.0f); this->invariantPosition = config.getOption("d3d11.invariantPosition", true); this->floatControls = config.getOption("d3d11.floatControls", true); this->disableMsaa = config.getOption("d3d11.disableMsaa", false); @@ -23,6 +24,9 @@ namespace dxvk { this->syncInterval = config.getOption("dxgi.syncInterval", -1); this->tearFree = config.getOption("dxgi.tearFree", Tristate::Auto); + // Clamp LOD bias so that people don't abuse this in unintended ways + this->samplerLodBias = dxvk::fclamp(this->samplerLodBias, -2.0f, 1.0f); + int32_t maxImplicitDiscardSize = config.getOption("d3d11.maxImplicitDiscardSize", 256); this->maxImplicitDiscardSize = maxImplicitDiscardSize >= 0 ? VkDeviceSize(maxImplicitDiscardSize) << 10 diff --git a/src/d3d11/d3d11_options.h b/src/d3d11/d3d11_options.h index 3c3a2616..dcbef7c3 100644 --- a/src/d3d11/d3d11_options.h +++ b/src/d3d11/d3d11_options.h @@ -61,7 +61,12 @@ namespace dxvk { /// Enforces anisotropic filtering with the /// given anisotropy value for all samplers. int32_t samplerAnisotropy; - + + /// Mipmap LOD bias + /// + /// Enforces the given LOD bias for all samplers. + float samplerLodBias; + /// Declare vertex positions in shaders as invariant bool invariantPosition; diff --git a/src/d3d11/d3d11_sampler.cpp b/src/d3d11/d3d11_sampler.cpp index e3e54cf3..8150c29c 100644 --- a/src/d3d11/d3d11_sampler.cpp +++ b/src/d3d11/d3d11_sampler.cpp @@ -44,6 +44,10 @@ namespace dxvk { if (desc.MaxAnisotropy < 1) info.maxAnisotropy = 1.0f; if (desc.MaxAnisotropy > 16) info.maxAnisotropy = 16.0f; + // Enforce LOD bias specified in the device options + if (info.minFilter == VK_FILTER_LINEAR && info.magFilter == VK_FILTER_LINEAR) + info.mipmapLodBias += device->GetOptions()->samplerLodBias; + // Enforce anisotropy specified in the device options int32_t samplerAnisotropyOption = device->GetOptions()->samplerAnisotropy; @@ -51,7 +55,7 @@ namespace dxvk { info.useAnisotropy = samplerAnisotropyOption > 0; info.maxAnisotropy = float(samplerAnisotropyOption); } - + m_sampler = device->GetDXVKDevice()->createSampler(info); }