Canvas.DistanceFieldSmoothness

Canvas.DistanceFieldSmoothness

#Overview

name: Canvas.DistanceFieldSmoothness

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 Canvas.DistanceFieldSmoothness is to control the global sharpness of distance field fonts and shapes rendered by the canvas in Unreal Engine 5. This setting variable is primarily used in the rendering system, specifically for batched elements and distance field rendering.

Based on the Callsites section, this setting variable is used in the Engine module, particularly in the BatchedElements.cpp file. It is primarily utilized by the rendering subsystem for handling batched elements and distance field rendering.

The value of this variable is set through an FAutoConsoleVariableRef, which means it can be adjusted at runtime through the console or configuration files. The default value is 4, as seen in the associated variable GBatchedElementSmoothWidth.

The Canvas.DistanceFieldSmoothness variable interacts directly with GBatchedElementSmoothWidth. They share the same value, with GBatchedElementSmoothWidth being the actual float variable used in the code.

Developers must be aware that this variable affects the visual quality of distance field fonts and shapes. A lower value will result in sharper edges, while a higher value will produce smoother but potentially blurrier results.

Best practices when using this variable include:

  1. Adjusting it based on the specific needs of your project’s visual style.
  2. Testing different values to find the optimal balance between sharpness and smoothness.
  3. Considering performance implications, as extreme values might affect rendering performance.

Regarding the associated variable GBatchedElementSmoothWidth:

The purpose of GBatchedElementSmoothWidth is to store the actual float value used for the smoothing width of batched elements with distance field blend modes.

This variable is used in the Engine module, specifically in the BatchedElements.cpp file, which is part of the rendering subsystem.

The value of GBatchedElementSmoothWidth is set through the Canvas.DistanceFieldSmoothness console variable.

GBatchedElementSmoothWidth interacts with other rendering-related variables and is used in calculations for shadow smoothness and glow effects.

Developers should be aware that this variable directly affects the rendering of batched elements, particularly those using distance field blend modes.

Best practices for using GBatchedElementSmoothWidth include:

  1. Modifying it through the Canvas.DistanceFieldSmoothness console variable rather than directly.
  2. Considering its impact on both regular distance field rendering and shadowed distance field rendering.
  3. Testing its effects in various rendering scenarios to ensure consistent visual quality across different use cases.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/BatchedElements.cpp:542

Scope: file

Source code excerpt:



FAutoConsoleVariableRef CVarWellCanvasDistanceFieldSmoothWidth(TEXT("Canvas.DistanceFieldSmoothness"), GBatchedElementSmoothWidth, TEXT("Global sharpness of distance field fonts/shapes rendered by canvas."), ECVF_Default);

template<class TSimpleElementPixelShader>
static TShaderRef<TSimpleElementPixelShader> GetPixelShader(ESimpleElementBlendMode BlendMode, ERHIFeatureLevel::Type FeatureLevel)
{
	return TShaderMapRef<TSimpleElementPixelShader>(GetGlobalShaderMap(FeatureLevel));
}

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/BatchedElements.cpp:539

Scope: file

Source code excerpt:


/** Global smoothing width for rendering batched elements with distance field blend modes */
float GBatchedElementSmoothWidth = 4;


FAutoConsoleVariableRef CVarWellCanvasDistanceFieldSmoothWidth(TEXT("Canvas.DistanceFieldSmoothness"), GBatchedElementSmoothWidth, TEXT("Global sharpness of distance field fonts/shapes rendered by canvas."), ECVF_Default);

template<class TSimpleElementPixelShader>
static TShaderRef<TSimpleElementPixelShader> GetPixelShader(ESimpleElementBlendMode BlendMode, ERHIFeatureLevel::Type FeatureLevel)
{
	return TShaderMapRef<TSimpleElementPixelShader>(GetGlobalShaderMap(FeatureLevel));
}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/BatchedElements.cpp:722

Scope (from outer to inner):

file
function     void FBatchedElements::PrepareShaders

Source code excerpt:

				static FVector2D ShadowDirection(-1.0f/Texture->GetSizeX(),-1.0f/Texture->GetSizeY());
				static FLinearColor ShadowColor(FLinearColor::Black);
				const float ShadowSmoothWidth = (GBatchedElementSmoothWidth * 2) / Texture->GetSizeX();
				
				const bool EnableShadow = (
					BlendMode == SE_BLEND_MaskedDistanceFieldShadowed || 
					BlendMode == SE_BLEND_TranslucentDistanceFieldShadowed
					);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/BatchedElements.cpp:735

Scope (from outer to inner):

file
function     void FBatchedElements::PrepareShaders

Source code excerpt:

					Gamma,
					AlphaRefVal,
					GBatchedElementSmoothWidth,
					EnableShadow,
					ShadowDirection,
					ShadowColor,
					ShadowSmoothWidth,
					(GlowInfo != NULL) ? *GlowInfo : FDepthFieldGlowInfo(),
					BlendMode