mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-23 04:52:07 +00:00
Merge pull request #681 from rg3/aniso_rework
Vulkan anisotropic filter tweaks
This commit is contained in:
commit
3371cf3014
9 changed files with 41 additions and 77 deletions
|
@ -245,8 +245,6 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable`
|
|||
dependent on the GPU driver, most of them support `1`, `2`, `4`, `8`
|
||||
and `16`. Anisotropic filtering gives a huge improvement to texture
|
||||
quality by a negligible performance impact.
|
||||
If vulkan render have used, flag is only toggle anisotropic filtering
|
||||
without use specific level.
|
||||
|
||||
* **r_msaa_samples**: Full scene anti aliasing samples. The number of
|
||||
samples depends on the GPU driver, most drivers support at least `2`,
|
||||
|
@ -438,8 +436,6 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable`
|
|||
|
||||
* **vk_lightmap**: Display lightmaps. (default: `0`)
|
||||
|
||||
* **vk_aniso**: Toggle anisotropic filtering. (default: `1`)
|
||||
|
||||
* **vk_postprocess**: Toggle additional color/gamma correction.
|
||||
(default: `1`)
|
||||
|
||||
|
|
|
@ -136,21 +136,6 @@ FOVCallback(void *s) {
|
|||
Cvar_SetValue("fov", slider->curvalue);
|
||||
}
|
||||
|
||||
static void
|
||||
AnisotropicCallback(void *s)
|
||||
{
|
||||
menulist_s *list = (menulist_s *)s;
|
||||
|
||||
if (list->curvalue == 0)
|
||||
{
|
||||
Cvar_SetValue("r_anisotropic", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Cvar_SetValue("r_anisotropic", pow(2, list->curvalue));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ResetDefaults(void *unused)
|
||||
{
|
||||
|
@ -258,6 +243,24 @@ ApplyChanges(void *unused)
|
|||
restart = true;
|
||||
}
|
||||
|
||||
/* anisotropic filtering */
|
||||
if (s_af_list.curvalue == 0)
|
||||
{
|
||||
if (gl_anisotropic->value != 0)
|
||||
{
|
||||
Cvar_SetValue("r_anisotropic", 0);
|
||||
restart = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gl_anisotropic->value != pow(2, s_af_list.curvalue))
|
||||
{
|
||||
Cvar_SetValue("r_anisotropic", pow(2, s_af_list.curvalue));
|
||||
restart = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* multisample anti-aliasing */
|
||||
if (s_msaa_list.curvalue == 0)
|
||||
{
|
||||
|
@ -536,7 +539,6 @@ VID_MenuInit(void)
|
|||
s_af_list.generic.name = "aniso filtering";
|
||||
s_af_list.generic.x = 0;
|
||||
s_af_list.generic.y = (y += 10);
|
||||
s_af_list.generic.callback = AnisotropicCallback;
|
||||
s_af_list.itemnames = pow2_names;
|
||||
s_af_list.curvalue = 0;
|
||||
if (gl_anisotropic->value)
|
||||
|
|
|
@ -206,10 +206,6 @@ R_TextureMode(char *string)
|
|||
{
|
||||
ri.Cvar_SetValue("r_anisotropic", gl_config.max_anisotropy);
|
||||
}
|
||||
else if (gl_anisotropic->value < 1.0)
|
||||
{
|
||||
ri.Cvar_SetValue("r_anisotropic", 1.0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -236,7 +232,7 @@ R_TextureMode(char *string)
|
|||
if (gl_config.anisotropic && gl_anisotropic->value)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
||||
gl_anisotropic->value);
|
||||
max(gl_anisotropic->value, 1.f));
|
||||
}
|
||||
}
|
||||
else /* texture has no mipmaps */
|
||||
|
@ -753,7 +749,7 @@ R_Upload32(unsigned *data, int width, int height, qboolean mipmap)
|
|||
if (mipmap && gl_config.anisotropic && gl_anisotropic->value)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
||||
gl_anisotropic->value);
|
||||
max(gl_anisotropic->value, 1.f));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -78,10 +78,6 @@ GL3_TextureMode(char *string)
|
|||
{
|
||||
ri.Cvar_SetValue("r_anisotropic", gl3config.max_anisotropy);
|
||||
}
|
||||
else if (gl_anisotropic->value < 1.0)
|
||||
{
|
||||
ri.Cvar_SetValue("r_anisotropic", 1.0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -110,7 +106,7 @@ GL3_TextureMode(char *string)
|
|||
/* Set anisotropic filter if supported and enabled */
|
||||
if (gl3config.anisotropic && gl_anisotropic->value)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_anisotropic->value);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max(gl_anisotropic->value, 1.f));
|
||||
}
|
||||
}
|
||||
else /* texture has no mipmaps */
|
||||
|
@ -216,7 +212,7 @@ GL3_Upload32(unsigned *data, int width, int height, qboolean mipmap)
|
|||
|
||||
if (mipmap && gl3config.anisotropic && gl_anisotropic->value)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_anisotropic->value);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max(gl_anisotropic->value, 1.f));
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
|
@ -50,13 +50,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
// fall over
|
||||
#define ROLL 2
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
extern viddef_t vid;
|
||||
|
||||
typedef struct image_s
|
||||
|
|
|
@ -68,12 +68,8 @@ typedef enum
|
|||
S_LINEAR = 1,
|
||||
S_MIPMAP_NEAREST = 2,
|
||||
S_MIPMAP_LINEAR = 3,
|
||||
S_ANISO_NEAREST = 4,
|
||||
S_ANISO_LINEAR = 5,
|
||||
S_ANISO_MIPMAP_NEAREST = 6,
|
||||
S_ANISO_MIPMAP_LINEAR = 7,
|
||||
S_NEAREST_UNNORMALIZED = 8,
|
||||
S_SAMPLER_CNT = 9
|
||||
S_NEAREST_UNNORMALIZED = 4,
|
||||
S_SAMPLER_CNT = 5
|
||||
} qvksampler_t;
|
||||
|
||||
#define NUM_SAMPLERS (S_SAMPLER_CNT * 2)
|
||||
|
|
|
@ -861,6 +861,14 @@ static void CreateSamplersHelper(VkSampler *samplers, VkSamplerAddressMode addre
|
|||
.unnormalizedCoordinates = VK_FALSE
|
||||
};
|
||||
|
||||
assert((vk_device.properties.limits.maxSamplerAnisotropy > 1.f) && "maxSamplerAnisotropy is 1");
|
||||
if (vk_device.features.samplerAnisotropy && vk_aniso->value > 0.f)
|
||||
{
|
||||
const float maxAniso = min(max(vk_aniso->value, 1.f), vk_device.properties.limits.maxSamplerAnisotropy);
|
||||
samplerInfo.anisotropyEnable = VK_TRUE;
|
||||
samplerInfo.maxAnisotropy = maxAniso;
|
||||
}
|
||||
|
||||
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_NEAREST]));
|
||||
QVk_DebugSetObjectName((uint64_t)samplers[S_NEAREST], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_NEAREST");
|
||||
|
||||
|
@ -874,6 +882,8 @@ static void CreateSamplersHelper(VkSampler *samplers, VkSamplerAddressMode addre
|
|||
nuSamplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
nuSamplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
nuSamplerInfo.unnormalizedCoordinates = VK_TRUE;
|
||||
nuSamplerInfo.anisotropyEnable = VK_FALSE;
|
||||
nuSamplerInfo.maxAnisotropy = 1.f;
|
||||
|
||||
VK_VERIFY(vkCreateSampler(vk_device.logical, &nuSamplerInfo, NULL, &samplers[S_NEAREST_UNNORMALIZED]));
|
||||
QVk_DebugSetObjectName((uint64_t)samplers[S_NEAREST_UNNORMALIZED], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_NEAREST_UNNORMALIZED");
|
||||
|
@ -892,36 +902,6 @@ static void CreateSamplersHelper(VkSampler *samplers, VkSamplerAddressMode addre
|
|||
samplerInfo.maxLod = 1.f;
|
||||
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_LINEAR]));
|
||||
QVk_DebugSetObjectName((uint64_t)samplers[S_LINEAR], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_LINEAR");
|
||||
|
||||
// aniso samplers
|
||||
assert((vk_device.properties.limits.maxSamplerAnisotropy > 1.f) && "maxSamplerAnisotropy is 1");
|
||||
|
||||
samplerInfo.magFilter = VK_FILTER_NEAREST;
|
||||
samplerInfo.minFilter = VK_FILTER_NEAREST;
|
||||
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
|
||||
if (vk_device.features.samplerAnisotropy)
|
||||
{
|
||||
samplerInfo.anisotropyEnable = VK_TRUE;
|
||||
samplerInfo.maxAnisotropy = vk_device.properties.limits.maxSamplerAnisotropy;
|
||||
}
|
||||
samplerInfo.maxLod = 1.f;
|
||||
|
||||
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_ANISO_NEAREST]));
|
||||
QVk_DebugSetObjectName((uint64_t)samplers[S_ANISO_NEAREST], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_ANISO_NEAREST");
|
||||
|
||||
samplerInfo.maxLod = FLT_MAX;
|
||||
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_ANISO_MIPMAP_NEAREST]));
|
||||
QVk_DebugSetObjectName((uint64_t)samplers[S_ANISO_MIPMAP_NEAREST], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_ANISO_MIPMAP_NEAREST");
|
||||
|
||||
samplerInfo.magFilter = VK_FILTER_LINEAR;
|
||||
samplerInfo.minFilter = VK_FILTER_LINEAR;
|
||||
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
||||
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_ANISO_MIPMAP_LINEAR]));
|
||||
QVk_DebugSetObjectName((uint64_t)samplers[S_ANISO_MIPMAP_LINEAR], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_ANISO_MIPMAP_LINEAR");
|
||||
|
||||
samplerInfo.maxLod = 1.f;
|
||||
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_ANISO_LINEAR]));
|
||||
QVk_DebugSetObjectName((uint64_t)samplers[S_ANISO_LINEAR], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_ANISO_LINEAR");
|
||||
}
|
||||
|
||||
// internal helper
|
||||
|
|
|
@ -666,7 +666,6 @@ void Vk_TextureMode( char *string )
|
|||
memcpy(prev_mode, string, strlen(string));
|
||||
prev_mode[strlen(string)] = '\0';
|
||||
|
||||
i += vk_aniso->value > 0 ? NUM_VK_MODES : 0;
|
||||
vk_current_sampler = i;
|
||||
|
||||
vkDeviceWaitIdle(vk_device.logical);
|
||||
|
@ -707,7 +706,6 @@ void Vk_LmapTextureMode( char *string )
|
|||
memcpy(prev_mode, string, strlen(string));
|
||||
prev_mode[strlen(string)] = '\0';
|
||||
|
||||
i += vk_aniso->value > 0 ? NUM_VK_MODES : 0;
|
||||
vk_current_lmap_sampler = i;
|
||||
|
||||
vkDeviceWaitIdle(vk_device.logical);
|
||||
|
|
|
@ -90,6 +90,13 @@ typedef unsigned char byte;
|
|||
#define YAW 1 /* left / right */
|
||||
#define ROLL 2 /* fall over */
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#define MAX_STRING_CHARS 2048 /* max length of a string passed to Cmd_TokenizeString */
|
||||
#define MAX_STRING_TOKENS 80 /* max tokens resulting from Cmd_TokenizeString */
|
||||
#define MAX_TOKEN_CHARS 1024 /* max length of an individual token */
|
||||
|
|
Loading…
Reference in a new issue