r.DepthOfField.MaxSize

r.DepthOfField.MaxSize

#Overview

name: r.DepthOfField.MaxSize

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.DepthOfField.MaxSize is to clamp the gaussian depth of field radius for better performance in Unreal Engine’s rendering system. This setting variable is part of the post-processing subsystem, specifically the Depth of Field effect.

The Unreal Engine’s renderer module relies on this setting variable, as evidenced by its usage in the PostProcessing.cpp file within the Runtime/Renderer/Private/PostProcess directory.

The value of this variable is set as a console variable with a default value of 100.0f. It can be modified at runtime through the console or programmatically.

This variable interacts with the View.FinalPostProcessSettings.DepthOfFieldFarBlurSize and View.FinalPostProcessSettings.DepthOfFieldNearBlurSize variables. The r.DepthOfField.MaxSize value is used to clamp these blur sizes.

Developers must be aware that this variable affects both the near and far depth of field blur sizes. It’s important to note that setting this value too low might result in a less pronounced depth of field effect, while setting it too high might impact performance.

Best practices when using this variable include:

  1. Adjusting it based on the specific needs of your scene and target hardware capabilities.
  2. Using it in conjunction with other depth of field settings for optimal visual results and performance.
  3. Testing thoroughly on various hardware configurations to ensure a good balance between visual quality and performance.

The associated variable CVarDepthOfFieldMaxSize is the actual C++ variable that stores and provides access to the r.DepthOfField.MaxSize value. It’s defined as a TAutoConsoleVariable, which allows it to be modified via the console and accessed in the render thread.

The purpose of CVarDepthOfFieldMaxSize is to provide a programmatic interface to the r.DepthOfField.MaxSize setting. It’s used in the rendering code to retrieve the current value of the setting and apply it to the depth of field calculations.

This variable is used in the IsGaussianActive function and the AddMobilePostProcessingPasses function to clamp the near and far blur sizes. Developers should be aware that changes to this variable will take effect in real-time, affecting the depth of field rendering immediately.

When working with CVarDepthOfFieldMaxSize, best practices include:

  1. Using GetValueOnRenderThread() to access its value in render thread code.
  2. Being cautious when modifying it during runtime, as it can affect visual consistency.
  3. Considering its impact on both desktop and mobile rendering paths, as it’s used in mobile post-processing as well.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessing.cpp:90

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:


TAutoConsoleVariable<float> CVarDepthOfFieldMaxSize(
	TEXT("r.DepthOfField.MaxSize"),
	100.0f,
	TEXT("Allows to clamp the gaussian depth of field radius (for better performance), default: 100"),
	ECVF_Scalability | ECVF_RenderThreadSafe);

TAutoConsoleVariable<bool> CVarBloomApplyLocalExposure(
	TEXT("r.Bloom.ApplyLocalExposure"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessing.cpp:89

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:

	ECVF_RenderThreadSafe);

TAutoConsoleVariable<float> CVarDepthOfFieldMaxSize(
	TEXT("r.DepthOfField.MaxSize"),
	100.0f,
	TEXT("Allows to clamp the gaussian depth of field radius (for better performance), default: 100"),
	ECVF_Scalability | ECVF_RenderThreadSafe);

TAutoConsoleVariable<bool> CVarBloomApplyLocalExposure(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessing.cpp:2084

Scope (from outer to inner):

file
function     static bool IsGaussianActive

Source code excerpt:

	float NearSize = View.FinalPostProcessSettings.DepthOfFieldNearBlurSize;

	float MaxSize = CVarDepthOfFieldMaxSize.GetValueOnRenderThread();

	FarSize = FMath::Min(FarSize, MaxSize);
	NearSize = FMath::Min(NearSize, MaxSize);
	const float CVarThreshold = CVarDepthOfFieldNearBlurSizeThreshold.GetValueOnRenderThread();

	if ((FarSize < 0.01f) && (NearSize < CVarThreshold))

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessing.cpp:2412

Scope (from outer to inner):

file
function     void AddMobilePostProcessingPasses

Source code excerpt:

					float FarSize = View.FinalPostProcessSettings.DepthOfFieldFarBlurSize;
					float NearSize = View.FinalPostProcessSettings.DepthOfFieldNearBlurSize;
					const float MaxSize = CVarDepthOfFieldMaxSize.GetValueOnRenderThread();
					FarSize = FMath::Min(FarSize, MaxSize);
					NearSize = FMath::Min(NearSize, MaxSize);
					const bool bFar = FarSize >= 0.01f;
					const bool bNear = NearSize >= CVarDepthOfFieldNearBlurSizeThreshold.GetValueOnRenderThread();
					const bool bCombinedNearFarPass = bFar && bNear;