r.Mobile.AmbientOcclusion

r.Mobile.AmbientOcclusion

#Overview

name: r.Mobile.AmbientOcclusion

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).

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Mobile.AmbientOcclusion is to control the enabling or disabling of Ambient Occlusion on mobile platforms in Unreal Engine 5. This setting variable is primarily used for the rendering system, specifically for mobile devices.

The Unreal Engine subsystems that rely on this setting variable are primarily the Renderer and RenderCore modules. It’s also used in the TargetPlatform module for platform-specific settings.

The value of this variable is set through the console variable system. It’s defined as a TAutoConsoleVariable with a default value of 0 (disabled). Users can change this value at runtime or through configuration files.

This variable interacts with other rendering-related variables, particularly those related to mobile rendering. For example, it’s used in conjunction with r.Mobile.GTAOPreIntegratedTextureType when appending shader map keys.

Developers must be aware that enabling this feature (by setting the value to 1) will occupy an extra sampler in the mobile base pass pixel shader. This could have performance implications on mobile devices with limited resources.

Best practices when using this variable include:

  1. Only enable it when necessary, as it can impact performance on mobile devices.
  2. Test thoroughly on target mobile devices to ensure acceptable performance when enabled.
  3. Consider the trade-off between visual quality improvement and performance cost.
  4. Be aware that changing this setting may require shader recompilation, which can affect load times and memory usage.
  5. Use in conjunction with other mobile rendering settings for optimal results.

It’s important to note that this is a read-only and render thread safe console variable, meaning it should typically be set at startup or through configuration files rather than changed frequently during runtime.

#Setting Variables

#References In INI files

Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:134, section: [/Script/Engine.RendererSettings]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessAmbientOcclusionMobile.cpp:21

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMobileAmbientOcclusion(
	TEXT("r.Mobile.AmbientOcclusion"),
	0,
	TEXT("Caution: An extra sampler will be occupied in mobile base pass pixel shader after enable the mobile ambient occlusion.\n")
	TEXT("0: Disable Ambient Occlusion on mobile platform. [default]\n")
	TEXT("1: Enable Ambient Occlusion on mobile platform.\n"),
	ECVF_ReadOnly | ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Private/TargetPlatformBase.cpp:90

Scope (from outer to inner):

file
function     bool FTargetPlatformBase::UsesMobileAmbientOcclusion

Source code excerpt:

bool FTargetPlatformBase::UsesMobileAmbientOcclusion() const
{
	static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.AmbientOcclusion"));
	return CVar ? (CVar->GetInt() != 0) : false;
}

bool FTargetPlatformBase::UsesMobileDBuffer() const
{
	static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.DBuffer"));

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Private/TargetPlatformSettingsBase.cpp:79

Scope (from outer to inner):

file
function     bool FTargetPlatformSettingsBase::UsesMobileAmbientOcclusion

Source code excerpt:

bool FTargetPlatformSettingsBase::UsesMobileAmbientOcclusion() const
{
	static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.AmbientOcclusion"));
	return CVar ? (CVar->GetInt() != 0) : false;
}

bool FTargetPlatformSettingsBase::UsesMobileDBuffer() const
{
	static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.DBuffer"));

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:761

Scope (from outer to inner):

file
function     void RenderUtilsInit

Source code excerpt:

	GRayTracingPlatformMask.Init(false, EShaderPlatform::SP_NumPlatforms);

	static IConsoleVariable* MobileAmbientOcclusionCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.AmbientOcclusion"));
	GMobileAmbientOcclusionPlatformMask.Init(MobileAmbientOcclusionCVar && MobileAmbientOcclusionCVar->GetInt(), EShaderPlatform::SP_NumPlatforms);

#if WITH_EDITOR
	ITargetPlatformManagerModule* TargetPlatformManager = GetTargetPlatformManager();
	if (TargetPlatformManager)
	{

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

Scope (from outer to inner):

file
function     void ShaderMapAppendKeyString

Source code excerpt:

		{
			static IConsoleVariable* MobileGTAOPreIntegratedTextureTypeCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.GTAOPreIntegratedTextureType"));
			static IConsoleVariable* MobileAmbientOcclusionCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.AmbientOcclusion"));
			int32 GTAOPreIntegratedTextureType = MobileGTAOPreIntegratedTextureTypeCVar ? MobileGTAOPreIntegratedTextureTypeCVar->GetInt() : 0;
			KeyString += ((MobileAmbientOcclusionCVar && MobileAmbientOcclusionCVar->GetInt() != 0) && IsMobileHDR()) ? FString::Printf(TEXT("_MobileAO_%d"), GTAOPreIntegratedTextureType) : TEXT("");
		}

		{
			KeyString += IsMobileDistanceFieldEnabled(Platform) ? TEXT("_MobSDF") : TEXT("");

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SystemTextures.cpp:763

Scope (from outer to inner):

file
function     void FSystemTextures::InitializeFeatureLevelDependentTextures

Source code excerpt:


	// Create the SSAO randomization texture
	static const auto MobileAmbientOcclusionCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.AmbientOcclusion"));
	if ((CurrentFeatureLevel < ERHIFeatureLevel::SM5 && InFeatureLevel >= ERHIFeatureLevel::SM5) ||
		(CurrentFeatureLevel < ERHIFeatureLevel::ES3_1 && MobileAmbientOcclusionCVar != nullptr && MobileAmbientOcclusionCVar->GetValueOnAnyThread()>0))
	{
		{
			float g_AngleOff1 = 127;
			float g_AngleOff2 = 198;