r.MobileHDR

r.MobileHDR

#Overview

name: r.MobileHDR

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

It is referenced in 11 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.MobileHDR is to control the rendering color space for mobile platforms in Unreal Engine 5. Specifically:

This setting variable is primarily used by the mobile rendering system in Unreal Engine 5. Based on the callsites, it affects various subsystems and modules, including:

  1. The core rendering system (RenderCore module)
  2. The Android-specific window handling (ApplicationCore module)
  3. The general engine settings (Engine module)
  4. The editor’s cooking process (UnrealEd module)

The value of this variable is set in several places:

  1. It’s initially defined as a console variable in ConsoleManager.cpp with a default value of 1.
  2. It can be configured in the project settings under the Renderer Settings category.
  3. It can be set in the platform-specific engine configuration files.

The associated variable CVarMobileHDR interacts directly with r.MobileHDR, as they share the same value. This variable is used to cache the value of r.MobileHDR for quick access in performance-critical code paths.

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

  1. Changing this setting requires restarting the editor.
  2. It affects mobile shader compilation, as indicated by the ECVF_MobileShaderChange flag.
  3. It impacts the availability of post-processing features on mobile platforms.
  4. It can affect performance and visual quality, especially on low-end mobile devices.

Best practices for using this variable include:

  1. Consider setting it to 0 for unlit games targeting low-end mobile devices to improve performance.
  2. Keep it at the default value of 1 for most mobile games to maintain visual quality and consistency with other platforms.
  3. Test thoroughly on target devices when changing this setting, as it can significantly impact both performance and visual appearance.
  4. Be aware of its interaction with other mobile rendering settings, such as post-processing and multi-view rendering.

Regarding the associated variable CVarMobileHDR:

The purpose of CVarMobileHDR is to provide a fast, read-only access to the r.MobileHDR setting within the engine’s code. It’s used to cache the value of r.MobileHDR for efficient querying in performance-critical sections of the rendering code.

This variable is primarily used in the RenderCore module, specifically in the FReadOnlyCVARCache class. It’s initialized when the FReadOnlyCVARCache is set up and is used to quickly determine whether mobile HDR is enabled without having to query the console variable system each time.

The value of CVarMobileHDR is set based on the r.MobileHDR console variable, and it’s typically not modified directly. Instead, changes to r.MobileHDR will be reflected in CVarMobileHDR when the cache is updated.

Developers should be aware that CVarMobileHDR is a cached value, and in some rare cases, it might not immediately reflect changes to r.MobileHDR if the cache hasn’t been updated. However, for most use cases, it will provide the correct, up-to-date value.

Best practices for using CVarMobileHDR include:

  1. Use it for performance-critical code paths where querying the full console variable might be too slow.
  2. Remember that it’s a read-only cache, so don’t attempt to modify it directly.
  3. If you need to ensure you have the most up-to-date value in a non-performance-critical section, consider using the original r.MobileHDR console variable instead.

#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:3466

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMobileHDR(
	TEXT("r.MobileHDR"),
	1,
	TEXT("0: Mobile renders in LDR gamma space. (suggested for unlit games targeting low-end phones)\n"
		 "1: Mobile renders in HDR linear space. (default)"),
	ECVF_RenderThreadSafe | ECVF_ReadOnly | ECVF_MobileShaderChange);

