r.AOApplyToStaticIndirect

r.AOApplyToStaticIndirect

#Overview

name: r.AOApplyToStaticIndirect

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.AOApplyToStaticIndirect is to control whether Distance Field Ambient Occlusion (DFAO) should be applied as indirect shadowing to static indirect light sources in Unreal Engine 5. These static indirect sources include lightmaps, stationary skylights, and reflection captures.

This setting variable is primarily used by the rendering system, specifically in the Distance Field Ambient Occlusion subsystem. It is part of the Renderer module in Unreal Engine 5.

The value of this variable is set through the console variable system, as indicated by the FAutoConsoleVariableRef declaration. It’s initialized to 0 (false) by default.

The associated variable GDistanceFieldAOApplyToStaticIndirect directly interacts with r.AOApplyToStaticIndirect. They share the same value and are used interchangeably in the code.

Developers must be aware that enabling this variable can have performance implications, as it increases the computation required for rendering. It’s marked with ECVF_Scalability, indicating that it affects the game’s performance scalability.

Best practices when using this variable include:

  1. Only enable it when higher quality indirect lighting is required, as it comes with a performance cost.
  2. Test the performance impact in various scenarios before enabling it in production.
  3. Consider making it a user-configurable option for players with higher-end hardware.

Regarding the associated variable GDistanceFieldAOApplyToStaticIndirect:

Developers should treat GDistanceFieldAOApplyToStaticIndirect as an internal implementation detail and interact with the feature through the r.AOApplyToStaticIndirect console variable instead.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

int32 GDistanceFieldAOApplyToStaticIndirect = 0;
FAutoConsoleVariableRef CVarDistanceFieldAOApplyToStaticIndirect(
	TEXT("r.AOApplyToStaticIndirect"),
	GDistanceFieldAOApplyToStaticIndirect,
	TEXT("Whether to apply DFAO as indirect shadowing even to static indirect sources (lightmaps + stationary skylight + reflection captures)"),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

int32 GDistanceFieldAOSpecularOcclusionMode = 1;

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

);

int32 GDistanceFieldAOApplyToStaticIndirect = 0;
FAutoConsoleVariableRef CVarDistanceFieldAOApplyToStaticIndirect(
	TEXT("r.AOApplyToStaticIndirect"),
	GDistanceFieldAOApplyToStaticIndirect,
	TEXT("Whether to apply DFAO as indirect shadowing even to static indirect sources (lightmaps + stationary skylight + reflection captures)"),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

int32 GDistanceFieldAOSpecularOcclusionMode = 1;
FAutoConsoleVariableRef CVarDistanceFieldAOSpecularOcclusionMode(

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

Scope (from outer to inner):

file
function     bool FSceneRenderer::ShouldPrepareForDistanceFieldAO

Source code excerpt:

		&& ((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:792

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderDFAOAsIndirectShadowing

Source code excerpt:

	TArray<FRDGTextureRef>& DynamicBentNormalAOTextures)
{
	if (GDistanceFieldAOApplyToStaticIndirect && ShouldRenderDistanceFieldAO() && ShouldRenderDistanceFieldLighting())
	{
		// Use the skylight's max distance if there is one, to be consistent with DFAO shadowing on the skylight
		const float OcclusionMaxDistance = Scene->SkyLight && !Scene->SkyLight->bWantsStaticShadowing ? Scene->SkyLight->OcclusionMaxDistance : Scene->DefaultMaxDistanceFieldOcclusionDistance;
		RenderDistanceFieldLighting(GraphBuilder, SceneTextures, FDistanceFieldAOParameters(OcclusionMaxDistance), DynamicBentNormalAOTextures, true, false);
	}
}

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/IndirectLightRendering.cpp:1943

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderDeferredReflectionsAndSkyLighting

Source code excerpt:

		RDG_GPU_STAT_SCOPE(GraphBuilder, SkyLightDiffuse);

		extern int32 GDistanceFieldAOApplyToStaticIndirect;
		if (Scene->SkyLight->bCastShadows
			&& !GDistanceFieldAOApplyToStaticIndirect
			&& ShouldRenderDistanceFieldAO()
			&& ShouldRenderDistanceFieldLighting()
			&& ViewFamily.EngineShowFlags.AmbientOcclusion
			&& !bReflectionCapture)
		{
			bApplySkyShadowing = true;