ShowFlag.DistanceFieldAO

ShowFlag.DistanceFieldAO

#Overview

name: ShowFlag.DistanceFieldAO

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

It is referenced in 15 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of ShowFlag.DistanceFieldAO is to control the visibility of Distance Field Ambient Occlusion (DFAO) in the Unreal Engine rendering system. DFAO is an advanced lighting technique that uses distance fields to calculate ambient occlusion, providing more accurate and efficient soft shadowing for large-scale objects.

This setting variable is primarily used by the rendering system, specifically the lighting and global illumination components. Based on the callsites, it’s clear that the following Unreal Engine subsystems and modules rely on this variable:

  1. The core rendering engine
  2. The SceneCapture system
  3. The Functional Testing module
  4. Various platform-specific modules (iOS, Android)

The value of this variable is typically set through the engine’s show flags system, which allows developers and users to toggle various rendering features on and off. It can be set programmatically or through the editor interface.

Several other variables interact with ShowFlag.DistanceFieldAO:

  1. DistanceFieldAO: This is an associated variable that shares the same value and is used in platform-specific settings and feature support checks.
  2. Other show flags like ScreenSpaceAO, LumenGlobalIllumination, and VolumetricFog are often toggled alongside DistanceFieldAO.

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

  1. DFAO can have a significant performance impact, especially on lower-end hardware.
  2. It interacts with other lighting features like global illumination and sky lighting.
  3. Its availability depends on the target platform’s capabilities.

Best practices when using this variable include:

  1. Only enable it when necessary, as it can be computationally expensive.
  2. Consider the target platform’s capabilities when deciding whether to use DFAO.
  3. Test performance with and without DFAO enabled to ensure it doesn’t negatively impact frame rates.
  4. Use it in conjunction with other lighting techniques for the best visual results.

Regarding the associated variable DistanceFieldAO:

The purpose of DistanceFieldAO is to indicate whether a particular platform or feature set supports Distance Field Ambient Occlusion. It’s used in platform-specific code and feature support checks.

This variable is primarily used in target platform settings and capability checks. It’s referenced in iOS, Android, and general target platform code.

The value of this variable is typically set based on the capabilities of the target platform, often determined by the platform’s properties or settings.

Developers should be aware that this variable determines whether DFAO will be available on a particular platform, which can affect both rendering quality and performance.

Best practices include:

  1. Checking this variable before attempting to use DFAO features in platform-specific code.
  2. Providing fallback rendering options for platforms that don’t support DFAO.
  3. Considering this variable when optimizing content for different platforms.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/ShowFlagsValues.inl:345

Scope: file

Source code excerpt:

SHOWFLAG_ALWAYS_ACCESSIBLE(ScreenSpaceAO, SFG_LightingFeatures, NSLOCTEXT("UnrealEd", "ScreenSpaceAOSF", "Screen Space Ambient Occlusion"))
/** Distance field AO, for now SHOWFLAG_ALWAYS_ACCESSIBLE because it's exposed in SceneCapture */
SHOWFLAG_ALWAYS_ACCESSIBLE(DistanceFieldAO, SFG_LightingFeatures, NSLOCTEXT("UnrealEd", "DistanceFieldAOSF", "Distance Field Ambient Occlusion"))
/** Lumen GI */
SHOWFLAG_ALWAYS_ACCESSIBLE(LumenGlobalIllumination, SFG_LightingFeatures, NSLOCTEXT("UnrealEd", "LumenGlobalIlluminationSF", "Lumen Global Illumination"))
/** SHOWFLAG_ALWAYS_ACCESSIBLE because it's exposed in SceneCapture */
SHOWFLAG_ALWAYS_ACCESSIBLE(VolumetricFog, SFG_LightingFeatures, NSLOCTEXT("UnrealEd", "VolumetricFogSF", "Volumetric Fog"))
/** Visualize screen space reflections, for developer (by default off): */
SHOWFLAG_FIXED_IN_SHIPPING(0, VisualizeSSR, SFG_Visualize, NSLOCTEXT("UnrealEd", "VisualizeSSR", "Screen Space Reflections"))

#Loc: <Workspace>/Engine/Plugins/Experimental/CinematicPrestreaming/Source/CinematicPrestreamingEditor/Private/CinePrestreamingRecorderSetting.cpp:35

Scope (from outer to inner):

file
function     UCinePrestreamingRecorderSetting::UCinePrestreamingRecorderSetting

Source code excerpt:

	ShowFlagsToDisable.Add("ShowFlag.LumenReflections");
	ShowFlagsToDisable.Add("ShowFlag.AmbientOcclusion");
	ShowFlagsToDisable.Add("ShowFlag.DistanceFieldAO");
}

