r.AOGlobalDistanceField.FastCameraMode

r.AOGlobalDistanceField.FastCameraMode

#Overview

name: r.AOGlobalDistanceField.FastCameraMode

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.AOGlobalDistanceField.FastCameraMode is to control the update behavior of the Global Distance Field for fast camera movement scenarios in Unreal Engine’s rendering system. This setting is specifically designed to improve performance and responsiveness of lighting updates when the camera is moving rapidly.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically within the Global Distance Field subsystem. It affects how the Global Signed Distance Field (SDF) is updated and processed.

The value of this variable is set through the Unreal Engine console variable system. It’s defined as an integer (int32) and initialized to 0 by default.

The associated variable GAOGlobalDistanceFieldFastCameraMode directly interacts with r.AOGlobalDistanceField.FastCameraMode. They share the same value, with GAOGlobalDistanceFieldFastCameraMode being the actual variable used in the C++ code to control the behavior.

Developers should be aware of several important aspects when using this variable:

  1. Enabling this mode (setting it to a non-zero value) will result in lower quality but faster updates of the Global SDF.
  2. It affects the minimum mesh SDF radius calculation, potentially increasing it by a factor of 5 to 10 when enabled.
  3. It influences the number of clipmap updates per frame and the total number of global distance field clipmaps.
  4. When enabled, it introduces a camera velocity offset calculation to account for rapid camera movement.

Best practices for using this variable include:

  1. Enable it only when dealing with scenarios involving fast camera movement where lighting responsiveness is crucial.
  2. Be aware of the quality trade-off when enabling this mode.
  3. Test thoroughly to ensure the visual quality remains acceptable for your specific use case.
  4. Consider the performance impact on different hardware configurations.

Regarding the associated variable GAOGlobalDistanceFieldFastCameraMode:

The purpose of GAOGlobalDistanceFieldFastCameraMode is to serve as the internal representation of the r.AOGlobalDistanceField.FastCameraMode console variable within the C++ code.

It is used directly in the Renderer module to control the behavior of the Global Distance Field system.

Its value is set by the console variable system when r.AOGlobalDistanceField.FastCameraMode is modified.

This variable interacts with several other variables and calculations in the Global Distance Field system, affecting mesh SDF radius, clipmap updates, and camera velocity offset.

Developers should treat GAOGlobalDistanceFieldFastCameraMode as the actual control variable in the code, while using r.AOGlobalDistanceField.FastCameraMode for external configuration.

Best practices include using this variable consistently throughout the codebase when checking for the fast camera mode, and ensuring it’s properly synchronized with the console variable if modified programmatically.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/GlobalDistanceField.cpp:176

Scope: file

Source code excerpt:

int32 GAOGlobalDistanceFieldFastCameraMode = 0;
FAutoConsoleVariableRef CVarAOGlobalDistanceFieldFastCameraMode(
	TEXT("r.AOGlobalDistanceField.FastCameraMode"),
	GAOGlobalDistanceFieldFastCameraMode,
	TEXT("Whether to update the Global SDF for fast camera movement - lower quality, faster updates so lighting can keep up with the camera."),
	ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int32> CVarAOGlobalDistanceFieldAverageCulledObjectsPerCell(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/GlobalDistanceField.cpp:174

Scope: file

Source code excerpt:

	);

int32 GAOGlobalDistanceFieldFastCameraMode = 0;
FAutoConsoleVariableRef CVarAOGlobalDistanceFieldFastCameraMode(
	TEXT("r.AOGlobalDistanceField.FastCameraMode"),
	GAOGlobalDistanceFieldFastCameraMode,
	TEXT("Whether to update the Global SDF for fast camera movement - lower quality, faster updates so lighting can keep up with the camera."),
	ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int32> CVarAOGlobalDistanceFieldAverageCulledObjectsPerCell(
	TEXT("r.AOGlobalDistanceField.AverageCulledObjectsPerCell"),

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/GlobalDistanceField.cpp:364

Scope (from outer to inner):

file
function     float GetMinMeshSDFRadius

Source code excerpt:

float GetMinMeshSDFRadius(float VoxelWorldSize)
{
	float MinRadius = GAOGlobalDistanceFieldMinMeshSDFRadius * (GAOGlobalDistanceFieldFastCameraMode ? 10.0f : 1.0f);
	float MinVoxelRadius = GAOGlobalDistanceFieldMinMeshSDFRadiusInVoxels * VoxelWorldSize * (GAOGlobalDistanceFieldFastCameraMode ? 5.0f : 1.0f);

	return FMath::Max(MinRadius, MinVoxelRadius);
}

int32 GetNumClipmapUpdatesPerFrame()
{
	return GAOGlobalDistanceFieldFastCameraMode ? 1 : GAOGlobalDistanceFieldClipmapUpdatesPerFrame;
}

int32 GlobalDistanceField::GetNumGlobalDistanceFieldClipmaps(bool bLumenEnabled, float LumenSceneViewDistance)
{
	int32 WantedClipmaps = GAOGlobalDistanceFieldNumClipmaps;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/GlobalDistanceField.cpp:391

Scope (from outer to inner):

file
function     int32 GlobalDistanceField::GetNumGlobalDistanceFieldClipmaps

Source code excerpt:

	}

	if (GAOGlobalDistanceFieldFastCameraMode)
	{
		WantedClipmaps++;
	}
	return FMath::Clamp<int32>(WantedClipmaps, 0, GlobalDistanceField::MaxClipmaps);
}

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/GlobalDistanceField.cpp:720

Scope (from outer to inner):

file
function     static void UpdateGlobalDistanceFieldViewOrigin

Source code excerpt:

	if (View.ViewState && (View.ViewState->GlobalDistanceFieldData->bFirstFrame || View.ViewState->GlobalDistanceFieldData->UpdateFrame != View.Family->FrameNumber))
	{
		if (GAOGlobalDistanceFieldFastCameraMode != 0)
		{
			FVector& CameraVelocityOffset = View.ViewState->GlobalDistanceFieldData->CameraVelocityOffset;
			const FVector CameraVelocity = View.ViewMatrices.GetViewOrigin() - View.PrevViewInfo.ViewMatrices.GetViewOrigin();
			// Framerate independent decay
			CameraVelocityOffset = CameraVelocityOffset * FMath::Pow(GAOGlobalDistanceFieldCameraPositionVelocityOffsetDecay, View.Family->Time.GetDeltaWorldTimeSeconds()) + CameraVelocity;