static TAutoConsoleVariable<int32> CVarMobileShadingPath(

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/RendererSettings.h:969

Scope (from outer to inner):

file
class        class URendererSettings : public UDeveloperSettings

Source code excerpt:

	UPROPERTY(config, EditAnywhere, Category = VR, meta=(
		EditCondition = "MobileShadingPath == 0",
		ConsoleVariable="r.MobileHDR", DisplayName="Mobile HDR",
		ToolTip="If true, mobile pipelines include a full post-processing pass with tonemapping. Disable this setting for a performance boost and to enable stereoscopic rendering optimizations. Changing this setting requires restarting the editor.",
		ConfigRestartRequired = true))
	uint32 bMobilePostProcessing:1;

	UPROPERTY(config, EditAnywhere, Category = VR, meta = (
		ConsoleVariable = "vr.MobileMultiView", DisplayName = "Mobile Multi-View",

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/UnrealEdEngine.cpp:322

Scope (from outer to inner):

file
function     bool CanCookForPlatformInThisProcess

Source code excerpt:

	FString IniValueString;
	bool ConfigSetting = false;
	if ( PlatformEngineIni.GetString( TEXT("/Script/Engine.RendererSettings"), TEXT("r.MobileHDR"), IniValueString ) == false )
	{
		// must always match the RSetting setting because we don't have a config setting
		return true; 
	}
	ConfigSetting = IniValueString.ToBool();

#Loc: <Workspace>/Engine/Source/Runtime/ApplicationCore/Private/Android/AndroidWindow.cpp:600

Scope (from outer to inner):

file
function     FPlatformRect FAndroidWindow::GetScreenRect

Source code excerpt:

		CalculateSurfaceSize(ScreenWidth, ScreenHeight, bUseEventThreadWindow);

		static auto* MobileHDRCvar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MobileHDR"));
		const bool bMobileHDR = (MobileHDRCvar && MobileHDRCvar->GetValueOnAnyThread() == 1);
		UE_LOG(LogAndroid, Log, TEXT("Mobile HDR: %s"), bMobileHDR ? TEXT("YES") : TEXT("no"));

		if (!bIsOculusMobileApp)
		{
			if (CurrentParams.WindowDPI && RequestedResX == 0 && RequestedResY == 0)

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ReadOnlyCVARCache.cpp:70

Scope (from outer to inner):

file
function     void FReadOnlyCVARCache::Initialize

Source code excerpt:

	const auto CVarSupportSkyAtmosphere = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.SupportSkyAtmosphere"));
	
	const auto CVarMobileHDR = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MobileHDR"));
	const auto CVarMobileAllowMovableDirectionalLights = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.AllowMovableDirectionalLights"));
	const auto CVarMobileEnableStaticAndCSMShadowReceivers = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.EnableStaticAndCSMShadowReceivers"));
	const auto CVarMobileEnableMovableLightCSMShaderCulling = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.EnableMovableLightCSMShaderCulling"));
	const auto CVarMobileAllowDistanceFieldShadows = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.AllowDistanceFieldShadows"));
	const auto CVarMobileSkyLightPermutation = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.SkyLightPermutation"));
	const auto CVarMobileEnableNoPrecomputedLightingCSMShader = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.EnableNoPrecomputedLightingCSMShader"));

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/HAL/ConsoleManager.cpp:3465

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarMobileHDR(
	TEXT("r.MobileHDR"),
	1,
	TEXT("0: Mobile renders in LDR gamma space. (suggested for unlit games targeting low-end phones)\n"
		 "1: Mobile renders in HDR linear space. (default)"),
	ECVF_RenderThreadSafe | ECVF_ReadOnly | ECVF_MobileShaderChange);

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ReadOnlyCVARCache.cpp:70

Scope (from outer to inner):

file
function     void FReadOnlyCVARCache::Initialize

Source code excerpt:

	const auto CVarSupportSkyAtmosphere = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.SupportSkyAtmosphere"));
	
	const auto CVarMobileHDR = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MobileHDR"));
	const auto CVarMobileAllowMovableDirectionalLights = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.AllowMovableDirectionalLights"));
	const auto CVarMobileEnableStaticAndCSMShadowReceivers = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.EnableStaticAndCSMShadowReceivers"));
	const auto CVarMobileEnableMovableLightCSMShaderCulling = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.EnableMovableLightCSMShaderCulling"));
	const auto CVarMobileAllowDistanceFieldShadows = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.AllowDistanceFieldShadows"));
	const auto CVarMobileSkyLightPermutation = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.SkyLightPermutation"));
	const auto CVarMobileEnableNoPrecomputedLightingCSMShader = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.EnableNoPrecomputedLightingCSMShader"));

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ReadOnlyCVARCache.cpp:88

Scope (from outer to inner):

file
function     void FReadOnlyCVARCache::Initialize

Source code excerpt:


	// mobile
	bMobileHDR = CVarMobileHDR->GetValueOnAnyThread() == 1;
	bMobileAllowMovableDirectionalLights = CVarMobileAllowMovableDirectionalLights->GetValueOnAnyThread() != 0;
	bMobileAllowDistanceFieldShadows = CVarMobileAllowDistanceFieldShadows->GetValueOnAnyThread() != 0;
	bMobileEnableStaticAndCSMShadowReceivers = CVarMobileEnableStaticAndCSMShadowReceivers->GetValueOnAnyThread() != 0;
	bMobileEnableMovableLightCSMShaderCulling = CVarMobileEnableMovableLightCSMShaderCulling->GetValueOnAnyThread() != 0;
	MobileSkyLightPermutationValue = CVarMobileSkyLightPermutation->GetValueOnAnyThread();
	bMobileEnableNoPrecomputedLightingCSMShader = CVarMobileEnableNoPrecomputedLightingCSMShader->GetValueOnAnyThread() != 0;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/RendererSettings.h:972

Scope (from outer to inner):

file
class        class URendererSettings : public UDeveloperSettings

Source code excerpt:

		ToolTip="If true, mobile pipelines include a full post-processing pass with tonemapping. Disable this setting for a performance boost and to enable stereoscopic rendering optimizations. Changing this setting requires restarting the editor.",
		ConfigRestartRequired = true))
	uint32 bMobilePostProcessing:1;

	UPROPERTY(config, EditAnywhere, Category = VR, meta = (
		ConsoleVariable = "vr.MobileMultiView", DisplayName = "Mobile Multi-View",
		ToolTip = "Enable single-pass stereoscopic rendering on mobile platforms.",
		ConfigRestartRequired = true))
		uint32 bMobileMultiView : 1;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/RendererSettings.cpp:270

Scope (from outer to inner):

file
function     void URendererSettings::PostEditChangeProperty

Source code excerpt:

			if(MobileShadingPath.GetValue() == 1)
			{
				bMobilePostProcessing = 1;
				UpdateDependentPropertyInConfigFile(this, GET_MEMBER_NAME_CHECKED(URendererSettings, bMobilePostProcessing));
			}
		}

		if ((PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(URendererSettings, bEnableSubstrate)))
		{
			if (bEnableSubstrate)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/RendererSettings.cpp:376

Scope (from outer to inner):

file
function     bool URendererSettings::CanEditChange

Source code excerpt:

	}

	if ((InProperty->GetFName() == GET_MEMBER_NAME_CHECKED(URendererSettings, bMobilePostProcessing)))
	{
		return MobileShadingPath.GetValue() == 0;
	}

	PRAGMA_DISABLE_DEPRECATION_WARNINGS
	// only allow changing ExtendDefaultLuminanceRange if it was disabled.