void UCinePrestreamingRecorderSetting::SetupForPipelineImpl(UMoviePipeline* InPipeline)
{
	// Subscribe to BeginFrame to capture the start of rendering on game thread. We may actually render multiple times to produce a single output Frame.
	BeginFrameDelegate = FCoreDelegates::OnBeginFrame.AddLambda([this]() { OnBeginFrame_GameThread(); });

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Developer/Android/AndroidTargetPlatformSettings/Private/AndroidTargetPlatformSettings.cpp:74

Scope (from outer to inner):

file
function     bool FAndroidTargetPlatformSettings::SupportsFeature

Source code excerpt:

		return bMobileVirtualTextures;

	case ETargetPlatformFeatures::DistanceFieldAO:
		return UsesDistanceFields();


	case ETargetPlatformFeatures::NormalmapLAEncodingMode:
	{
		static IConsoleVariable* CompressorCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("cook.ASTCTextureCompressor"));

#Loc: <Workspace>/Engine/Source/Developer/DeviceManager/Private/Widgets/Details/SDeviceDetails.cpp:148

Scope (from outer to inner):

file
function     BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION void SDeviceDetails::Construct
lambda-function

Source code excerpt:

				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("AudioStreaming"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::AudioStreaming))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("DistanceFieldShadows"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::DistanceFieldShadows))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("DistanceFieldAO"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::DistanceFieldAO))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("GrayscaleSRGB"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::GrayscaleSRGB))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("HighQualityLightmaps"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::HighQualityLightmaps))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("LowQualityLightmaps"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::LowQualityLightmaps))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("MultipleGameInstances"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::MultipleGameInstances))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("Packaging"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::Packaging))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("SdkConnectDisconnect"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::SdkConnectDisconnect))));

#Loc: <Workspace>/Engine/Source/Developer/FunctionalTesting/Private/AutomationBlueprintFunctionLibrary.cpp:189

Scope (from outer to inner):

file
class        class FAutomationViewExtension : public FWorldSceneViewExtension
function     virtual void SetupViewFamily

Source code excerpt:

			ShowFlags.SetScreenSpaceReflections(ViewSettings->ScreenSpaceReflections);
			ShowFlags.SetScreenSpaceAO(ViewSettings->ScreenSpaceAO);
			ShowFlags.SetDistanceFieldAO(ViewSettings->DistanceFieldAO);
			ShowFlags.SetContactShadows(ViewSettings->ContactShadows);
			ShowFlags.SetEyeAdaptation(ViewSettings->EyeAdaptation);
			ShowFlags.SetBloom(ViewSettings->Bloom);
		}

		if (Options.bOverride_OverrideTimeTo)

#Loc: <Workspace>/Engine/Source/Developer/FunctionalTesting/Public/AutomationViewSettings.h:20

Scope (from outer to inner):

file
class        class UAutomationViewSettings : public UDataAsset
function     UAutomationViewSettings

Source code excerpt:

		, ScreenSpaceReflections(true)
		, ScreenSpaceAO(true)
		, DistanceFieldAO(true)
		, ContactShadows(true)
		, EyeAdaptation(true)
		, Bloom(true)
	{
	}

#Loc: <Workspace>/Engine/Source/Developer/FunctionalTesting/Public/AutomationViewSettings.h:43

Scope (from outer to inner):

file
class        class UAutomationViewSettings : public UDataAsset

Source code excerpt:

	
	UPROPERTY(EditAnywhere, Category="Rendering")
	bool DistanceFieldAO;
	
	UPROPERTY(EditAnywhere, Category="Rendering")
	bool ContactShadows;
	
	UPROPERTY(EditAnywhere, Category="Rendering")
	bool EyeAdaptation;

#Loc: <Workspace>/Engine/Source/Developer/IOS/IOSTargetPlatform/Private/IOSTargetPlatform.cpp:494

Scope (from outer to inner):

file
function     bool FIOSTargetPlatform::SupportsFeature

Source code excerpt:

			return bMobileVirtualTextures;

		case ETargetPlatformFeatures::DistanceFieldAO:
			return UsesDistanceFields();

		case ETargetPlatformFeatures::NormalmapLAEncodingMode:
		{
			static IConsoleVariable* CompressorCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("cook.ASTCTextureCompressor"));
			const bool bUsesARMCompressor = (CompressorCVar ? (CompressorCVar->GetInt() != 0) : false);

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Public/Common/TargetPlatformBase.h:456

Scope (from outer to inner):

file
class        class TTargetPlatformBase : public FTargetPlatformBase
function     virtual bool SupportsFeature

Source code excerpt:

			return TPlatformProperties::SupportsDistanceFieldShadows();

		case ETargetPlatformFeatures::DistanceFieldAO:
			return TPlatformProperties::SupportsDistanceFieldAO();

		case ETargetPlatformFeatures::GrayscaleSRGB:
			return TPlatformProperties::SupportsGrayscaleSRGB();

		case ETargetPlatformFeatures::HighQualityLightmaps:

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Public/Common/TargetPlatformSettingsBase.h:88

