Add anisotropic samplers

This commit is contained in:
Benau 2022-07-23 10:58:37 +08:00
parent e991e06640
commit 7f31ffa552
4 changed files with 90 additions and 2 deletions

View File

@ -30,6 +30,9 @@ namespace GE
{
GVS_MIN = 0,
GVS_NEAREST = GVS_MIN,
GVS_3D_MESH_MIPMAP_2,
GVS_3D_MESH_MIPMAP_4,
GVS_3D_MESH_MIPMAP_16,
GVS_2D_RENDER,
GVS_COUNT,
};

View File

@ -1344,11 +1344,53 @@ void GEVulkanDriver::createSamplers()
throw std::runtime_error("vkCreateSampler failed for GVS_NEAREST");
m_vk->samplers[GVS_NEAREST] = sampler;
const float max_aniso = m_properties.limits.maxSamplerAnisotropy;
// GVS_3D_MESH_MIPMAP_2
sampler_info.magFilter = VK_FILTER_LINEAR;
sampler_info.minFilter = VK_FILTER_LINEAR;
sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
sampler_info.maxAnisotropy = std::min(2.0f, max_aniso);
result = vkCreateSampler(m_vk->device, &sampler_info, NULL,
&sampler);
if (result != VK_SUCCESS)
{
throw std::runtime_error(
"vkCreateSampler failed for GVS_3D_MESH_MIPMAP_2");
}
m_vk->samplers[GVS_3D_MESH_MIPMAP_2] = sampler;
// GVS_3D_MESH_MIPMAP_4
sampler_info.maxAnisotropy = std::min(4.0f, max_aniso);
result = vkCreateSampler(m_vk->device, &sampler_info, NULL,
&sampler);
if (result != VK_SUCCESS)
{
throw std::runtime_error(
"vkCreateSampler failed for GVS_3D_MESH_MIPMAP_4");
}
m_vk->samplers[GVS_3D_MESH_MIPMAP_4] = sampler;
// GVS_3D_MESH_MIPMAP_16
sampler_info.maxAnisotropy = std::min(16.0f, max_aniso);
result = vkCreateSampler(m_vk->device, &sampler_info, NULL,
&sampler);
if (result != VK_SUCCESS)
{
throw std::runtime_error(
"vkCreateSampler failed for GVS_3D_MESH_MIPMAP_16");
}
m_vk->samplers[GVS_3D_MESH_MIPMAP_16] = sampler;
// GVS_2D_RENDER
sampler_info.magFilter = VK_FILTER_LINEAR;
sampler_info.minFilter = VK_FILTER_LINEAR;
// Avoid artifacts when resizing down the screen
sampler_info.maxLod = 0.25f;
sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
sampler_info.maxAnisotropy = 1.0f;
result = vkCreateSampler(m_vk->device, &sampler_info, NULL,
&sampler);

View File

@ -97,6 +97,8 @@
#ifndef SERVER_ONLY
#include <ge_main.hpp>
#include <ge_vulkan_driver.hpp>
#include <ge_vulkan_texture_descriptor.hpp>
#endif
#ifdef ENABLE_RECORDER
@ -606,6 +608,29 @@ void IrrDriver::initDevice()
#ifndef SERVER_ONLY
GE::setVideoDriver(m_device->getVideoDriver());
GE::GEVulkanDriver* vk = GE::getVKDriver();
if (vk)
{
GE::GEVulkanTextureDescriptor* td = vk->getMeshTextureDescriptor();
switch (UserConfigParams::m_anisotropic)
{
case 16:
td->setSamplerUse(GE::GVS_3D_MESH_MIPMAP_16);
break;
case 4:
td->setSamplerUse(GE::GVS_3D_MESH_MIPMAP_4);
break;
case 2:
td->setSamplerUse(GE::GVS_3D_MESH_MIPMAP_2);
break;
default:
Log::warn("irr_driver", "Unsupported anisotropic values, revert");
UserConfigParams::m_anisotropic = 16;
td->setSamplerUse(GE::GVS_3D_MESH_MIPMAP_16);
break;
}
}
// Assume sp is supported
CentralVideoSettings::m_supports_sp = true;
CVS->init();

View File

@ -41,6 +41,13 @@
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
#ifndef SERVER_ONLY
#include <ge_main.hpp>
#include <ge_vulkan_driver.hpp>
#include <ge_vulkan_texture_descriptor.hpp>
#endif
#include <iostream>
#include <sstream>
@ -151,26 +158,37 @@ int OptionsScreenVideo::getImageQuality()
// --------------------------------------------------------------------------------------------
void OptionsScreenVideo::setImageQuality(int quality)
{
#ifndef SERVER_ONLY
GE::GEVulkanTextureDescriptor* td = NULL;
if (GE::getVKDriver())
td = GE::getVKDriver()->getMeshTextureDescriptor();
switch (quality)
{
case 0:
UserConfigParams::m_anisotropic = 2;
UserConfigParams::m_high_definition_textures = 0x02;
UserConfigParams::m_hq_mipmap = false;
if (td)
td->setSamplerUse(GE::GVS_3D_MESH_MIPMAP_2);
break;
case 1:
UserConfigParams::m_anisotropic = 4;
UserConfigParams::m_high_definition_textures = 0x03;
UserConfigParams::m_hq_mipmap = false;
if (td)
td->setSamplerUse(GE::GVS_3D_MESH_MIPMAP_4);
break;
case 2:
UserConfigParams::m_anisotropic = 16;
UserConfigParams::m_high_definition_textures = 0x03;
UserConfigParams::m_hq_mipmap = true;
if (td)
td->setSamplerUse(GE::GVS_3D_MESH_MIPMAP_16);
break;
default:
assert(false);
}
#endif
} // setImageQuality
// --------------------------------------------------------------------------------------------
@ -444,10 +462,10 @@ void OptionsScreenVideo::init()
applyBtn->setActive(!in_game);
#ifndef SERVER_ONLY
gfx->setActive(!in_game && CVS->isGLSL());
#endif
getWidget<ButtonWidget>("custom")->setActive(!in_game);
getWidget<ButtonWidget>("custom")->setActive(!in_game || !CVS->isGLSL());
if (getWidget<SpinnerWidget>("scale_rtts")->isActivated())
getWidget<SpinnerWidget>("scale_rtts")->setActive(!in_game);
#endif
#if defined(MOBILE_STK) || defined(__SWITCH__)
applyBtn->setVisible(false);