r.MaxAnisotropy
r.MaxAnisotropy
#Overview
name: r.MaxAnisotropy
The value of this variable can be defined or overridden in .ini config files. 13
.ini config files referencing this setting variable.
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
MaxAnisotropy should range from 1 to 16. Higher values mean better texure quality when using anisotropic filtering but at a cost to performance. Default is 4.
It is referenced in 7
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.MaxAnisotropy is to control the maximum level of anisotropic filtering applied to textures in the rendering system. This setting affects the quality of texture rendering, particularly for surfaces viewed at oblique angles.
This setting variable is primarily used in the Unreal Engine’s rendering subsystem. It’s referenced in various parts of the engine, including the Core, Engine, and RHI (Rendering Hardware Interface) modules, as well as the ImgMedia plugin.
The value of this variable is set through the console variable system. It’s initialized with a default value of 4, but can be changed at runtime through console commands or programmatically.
Several other variables and systems interact with r.MaxAnisotropy:
- It’s used in calculating mip levels for image media assets.
- It’s part of the engine’s scalability settings.
- It’s used in texture LOD (Level of Detail) settings.
- It affects sampler state refreshes in the rendering system.
- It’s used in streamable texture resources.
Developers should be aware that:
- The valid range for this variable is 1 to 16.
- Higher values provide better texture quality but at a performance cost.
- Changes to this value can trigger a refresh of sampler states, which could impact performance if changed frequently.
Best practices when using this variable include:
- Use the default value (4) unless there’s a specific need for higher quality or better performance.
- Consider exposing this as a user-configurable graphics option for PC games.
- Be cautious about setting this too high on lower-end hardware, as it can impact performance.
- When setting custom values, use the FMath::Clamp function to ensure the value stays within the valid range.
- Consider the performance implications when changing this value dynamically during gameplay.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseScalability.ini:560, section: [TextureQuality@0]
- INI Section:
TextureQuality@0
- Raw value:
0
- Is Array:
False
Location: <Workspace>/Engine/Config/BaseScalability.ini:571, section: [TextureQuality@1]
- INI Section:
TextureQuality@1
- Raw value:
2
- Is Array:
False
Location: <Workspace>/Engine/Config/BaseScalability.ini:582, section: [TextureQuality@2]
- INI Section:
TextureQuality@2
- Raw value:
4
- Is Array:
False
Location: <Workspace>/Engine/Config/BaseScalability.ini:593, section: [TextureQuality@3]
- INI Section:
TextureQuality@3
- Raw value:
8
- Is Array:
False
Location: <Workspace>/Engine/Config/BaseScalability.ini:604, section: [TextureQuality@Cine]
- INI Section:
TextureQuality@Cine
- Raw value:
8
- Is Array:
False
Location: <Workspace>/Engine/Config/Android/AndroidScalability.ini:201, section: [TextureQuality@0]
- INI Section:
TextureQuality@0
- Raw value:
1
- Is Array:
False
Location: <Workspace>/Engine/Config/Android/AndroidScalability.ini:205, section: [TextureQuality@1]
- INI Section:
TextureQuality@1
- Raw value:
1
- Is Array:
False
Location: <Workspace>/Engine/Config/Android/AndroidScalability.ini:209, section: [TextureQuality@2]
- INI Section:
TextureQuality@2
- Raw value:
2
- Is Array:
False
Location: <Workspace>/Engine/Config/Android/AndroidScalability.ini:213, section: [TextureQuality@3]
- INI Section:
TextureQuality@3
- Raw value:
4
- Is Array:
False
Location: <Workspace>/Engine/Config/IOS/IOSScalability.ini:201, section: [TextureQuality@0]
- INI Section:
TextureQuality@0
- Raw value:
1
- Is Array:
False
Location: <Workspace>/Engine/Config/IOS/IOSScalability.ini:205, section: [TextureQuality@1]
- INI Section:
TextureQuality@1
- Raw value:
1
- Is Array:
False
Location: <Workspace>/Engine/Config/IOS/IOSScalability.ini:209, section: [TextureQuality@2]
- INI Section:
TextureQuality@2
- Raw value:
2
- Is Array:
False
Location: <Workspace>/Engine/Config/IOS/IOSScalability.ini:213, section: [TextureQuality@3]
- INI Section:
TextureQuality@3
- Raw value:
4
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/HAL/ConsoleManager.cpp:3856
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarMaxAnistropy(
TEXT("r.MaxAnisotropy"),
4,
TEXT("MaxAnisotropy should range from 1 to 16. Higher values mean better texure quality when using anisotropic filtering but at a cost to performance. Default is 4."),
ECVF_Scalability | ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarShadowMaxResolution(
TEXT("r.Shadow.MaxResolution"),
#Loc: <Workspace>/Engine/Plugins/Media/ImgMedia/Source/ImgMedia/Private/Assets/ImgMediaMipMapInfo.cpp:350
Scope (from outer to inner):
file
namespace anonymous
function bool CalculateMipLevelAniso
Source code excerpt:
bool CalculateMipLevelAniso(const FImgMediaViewInfo& ViewInfo, const FVector& TexelWS, const FVector& TexelOffXWS, const FVector& TexelOffYWS, float& OutMipLevel)
{
static const float MaxAnisoLog2 = FMath::Log2((float)FMath::Clamp(IConsoleManager::Get().FindConsoleVariable(TEXT("r.MaxAnisotropy"))->GetInt(), 1, 16));
FVector2D TexelScreenSpace[3];
bool bValid = true;
bValid &= ProjectWorldToScreenFast(TexelWS, ViewInfo.ViewportRect, ViewInfo.ViewProjectionMatrix, TexelScreenSpace[0]);
bValid &= ProjectWorldToScreenFast(TexelOffXWS, ViewInfo.ViewportRect, ViewInfo.ViewProjectionMatrix, TexelScreenSpace[1]);
bValid &= ProjectWorldToScreenFast(TexelOffYWS, ViewInfo.ViewportRect, ViewInfo.ViewProjectionMatrix, TexelScreenSpace[2]);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/TextureLODSettings.h:138
Scope: file
Source code excerpt:
bool CookPlatformTilingDisabled;
/** Allows us to override max anisotropy. If unspecified, uses r.MaxAnisotropy */
UPROPERTY()
int32 MaxAniso;
ENGINE_API void SetupGroup();
ENGINE_API bool operator==(const FTextureLODGroup& Other) const;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:753
Scope (from outer to inner):
file
function void ScalabilityCVarsSinkCallback
Source code excerpt:
{
static const auto* MaxAnisotropy = ConsoleMan.FindTConsoleVariableDataInt(TEXT("r.MaxAnisotropy"));
LocalScalabilityCVars.MaxAnisotropy = MaxAnisotropy->GetValueOnGameThread();
}
{
static const auto* MaxShadowResolution = ConsoleMan.FindTConsoleVariableDataInt(TEXT("r.Shadow.MaxResolution"));
LocalScalabilityCVars.MaxShadowResolution = MaxShadowResolution->GetValueOnGameThread();
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:1063
Scope (from outer to inner):
file
function void RefreshSamplerStatesCallback
Source code excerpt:
{
static const auto CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MaxAnisotropy"));
int32 MaxAnisotropy = CVar->GetValueOnGameThread();
// compare against the default so with that number we avoid RefreshSamplerStates() calls on startup
// todo: This can be improved since we now have many defaults (see BaseScalability.ini)
static int32 LastMaxAnisotropy = 4;
if(LastMaxAnisotropy != MaxAnisotropy)
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/Rendering/StreamableTextureResource.h:115
Scope (from outer to inner):
file
class class FStreamableTextureResource : public FTextureResource
Source code excerpt:
bool bUsePartiallyResidentMips = false;
/** Max anisotropy. if 0, will use r.MaxAnisotropy */
int8 MaxAniso = 0;
#if STATS
private:
void CalcRequestedMipsSize();
void IncrementTextureStats() const;
#Loc: <Workspace>/Engine/Source/Runtime/RHI/Public/RHIUtilities.h:582
Scope (from outer to inner):
file
function inline uint32 ComputeAnisotropyRT
Source code excerpt:
inline uint32 ComputeAnisotropyRT(int32 InitializerMaxAnisotropy)
{
static const auto CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MaxAnisotropy"));
int32 CVarValue = CVar->GetValueOnAnyThread(); // this is sometimes called from main thread during initialization of static RHI states
return FMath::Clamp(InitializerMaxAnisotropy > 0 ? InitializerMaxAnisotropy : CVarValue, 1, 16);
}
#if UE_BUILD_SHIPPING || UE_BUILD_TEST