r.GlobalDistanceFieldHeightFieldThicknessScale

r.GlobalDistanceFieldHeightFieldThicknessScale

#Overview

name: r.GlobalDistanceFieldHeightFieldThicknessScale

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.GlobalDistanceFieldHeightFieldThicknessScale is to control the thickness of the height field when it’s entered into the global distance field. It is primarily used in the rendering system, specifically for global distance field calculations.

This setting variable is primarily used in the Renderer module of Unreal Engine, particularly in the global distance field subsystem. It’s referenced in the GlobalDistanceField.cpp file, which is part of the rendering pipeline.

The value of this variable is set through the console variable system. It’s initialized with a default value of 4.0f and can be modified at runtime using console commands.

The associated variable GGlobalDistanceFieldHeightFieldThicknessScale directly interacts with r.GlobalDistanceFieldHeightFieldThicknessScale. They share the same value, with GGlobalDistanceFieldHeightFieldThicknessScale being the C++ variable that’s used in the actual calculations.

Developers must be aware that this variable affects the thickness of the height field in the global distance field, measured in distance field voxels. The default value of 4 means the thickness is 4 times the voxel size.

Best practices when using this variable include:

  1. Understanding that changing this value will affect the visual quality and performance of global distance field calculations.
  2. Adjusting it carefully, as it can impact both rendering quality and performance.
  3. Testing different values to find the best balance between visual quality and performance for your specific use case.

Regarding the associated variable GGlobalDistanceFieldHeightFieldThicknessScale:

This is the actual C++ variable used in the rendering calculations. It’s used in several places within the GlobalDistanceField.cpp file, particularly in setting up shader parameters for various rendering passes related to the global distance field.

The variable is used to calculate the HeightfieldThickness parameter, which is passed to various shaders. The calculation is typically done as:

HeightfieldThickness = PackedClipmap.VoxelSize.X * GGlobalDistanceFieldHeightFieldThicknessScale

This means that changing the r.GlobalDistanceFieldHeightFieldThicknessScale console variable will directly affect these shader parameters, influencing how the global distance field is rendered.

Developers should be aware that this variable is marked with ECVF_Scalability and ECVF_RenderThreadSafe flags, meaning it can be changed for scalability purposes and is safe to modify from the render thread.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

float GGlobalDistanceFieldHeightFieldThicknessScale = 4.0f;
FAutoConsoleVariableRef CVarGlobalDistanceFieldHeightFieldThicknessScale(
	TEXT("r.GlobalDistanceFieldHeightFieldThicknessScale"),
	GGlobalDistanceFieldHeightFieldThicknessScale,
	TEXT("Thickness of the height field when it's entered into the global distance field, measured in distance field voxels. Defaults to 4 which means 4x the voxel size as thickness."),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

float GAOGlobalDistanceFieldMinMeshSDFRadius = 20;

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	);

float GGlobalDistanceFieldHeightFieldThicknessScale = 4.0f;
FAutoConsoleVariableRef CVarGlobalDistanceFieldHeightFieldThicknessScale(
	TEXT("r.GlobalDistanceFieldHeightFieldThicknessScale"),
	GGlobalDistanceFieldHeightFieldThicknessScale,
	TEXT("Thickness of the height field when it's entered into the global distance field, measured in distance field voxels. Defaults to 4 which means 4x the voxel size as thickness."),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

float GAOGlobalDistanceFieldMinMeshSDFRadius = 20;
FAutoConsoleVariableRef CVarAOGlobalDistanceFieldMinMeshSDFRadius(

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

Scope (from outer to inner):

file
function     class FInitPageFreeListCS : public FGlobalShader { /*ARE_GLOBAL_SHADER
class        class FInitPageFreeListCS : public FGlobalShader
function     BEGIN_SHADER_PARAMETER_STRUCT

Source code excerpt:

						PassParameters->NumHeightfields = HeightfieldDescriptions.Num();
						PassParameters->InfluenceRadius = PackedClipmap.InfluenceRadius;
						PassParameters->HeightfieldThickness = PackedClipmap.VoxelSize.X * GGlobalDistanceFieldHeightFieldThicknessScale;
						PassParameters->HeightfieldTexture = HeightfieldTexture->GetResource()->TextureRHI;
						PassParameters->HeightfieldSampler = TStaticSamplerState<SF_Bilinear>::GetRHI();
						PassParameters->VisibilityTexture = VisibilityTexture ? VisibilityTexture->GetResource()->TextureRHI : GBlackTexture->TextureRHI;
						PassParameters->VisibilitySampler = TStaticSamplerState<SF_Bilinear>::GetRHI();
						PassParameters->HeightfieldDescriptions = GraphBuilder.CreateSRV(HeightfieldDescriptionBuffer, EPixelFormat::PF_A32B32G32R32F);

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

Scope: file

Source code excerpt:

							PassParameters->NumHeightfields = HeightfieldDescriptions.Num();
							PassParameters->InfluenceRadius = PackedClipmap.InfluenceRadius;
							PassParameters->HeightfieldThickness = PackedClipmap.VoxelSize.X * GGlobalDistanceFieldHeightFieldThicknessScale;
							PassParameters->HeightfieldTexture = HeightfieldTexture->GetResource()->TextureRHI;
							PassParameters->HeightfieldSampler = TStaticSamplerState<SF_Bilinear>::GetRHI();
							PassParameters->VisibilityTexture = VisibilityTexture ? VisibilityTexture->GetResource()->TextureRHI : GBlackTexture->TextureRHI;
							PassParameters->VisibilitySampler = TStaticSamplerState<SF_Bilinear>::GetRHI();
							PassParameters->HeightfieldDescriptions = GraphBuilder.CreateSRV(HeightfieldDescriptionBuffer, EPixelFormat::PF_A32B32G32R32F);
							PassParameters->PreViewTranslationHigh = PackedClipmap.PreViewTranslation.High;

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

Scope: file

Source code excerpt:

							PassParameters->NumHeightfields = HeightfieldDescriptions.Num();
							PassParameters->InfluenceRadius = PackedClipmap.InfluenceRadius;
							PassParameters->HeightfieldThickness = PackedClipmap.VoxelSize.X * GGlobalDistanceFieldHeightFieldThicknessScale;
							PassParameters->HeightfieldTexture = HeightfieldTexture->GetResource()->TextureRHI;
							PassParameters->HeightfieldSampler = TStaticSamplerState<SF_Bilinear>::GetRHI();
							PassParameters->VisibilityTexture = VisibilityTexture ? VisibilityTexture->GetResource()->TextureRHI : GBlackTexture->TextureRHI;
							PassParameters->VisibilitySampler = TStaticSamplerState<SF_Bilinear>::GetRHI();
							PassParameters->HeightfieldDescriptions = GraphBuilder.CreateSRV(HeightfieldDescriptionBuffer, EPixelFormat::PF_A32B32G32R32F);
							PassParameters->PreViewTranslationHigh = PackedClipmap.PreViewTranslation.High;