r.AOComputeShaderNormalCalculation

r.AOComputeShaderNormalCalculation

#Overview

name: r.AOComputeShaderNormalCalculation

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.AOComputeShaderNormalCalculation is to control whether the compute shader version of the distance field normal computation is used in the Ambient Occlusion (AO) rendering process.

This setting variable is primarily used in the rendering system of Unreal Engine, specifically in the Distance Field Ambient Occlusion (DFAO) module. It is referenced in the DistanceFieldAmbientOcclusion.cpp file, which is part of the Renderer module.

The value of this variable is set using an FAutoConsoleVariableRef, which means it can be changed at runtime through console commands. It is initialized to 0 by default, indicating that the compute shader version is not used by default.

The associated variable GAOComputeShaderNormalCalculation directly interacts with r.AOComputeShaderNormalCalculation. They share the same value, with GAOComputeShaderNormalCalculation being the actual integer variable used in the code logic.

Developers must be aware that enabling this variable (setting it to 1) will switch the distance field normal computation to use a compute shader version. This may have performance implications and could affect the visual quality of ambient occlusion in the scene.

Best practices when using this variable include:

  1. Testing the performance impact in your specific use case before enabling it.
  2. Ensuring that your hardware supports compute shaders efficiently if you decide to enable this feature.
  3. Monitoring the visual quality of ambient occlusion when toggling this setting to ensure it meets your project’s requirements.

Regarding the associated variable GAOComputeShaderNormalCalculation:

The purpose of GAOComputeShaderNormalCalculation is to serve as the actual integer variable that controls the use of compute shader for distance field normal calculation in the code logic.

This variable is used directly in the ComputeDistanceFieldNormal function within the DistanceFieldAmbientOcclusion.cpp file. It determines whether to use the compute shader path for normal calculation.

The value of GAOComputeShaderNormalCalculation is set through the r.AOComputeShaderNormalCalculation console variable.

Developers should be aware that this variable directly affects the execution path in the ComputeDistanceFieldNormal function. When it’s true (non-zero), it triggers the use of compute shaders for normal calculation.

Best practices for using GAOComputeShaderNormalCalculation include:

  1. Avoiding direct modification of this variable in code; instead, use the r.AOComputeShaderNormalCalculation console variable to change its value.
  2. When debugging DFAO issues, checking the value of this variable to understand which path is being taken for normal calculation.
  3. Considering the impact on different hardware when deciding whether to enable this feature in your project settings.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

int32 GAOComputeShaderNormalCalculation = 0;
FAutoConsoleVariableRef CVarAOComputeShaderNormalCalculation(
	TEXT("r.AOComputeShaderNormalCalculation"),
	GAOComputeShaderNormalCalculation,
	TEXT("Whether to use the compute shader version of the distance field normal computation."),
	ECVF_RenderThreadSafe
	);

int32 GAOSampleSet = 1;

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	);

int32 GAOComputeShaderNormalCalculation = 0;
FAutoConsoleVariableRef CVarAOComputeShaderNormalCalculation(
	TEXT("r.AOComputeShaderNormalCalculation"),
	GAOComputeShaderNormalCalculation,
	TEXT("Whether to use the compute shader version of the distance field normal computation."),
	ECVF_RenderThreadSafe
	);

int32 GAOSampleSet = 1;
FAutoConsoleVariableRef CVarAOSampleSet(

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

Scope (from outer to inner):

file
function     void ComputeDistanceFieldNormal

Source code excerpt:

	const FIntPoint DFAOViewSize = View.ViewRect.Size() / GAODownsampleFactor;

	if (GAOComputeShaderNormalCalculation)
	{
		uint32 GroupSizeX = FMath::DivideAndRoundUp(DFAOViewSize.X, GDistanceFieldAOTileSizeX);
		uint32 GroupSizeY = FMath::DivideAndRoundUp(DFAOViewSize.Y, GDistanceFieldAOTileSizeY);

		auto* PassParameters = GraphBuilder.AllocParameters<FComputeDistanceFieldNormalCS::FParameters>();
		PassParameters->View = View.ViewUniformBuffer;