Scope (from outer to inner):

file
class        class TTargetPlatformSettingsBase : public FTargetPlatformSettingsBase
function     virtual bool SupportsFeature

Source code excerpt:

			return TPlatformProperties::SupportsDistanceFieldShadows();

		case ETargetPlatformFeatures::DistanceFieldAO:
			return TPlatformProperties::SupportsDistanceFieldAO();

		case ETargetPlatformFeatures::GrayscaleSRGB:
			return TPlatformProperties::SupportsGrayscaleSRGB();

		case ETargetPlatformFeatures::HighQualityLightmaps:

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Public/Interfaces/ITargetPlatformSettings.h:22

Scope: file

Source code excerpt:


	/** Distance field AO. */
	DistanceFieldAO,

	/** Gray scale SRGB texture formats support. */
	GrayscaleSRGB,

	/** High quality light maps. */
	HighQualityLightmaps,

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:1765

Scope (from outer to inner):

file
function     void FStaticMeshRenderData::Serialize

Source code excerpt:

#if WITH_EDITOR
		const bool bWantToStripDistanceFieldData = Ar.IsCooking() 
			&& (!Ar.CookingTarget()->SupportsFeature(ETargetPlatformFeatures::DistanceFieldAO) || !Ar.CookingTarget()->UsesDistanceFields());

		ClassDataStripFlags |= (bWantToStripDistanceFieldData ? DistanceFieldDataStripFlag : 0);
#endif

		FStripDataFlags StripFlags(Ar, ClassDataStripFlags);
		if (!StripFlags.IsAudioVisualDataStripped() && !StripFlags.IsClassDataStripped(DistanceFieldDataStripFlag))

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/ShowFlagsValues.inl:345

Scope: file

Source code excerpt:

SHOWFLAG_ALWAYS_ACCESSIBLE(ScreenSpaceAO, SFG_LightingFeatures, NSLOCTEXT("UnrealEd", "ScreenSpaceAOSF", "Screen Space Ambient Occlusion"))
/** Distance field AO, for now SHOWFLAG_ALWAYS_ACCESSIBLE because it's exposed in SceneCapture */
SHOWFLAG_ALWAYS_ACCESSIBLE(DistanceFieldAO, SFG_LightingFeatures, NSLOCTEXT("UnrealEd", "DistanceFieldAOSF", "Distance Field Ambient Occlusion"))
/** Lumen GI */
SHOWFLAG_ALWAYS_ACCESSIBLE(LumenGlobalIllumination, SFG_LightingFeatures, NSLOCTEXT("UnrealEd", "LumenGlobalIlluminationSF", "Lumen Global Illumination"))
/** SHOWFLAG_ALWAYS_ACCESSIBLE because it's exposed in SceneCapture */
SHOWFLAG_ALWAYS_ACCESSIBLE(VolumetricFog, SFG_LightingFeatures, NSLOCTEXT("UnrealEd", "VolumetricFogSF", "Volumetric Fog"))
/** Visualize screen space reflections, for developer (by default off): */
SHOWFLAG_FIXED_IN_SHIPPING(0, VisualizeSSR, SFG_Visualize, NSLOCTEXT("UnrealEd", "VisualizeSSR", "Screen Space Reflections"))

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldAmbientOcclusion.cpp:711

Scope (from outer to inner):

file
function     bool FSceneRenderer::ShouldPrepareForDistanceFieldAO

Source code excerpt:


	return SupportsDistanceFieldAO(Scene->GetFeatureLevel(), Scene->GetShaderPlatform())
		&& ((ShouldRenderDeferredDynamicSkyLight(Scene, ViewFamily) && bAnyViewHasGIMethodSupportingDFAO && Scene->SkyLight->bCastShadows && ViewFamily.EngineShowFlags.DistanceFieldAO)
			|| ViewFamily.EngineShowFlags.VisualizeDistanceFieldAO
			|| (GDistanceFieldAOApplyToStaticIndirect && bAnyViewHasGIMethodSupportingDFAO && ViewFamily.EngineShowFlags.DistanceFieldAO));
}

bool FSceneRenderer::ShouldPrepareDistanceFieldScene() const
{
	if (!ensure(Scene != nullptr))
	{

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldAmbientOcclusion.cpp:931

Scope (from outer to inner):

file
function     bool FSceneRenderer::ShouldRenderDistanceFieldAO

Source code excerpt:

	}

	return ViewFamily.EngineShowFlags.DistanceFieldAO
		&& !bShouldRenderRTAO
		&& !ViewFamily.EngineShowFlags.VisualizeDistanceFieldAO
		&& !ViewFamily.EngineShowFlags.VisualizeMeshDistanceFields
		&& !ViewFamily.EngineShowFlags.VisualizeGlobalDistanceField
		&& !ViewFamily.EngineShowFlags.PathTracing;
}