r.FastVRam.BokehDOF

r.FastVRam.BokehDOF

#Overview

name: r.FastVRam.BokehDOF

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

It is referenced in 9 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.FastVRam.BokehDOF is to control the allocation of fast VRAM for the Bokeh Depth of Field (DOF) effect in Unreal Engine’s rendering system. This setting is part of the engine’s optimization strategy for managing graphics memory usage.

This setting variable is primarily used in the Renderer module of Unreal Engine. It’s specifically related to the scene rendering process and post-processing effects, particularly the Bokeh Depth of Field effect.

The value of this variable is set through the FASTVRAM_CVAR macro, which likely defines it as a console variable (CVar) that can be adjusted at runtime. It’s initialized with a default value of 1, indicating that fast VRAM allocation for Bokeh DOF is enabled by default.

The r.FastVRam.BokehDOF variable interacts with an associated variable named BokehDOF. They share the same value and are used together in the FFastVramConfig::Update() function to update texture flags based on the CVar’s value.

Developers should be aware that this variable affects memory allocation for the Bokeh DOF effect. Enabling it (value 1) will allocate fast VRAM for this effect, which can improve performance but may increase memory usage. Disabling it (value 0) will use standard memory allocation, potentially saving VRAM at the cost of some performance.

Best practices when using this variable include:

  1. Consider the target hardware capabilities when deciding whether to enable or disable fast VRAM for Bokeh DOF.
  2. Profile the application’s performance and memory usage with this setting both enabled and disabled to determine the optimal configuration for your specific use case.
  3. Be aware that changing this setting may require adjustments to other graphics settings to maintain the desired visual quality and performance balance.

Regarding the associated variable BokehDOF:

The purpose of BokehDOF is to represent the texture create flags for the Bokeh Depth of Field effect. It’s used in conjunction with r.FastVRam.BokehDOF to determine how the textures for this effect should be created and managed in memory.

BokehDOF is used in the Renderer module, specifically in the scene rendering and texture compression processes. It’s part of the FFastVramConfig struct, which manages various texture flags for different rendering features.

The value of BokehDOF is set based on the r.FastVRam.BokehDOF console variable in the FFastVramConfig::Update() function.

This variable interacts closely with r.FastVRam.BokehDOF, as well as other texture-related variables in the FFastVramConfig struct.

Developers should be aware that BokehDOF affects how textures for the Bokeh DOF effect are created and managed. It’s part of a larger system for optimizing texture memory usage across various rendering features.

Best practices for using BokehDOF include:

  1. Understand how it relates to the r.FastVRam.BokehDOF setting and how changes to one affect the other.
  2. Consider the impact on texture memory usage and performance when modifying this variable.
  3. Test thoroughly when making changes, as it can affect the visual quality and performance of the Bokeh DOF effect.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:470

Scope: file

Source code excerpt:

FASTVRAM_CVAR(SceneColor, 1);
FASTVRAM_CVAR(Bloom, 1);
FASTVRAM_CVAR(BokehDOF, 1);
FASTVRAM_CVAR(CircleDOF, 1);
FASTVRAM_CVAR(CombineLUTs, 1);
FASTVRAM_CVAR(Downsample, 1);
FASTVRAM_CVAR(EyeAdaptation, 1);
FASTVRAM_CVAR(Histogram, 1);
FASTVRAM_CVAR(HistogramReduce, 1);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Developer/TextureCompressor/Private/TextureCompressorModule.cpp:3053

Scope: file

Source code excerpt:


/**
 * Compute the alpha channel how BokehDOF needs it setup
 *
 * @param	Image	Image to adjust
 */
static void ComputeBokehAlpha(FImage& Image)
{
	check( Image.SizeX > 0 && Image.SizeY > 0 );

	// compute LinearAverage
	FLinearColor LinearAverage = FImageCore::ComputeImageLinearAverage(Image);

#Loc: <Workspace>/Engine/Source/Developer/TextureCompressor/Private/TextureCompressorModule.cpp:3071

Scope (from outer to inner):

file
function     static void ComputeBokehAlpha

Source code excerpt:


		// ideally this would be 1 but then some pixels would need to be >1 which is not supported for the textureformat we want to use.
		// The value affects the occlusion computation of the BokehDOF
		const float LumGoal = 0.25f;

		// clamp to avoid division by 0
		Scale *= LumGoal / FMath::Max(RGBLum, 0.001f);
	}

