r.MSAACount
r.MSAACount
#Overview
name: r.MSAACount
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Number of MSAA samples to use with the forward renderer. Only used when MSAA is enabled in the rendering project settings.\n0: MSAA disabled (Temporal AA enabled)\n1: MSAA disabled\n2: Use 2x MSAA\n4: Use 4x MSAA8: Use 8x MSAA
It is referenced in 8
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.MSAACount is to control the number of Multisample Anti-Aliasing (MSAA) samples used in the rendering process, specifically with the forward renderer. This setting variable is primarily used for anti-aliasing in the rendering system of Unreal Engine 5.
The Unreal Engine subsystems that rely on this setting variable are primarily the Renderer module and the Engine module. This can be seen from the file locations where the variable is referenced, such as SceneTextures.cpp in the Renderer module and SceneUtils.cpp in the Engine module.
The value of this variable is set through a console variable (CVar) system. It is defined with a default value of 4 in the SceneTextures.cpp file.
This variable interacts closely with other anti-aliasing related variables, particularly r.AntiAliasingMethod. The interaction can be seen in the UpdateEarlyZPassModeCVarSinkFunction in RendererScene.cpp, where both r.MSAACount and r.AntiAliasingMethod are checked to determine if updates to the early Z-pass mode are necessary.
Developers must be aware that this variable is only effective when MSAA is enabled in the rendering project settings and when using forward rendering. It’s also important to note that setting this to 0 or 1 effectively disables MSAA, with 0 enabling Temporal AA instead.
Best practices when using this variable include:
- Only adjusting it when using forward rendering.
- Understanding the performance implications of higher MSAA sample counts.
- Coordinating its use with other anti-aliasing methods to avoid conflicts.
Regarding the associated variable CVarMSAACount:
CVarMSAACount is the actual console variable object that corresponds to r.MSAACount. It’s used to interact with the r.MSAACount setting programmatically within the engine code.
The purpose of CVarMSAACount is to provide a programmatic interface to read and potentially modify the r.MSAACount value at runtime.
This variable is primarily used in the Renderer module, as seen in the RendererScene.cpp file.
The value of CVarMSAACount is set when r.MSAACount is modified, as they represent the same setting.
CVarMSAACount interacts directly with r.MSAACount, essentially serving as its in-code representation.
Developers should be aware that changes to CVarMSAACount will affect r.MSAACount and vice versa.
Best practices for using CVarMSAACount include using it for reading the current MSAA count in C++ code, and potentially for dynamically adjusting MSAA settings in response to performance metrics or other runtime conditions.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneTextures.cpp:43
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarMSAACount(
TEXT("r.MSAACount"),
4,
TEXT("Number of MSAA samples to use with the forward renderer. Only used when MSAA is enabled in the rendering project settings.\n")
TEXT("0: MSAA disabled (Temporal AA enabled)\n")
TEXT("1: MSAA disabled\n")
TEXT("2: Use 2x MSAA\n")
TEXT("4: Use 4x MSAA")
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/RendererSettings.h:193
Scope (from outer to inner):
file
namespace EMobileAntiAliasingMethod
Source code excerpt:
FXAA = AAM_FXAA UMETA(DisplayName = "Fast Approximate Anti-Aliasing (FXAA)"),
TemporalAA = AAM_TemporalAA UMETA(DisplayName = "Temporal Anti-Aliasing (TAA)"),
/** Only supported with forward shading. MSAA sample count is controlled by r.MSAACount. */
MSAA = AAM_MSAA UMETA(DisplayName = "Multisample Anti-Aliasing (MSAA)"),
};
}
/** The default float precision for material's pixel shaders on mobile devices*/
UENUM()
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SceneUtils.cpp:96
Scope (from outer to inner):
file
function EAntiAliasingMethod GetDefaultAntiAliasingMethod
Source code excerpt:
}
static auto* MSAACountCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MSAACount"));
EShaderPlatform ShaderPlatform = GetFeatureLevelShaderPlatform(InFeatureLevel);
if (AntiAliasingMethod == EAntiAliasingMethod::AAM_None)
{
// NOP
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SceneUtils.cpp:179
Scope (from outer to inner):
file
function uint32 GetDefaultMSAACount
Source code excerpt:
if (AntiAliasingMethod == EAntiAliasingMethod::AAM_MSAA)
{
static auto* MSAACountCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MSAACount"));
EShaderPlatform ShaderPlatform = GetFeatureLevelShaderPlatform(InFeatureLevel);
if (IsForwardShadingEnabled(ShaderPlatform) || (IsMobilePlatform(ShaderPlatform) && !IsMobileDeferredShadingEnabled(ShaderPlatform)))
{
NumSamples = FMath::Max(1, MSAACountCVar->GetValueOnAnyThread());
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/SceneUtils.h:50
Scope: file
Source code excerpt:
AAM_FXAA UMETA(DisplayName = "Fast Approximate Anti-Aliasing (FXAA)"),
AAM_TemporalAA UMETA(DisplayName = "Temporal Anti-Aliasing (TAA)"),
/** Only supported with forward shading. MSAA sample count is controlled by r.MSAACount. */
AAM_MSAA UMETA(DisplayName = "Multisample Anti-Aliasing (MSAA)"),
AAM_TSR UMETA(DisplayName = "Temporal Super-Resolution (TSR)"),
AAM_MAX,
};
/** Returns whether the anti-aliasing method use a temporal accumulation */
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RendererScene.cpp:1370
Scope (from outer to inner):
file
function static void UpdateEarlyZPassModeCVarSinkFunction
Source code excerpt:
{
static auto* CVarAntiAliasingMethod = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.AntiAliasingMethod"));
static auto* CVarMSAACount = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MSAACount"));
static int32 CachedAntiAliasingMethod = CVarAntiAliasingMethod->GetValueOnGameThread();
static int32 CachedMSAACount = CVarMSAACount->GetValueOnGameThread();
static int32 CachedEarlyZPass = CVarEarlyZPass.GetValueOnGameThread();
static int32 CachedBasePassWriteDepthEvenWithFullPrepass = CVarBasePassWriteDepthEvenWithFullPrepass.GetValueOnGameThread();
const int32 AntiAliasingMethod = CVarAntiAliasingMethod->GetValueOnGameThread();
#Associated Variable and Callsites
This variable is associated with another variable named CVarMSAACount
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RendererScene.cpp:1370
Scope (from outer to inner):
file
function static void UpdateEarlyZPassModeCVarSinkFunction
Source code excerpt:
{
static auto* CVarAntiAliasingMethod = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.AntiAliasingMethod"));
static auto* CVarMSAACount = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MSAACount"));
static int32 CachedAntiAliasingMethod = CVarAntiAliasingMethod->GetValueOnGameThread();
static int32 CachedMSAACount = CVarMSAACount->GetValueOnGameThread();
static int32 CachedEarlyZPass = CVarEarlyZPass.GetValueOnGameThread();
static int32 CachedBasePassWriteDepthEvenWithFullPrepass = CVarBasePassWriteDepthEvenWithFullPrepass.GetValueOnGameThread();
const int32 AntiAliasingMethod = CVarAntiAliasingMethod->GetValueOnGameThread();
const int32 MSAACount = CVarMSAACount->GetValueOnGameThread();
const int32 EarlyZPass = CVarEarlyZPass.GetValueOnGameThread();
const int32 BasePassWriteDepthEvenWithFullPrepass = CVarBasePassWriteDepthEvenWithFullPrepass.GetValueOnGameThread();
// Switching between MSAA and another AA in forward shading mode requires EarlyZPassMode to update.
if (AntiAliasingMethod != CachedAntiAliasingMethod
|| MSAACount != CachedMSAACount
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneTextures.cpp:42
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<int32> CVarMSAACount(
TEXT("r.MSAACount"),
4,
TEXT("Number of MSAA samples to use with the forward renderer. Only used when MSAA is enabled in the rendering project settings.\n")
TEXT("0: MSAA disabled (Temporal AA enabled)\n")
TEXT("1: MSAA disabled\n")
TEXT("2: Use 2x MSAA\n")