r.Mobile.FloatPrecisionMode
r.Mobile.FloatPrecisionMode
#Overview
name: r.Mobile.FloatPrecisionMode
The value of this variable can be defined or overridden in .ini config files. 1
.ini config file referencing this setting variable.
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
0: Use Half-precision (default)\n1: Half precision, except Full precision for material expressions\n2: Force use of high precision in pixel shaders.\n
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Mobile.FloatPrecisionMode is to control the floating-point precision mode in mobile rendering, specifically for shaders and material expressions.
This setting variable is primarily used in the rendering system of Unreal Engine, particularly for mobile platforms. It affects the Engine’s shader compilation process and material system. Based on the callsites, it’s used in the Core, Engine, and RenderCore modules.
The value of this variable is set through the console variable system, as seen in the ConsoleManager.cpp file. It’s defined as an integer with three possible values: 0: Use Half-precision (default) 1: Half precision, except Full precision for material expressions 2: Force use of high precision in pixel shaders
This variable interacts with other parts of the rendering system, particularly in material and shader compilation. It affects the precision of floating-point calculations in shaders and material expressions.
Developers must be aware that changing this variable can impact performance and visual quality on mobile devices. Higher precision generally means better visual quality but at the cost of performance. It’s also important to note that this variable is marked as ECVF_ReadOnly, meaning it should not be changed at runtime.
Best practices when using this variable include:
- Default to half-precision (0) for optimal performance on mobile devices.
- Use full precision for material expressions (1) when you notice visual artifacts in complex materials.
- Only use full precision in pixel shaders (2) when absolutely necessary, as it can significantly impact performance.
- Test thoroughly on target mobile devices to ensure a good balance between visual quality and performance.
- Set this variable early in the development process, as changing it later may require recompilation of shaders and materials.
#Setting Variables
#References In INI files
Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:131, section: [/Script/Engine.RendererSettings]
- INI Section:
/Script/Engine.RendererSettings
- Raw value:
2
- 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:3537
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarMobileFloatPrecisionMode(
TEXT("r.Mobile.FloatPrecisionMode"),
0,
TEXT("0: Use Half-precision (default)\n"
"1: Half precision, except Full precision for material expressions\n"
"2: Force use of high precision in pixel shaders.\n"),
ECVF_ReadOnly);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Materials/MaterialShared.cpp:3604
Scope (from outer to inner):
file
function void FMaterial::GetOutputPrecision
Source code excerpt:
void FMaterial::GetOutputPrecision(EMaterialFloatPrecisionMode FloatPrecisionMode, bool& FullPrecisionInPS, bool& FullPrecisionInMaterial)
{
static const IConsoleVariable* CVarFloatPrecisionMode = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.FloatPrecisionMode"));
if (FloatPrecisionMode != EMaterialFloatPrecisionMode::MFPM_Default)
{
FullPrecisionInMaterial = FloatPrecisionMode == EMaterialFloatPrecisionMode::MFPM_Full_MaterialExpressionOnly;
FullPrecisionInPS = FloatPrecisionMode == EMaterialFloatPrecisionMode::MFPM_Full;
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:8128
Scope (from outer to inner):
file
function void GlobalBeginCompileShader
Source code excerpt:
if (bUsingMobileRenderer)
{
static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.FloatPrecisionMode"));
Input.Environment.FullPrecisionInPS |= CVar ? (CVar->GetInt() == EMobileFloatPrecisionMode::Full) : false;
}
{
int32 FlowControl = CVarShaderFlowControl.GetValueOnAnyThread();
switch (FlowControl)
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/Shader.cpp:1685
Scope (from outer to inner):
file
function void ShaderMapAppendKeyString
Source code excerpt:
{
static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.FloatPrecisionMode"));
if(CVar && CVar->GetInt() > 0)
{
KeyString.Appendf(TEXT("_highp%d"), CVar->GetInt());
}
}