#Loc: <Workspace>/Engine/Source/Developer/TextureCompressor/Private/TextureCompressorModule.cpp:4411

Scope (from outer to inner):

file
class        class FTextureCompressorModule : public ITextureCompressorModule
function     bool BuildTextureMips

Source code excerpt:

			if (BuildSettings.bComputeBokehAlpha)
			{
				// To get the occlusion in the BokehDOF shader working for all Bokeh textures.
				ComputeBokehAlpha(Mip);

				if (bDoDetailedAlphaLogging)
				{
					UE_LOG(LogTextureCompressor, Display, TEXT("[alpha] Bokeh: %d - %.*s"), FImageCore::DetectAlphaChannel(Mip), DebugTexturePathName.Len(), DebugTexturePathName.GetData());
				}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/Scene.h:2109

Scope: file

Source code excerpt:

	float DepthOfFieldFarTransitionRegion;

	/** SM5: BokehDOF only: To amplify the depth of field effect (like aperture)  0=off 
	    ES3_1: Used to blend DoF. 0=off
	*/
	UPROPERTY(interp, EditAnywhere, BlueprintReadWrite, Category="Lens|Mobile Depth of Field", meta=(ClampMin = "0.0", ClampMax = "2.0", editcondition = "bOverride_DepthOfFieldScale", DisplayName = "Scale"))
	float DepthOfFieldScale;

	/** Gaussian only: Maximum size of the Depth of Field blur (in percent of the view width) (note: performance cost scales with size) */
	UPROPERTY(interp, EditAnywhere, BlueprintReadWrite, Category="Lens|Mobile Depth of Field", meta=(UIMin = "0.0", UIMax = "32.0", editcondition = "bOverride_DepthOfFieldNearBlurSize", DisplayName = "Near Blur Size"))
	float DepthOfFieldNearBlurSize;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/TextureDefines.h:56

Scope: file

Source code excerpt:

	TEXTUREGROUP_Terrain_Heightmap UMETA(DisplayName="ini:Terrain_Heightmap"),
	TEXTUREGROUP_Terrain_Weightmap UMETA(DisplayName="ini:Terrain_Weightmap"),
	/** Using this TextureGroup triggers special mip map generation code only useful for the BokehDOF post process. */
	TEXTUREGROUP_Bokeh UMETA(DisplayName="ini:Bokeh"),
	/** No compression, created on import of a .IES file. */
	TEXTUREGROUP_IESLightProfile UMETA(DisplayName="ini:IESLightProfile"),
	/** Non-filtered, useful for 2D rendering. */
	TEXTUREGROUP_Pixels2D UMETA(DisplayName="ini:2D Pixels (unfiltered)"),
	/** Hierarchical LOD generated textures*/

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:470

Scope: file

Source code excerpt:

FASTVRAM_CVAR(SceneColor, 1);
FASTVRAM_CVAR(Bloom, 1);
FASTVRAM_CVAR(BokehDOF, 1);
FASTVRAM_CVAR(CircleDOF, 1);
FASTVRAM_CVAR(CombineLUTs, 1);
FASTVRAM_CVAR(Downsample, 1);
FASTVRAM_CVAR(EyeAdaptation, 1);
FASTVRAM_CVAR(Histogram, 1);
FASTVRAM_CVAR(HistogramReduce, 1);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:670

Scope (from outer to inner):

file
function     void FFastVramConfig::Update

Source code excerpt:

	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_SceneColor, SceneColor);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_Bloom, Bloom);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_BokehDOF, BokehDOF);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_CircleDOF, CircleDOF);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_CombineLUTs, CombineLUTs);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_Downsample, Downsample);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_EyeAdaptation, EyeAdaptation);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_Histogram, Histogram);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_HistogramReduce, HistogramReduce);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.h:2819

Scope: file

Source code excerpt:

	ETextureCreateFlags SceneColor;
	ETextureCreateFlags Bloom;
	ETextureCreateFlags BokehDOF;
	ETextureCreateFlags CircleDOF;
	ETextureCreateFlags CombineLUTs;
	ETextureCreateFlags Downsample;
	ETextureCreateFlags EyeAdaptation;
	ETextureCreateFlags Histogram;
	ETextureCreateFlags HistogramReduce;