r.VT.AnisotropicFiltering

r.VT.AnisotropicFiltering

#Overview

name: r.VT.AnisotropicFiltering

This variable is created as a Console Variable (cvar).

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.VT.AnisotropicFiltering is to control whether anisotropic filtering is enabled for Virtual Textures (VTs) in Unreal Engine 5. This setting variable is primarily used for the rendering system, specifically for improving the visual quality of Virtual Textures.

This setting variable is relied upon by the Virtual Texture system, which is part of Unreal Engine’s rendering module. It is referenced in various subsystems, including shader compilation, material uniform expressions, and Virtual Texture scalability settings.

The value of this variable is set through the console variable system in Unreal Engine. It is defined as a TAutoConsoleVariable with a default value of 0 (disabled).

There are several other variables that interact with r.VT.AnisotropicFiltering:

  1. r.VT.MaxAnisotropy: This variable sets the maximum level of anisotropy when anisotropic filtering is enabled.
  2. CVarVTEnableAnisotropy: This is an associated variable that shares the same value as r.VT.AnisotropicFiltering.

Developers must be aware of the following when using this variable:

  1. Enabling anisotropic filtering can improve texture quality, especially at oblique viewing angles, but may have performance implications.
  2. This setting affects shader compilation, so changing it may trigger shader recompilation.
  3. The effect of this variable is platform-dependent, and it may have different behaviors on mobile platforms.

Best practices when using this variable include:

  1. Consider the performance impact when enabling anisotropic filtering, especially on lower-end devices.
  2. Use in conjunction with r.VT.MaxAnisotropy to fine-tune the level of anisotropic filtering.
  3. Test the visual quality and performance impact across different platforms and hardware configurations.

Regarding the associated variable CVarVTEnableAnisotropy:

The purpose of CVarVTEnableAnisotropy is the same as r.VT.AnisotropicFiltering, serving as an internal representation of the anisotropic filtering setting for Virtual Textures.

This variable is used within the VirtualTextureScalability namespace, indicating its importance in managing scalability settings for Virtual Textures.

The value of CVarVTEnableAnisotropy is set to the same value as r.VT.AnisotropicFiltering, ensuring consistency between the console variable and the internal representation.

CVarVTEnableAnisotropy interacts directly with the IsAnisotropicFilteringEnabled() function, which is likely used throughout the engine to check if anisotropic filtering for Virtual Textures is enabled.

Developers should be aware that changes to r.VT.AnisotropicFiltering will be reflected in CVarVTEnableAnisotropy, and vice versa.

Best practices for CVarVTEnableAnisotropy include using the IsAnisotropicFilteringEnabled() function to check the status of anisotropic filtering rather than accessing the variable directly, as this provides a cleaner and more maintainable code structure.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/VT/VirtualTextureScalability.cpp:111

Scope (from outer to inner):

file
namespace    VirtualTextureScalability

Source code excerpt:


	static TAutoConsoleVariable<int32> CVarVTEnableAnisotropy(
		TEXT("r.VT.AnisotropicFiltering"),
		0,
		TEXT("Is anisotropic filtering for VTs enabled?"),
		ECVF_RenderThreadSafe | ECVF_ReadOnly);

	static TAutoConsoleVariable<int32> CVarVTMaxAnisotropy(
		TEXT("r.VT.MaxAnisotropy"),

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Materials/MaterialUniformExpressions.cpp:1416

Scope (from outer to inner):

file
function     void FUniformExpressionSet::FillUniformBuffer

Source code excerpt:

				}
			}
			static const auto CVarVTAnisotropic = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.VT.AnisotropicFiltering"));
			const bool VTAnisotropic = CVarVTAnisotropic && CVarVTAnisotropic->GetValueOnAnyThread() != 0;
			static const auto CVarVTMaxAnisotropic = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.VT.MaxAnisotropy"));
			const int32 VTMaxAnisotropic = (VTAnisotropic && CVarVTMaxAnisotropic) ? CVarVTMaxAnisotropic->GetValueOnAnyThread(): 1;
			// Now check for runtime virtual texture
			if (!bValidResources)
			{

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:8653

Scope (from outer to inner):

file
function     void GlobalBeginCompileShader

Source code excerpt:


	{
		static const auto CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VT.AnisotropicFiltering"));
		SET_SHADER_DEFINE(Input.Environment, VIRTUAL_TEXTURE_ANISOTROPIC_FILTERING, CVar ? (CVar->GetInt() != 0) : 0);
		
		if (bIsMobilePlatform)
		{
			static FShaderPlatformCachedIniValue<bool> CVarVTMobileManualTrilinearFiltering(TEXT("r.VT.Mobile.ManualTrilinearFiltering"));
			SET_SHADER_DEFINE(Input.Environment, VIRTUAL_TEXTURE_MANUAL_TRILINEAR_FILTERING, (CVarVTMobileManualTrilinearFiltering.Get(Target.GetPlatform()) ? 1 : 0));

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/Shader.cpp:2185

Scope (from outer to inner):

file
function     void ShaderMapAppendKeyString

Source code excerpt:

		bool VTTextures = CVarVirtualTexture && CVarVirtualTexture->GetValueOnAnyThread() != 0;

		static const auto CVarVTAnisotropic = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.VT.AnisotropicFiltering"));
		int32 VTFiltering = CVarVTAnisotropic && CVarVTAnisotropic->GetValueOnAnyThread() != 0 ? 1 : 0;

		if (IsMobilePlatform(Platform) && VTTextures)
		{
			static FShaderPlatformCachedIniValue<bool> MobileVirtualTexturesIniValue(TEXT("r.Mobile.VirtualTextures"));
			VTTextures = (MobileVirtualTexturesIniValue.Get(Platform) != false);

#Associated Variable and Callsites

This variable is associated with another variable named CVarVTEnableAnisotropy. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/VT/VirtualTextureScalability.cpp:110

Scope (from outer to inner):

file
namespace    VirtualTextureScalability

Source code excerpt:

		ECVF_RenderThreadSafe | ECVF_ReadOnly);

	static TAutoConsoleVariable<int32> CVarVTEnableAnisotropy(
		TEXT("r.VT.AnisotropicFiltering"),
		0,
		TEXT("Is anisotropic filtering for VTs enabled?"),
		ECVF_RenderThreadSafe | ECVF_ReadOnly);

	static TAutoConsoleVariable<int32> CVarVTMaxAnisotropy(

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/VT/VirtualTextureScalability.cpp:217

Scope (from outer to inner):

file
namespace    VirtualTextureScalability
function     bool IsAnisotropicFilteringEnabled

Source code excerpt:

	bool IsAnisotropicFilteringEnabled()
	{
		return CVarVTEnableAnisotropy.GetValueOnAnyThread() != 0;
	}

	int32 GetMaxAnisotropy()
	{
		return CVarVTMaxAnisotropy.GetValueOnAnyThread();
	}