r.AOMaxViewDistance

r.AOMaxViewDistance

#Overview

name: r.AOMaxViewDistance

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.AOMaxViewDistance is to control the maximum distance at which Ambient Occlusion (AO) will be computed in the rendering system. This setting directly impacts the visual quality and performance of the ambient occlusion effect in Unreal Engine 5.

This setting variable is primarily used by the Renderer module, specifically within the Distance Field Ambient Occlusion subsystem. It’s referenced in the DistanceFieldAmbientOcclusion.cpp file, which is part of the core rendering pipeline.

The value of this variable is set through the Unreal Engine console variable system. It’s initialized with a default value of 20000 units and can be modified at runtime using console commands or through the project settings.

The r.AOMaxViewDistance variable interacts directly with its associated C++ variable GAOMaxViewDistance. They share the same value, with r.AOMaxViewDistance being the console-accessible name and GAOMaxViewDistance being the actual variable used in the C++ code.

Developers must be aware that this variable has a significant impact on both visual quality and performance. Setting it too high may result in unnecessary computations for distant objects, while setting it too low might cause noticeable pop-in of ambient occlusion effects.

Best practices when using this variable include:

  1. Adjusting it based on the scale and requirements of your specific scene.
  2. Finding a balance between visual quality and performance.
  3. Considering the target hardware capabilities when setting this value.
  4. Testing thoroughly with different values to ensure optimal results across various scenarios.

Regarding the associated variable GAOMaxViewDistance:

The purpose of GAOMaxViewDistance is to store the actual value used in the C++ code for the maximum Ambient Occlusion view distance. It’s the internal representation of the r.AOMaxViewDistance console variable.

This variable is used directly in the rendering code, specifically in the GetMaxAOViewDistance() function, which is likely called during the AO computation process. The function also includes a safeguard to ensure the value doesn’t exceed 65000 units, which is related to the precision limits of the scene depth storage in fp16 alpha.

Developers should be aware that modifying GAOMaxViewDistance directly in code is not recommended. Instead, they should use the r.AOMaxViewDistance console variable to ensure proper synchronization between the console system and the internal variable.

Best practices for GAOMaxViewDistance include:

  1. Avoiding direct manipulation in code; use the console variable system instead.
  2. Being aware of its usage in performance-critical rendering code.
  3. Understanding its relationship with scene depth storage limitations.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

float GAOMaxViewDistance = 20000;
FAutoConsoleVariableRef CVarAOMaxViewDistance(
	TEXT("r.AOMaxViewDistance"),
	GAOMaxViewDistance,
	TEXT("The maximum distance that AO will be computed at."),
	ECVF_RenderThreadSafe
	);

int32 GAOComputeShaderNormalCalculation = 0;

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	);

float GAOMaxViewDistance = 20000;
FAutoConsoleVariableRef CVarAOMaxViewDistance(
	TEXT("r.AOMaxViewDistance"),
	GAOMaxViewDistance,
	TEXT("The maximum distance that AO will be computed at."),
	ECVF_RenderThreadSafe
	);

int32 GAOComputeShaderNormalCalculation = 0;
FAutoConsoleVariableRef CVarAOComputeShaderNormalCalculation(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldAmbientOcclusion.h:73

Scope (from outer to inner):

file
function     inline float GetMaxAOViewDistance

Source code excerpt:

inline float GetMaxAOViewDistance()
{
	extern float GAOMaxViewDistance;
	// Scene depth stored in fp16 alpha, must fade out before it runs out of range
	// The fade extends past GAOMaxViewDistance a bit
	return FMath::Min(GAOMaxViewDistance, 65000.0f);
}

BEGIN_SHADER_PARAMETER_STRUCT(FAOParameters, )
	SHADER_PARAMETER(float, AOObjectMaxDistance)
	SHADER_PARAMETER(float, AOStepScale)
	SHADER_PARAMETER(float, AOStepExponentScale)