r.DFShadow.TwoSidedMeshDistanceBiasScale

r.DFShadow.TwoSidedMeshDistanceBiasScale

#Overview

name: r.DFShadow.TwoSidedMeshDistanceBiasScale

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.DFShadow.TwoSidedMeshDistanceBiasScale is to control the distance bias scaling when calculating distance field shadows for two-sided meshes in Unreal Engine’s rendering system. This setting is specifically used to improve the appearance of shadows cast by two-sided meshes, such as trees, to make them match up better with standard shadow mapping techniques.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically within the distance field shadowing subsystem. It’s referenced in the DistanceFieldShadowing.cpp and LumenSceneDirectLighting.cpp files, which are part of the rendering pipeline.

The value of this variable is set through the Unreal Engine console variable system. It’s initialized with a default value of 1.0f and can be modified at runtime using the console command “r.DFShadow.TwoSidedMeshDistanceBiasScale”.

The associated variable GDFShadowTwoSidedMeshDistanceBiasScale interacts directly with r.DFShadow.TwoSidedMeshDistanceBiasScale. They share the same value, with GDFShadowTwoSidedMeshDistanceBiasScale being the actual float variable used in the C++ code.

Developers should be aware that modifying this variable will affect the appearance of shadows cast by two-sided meshes when using distance field shadowing. It’s particularly useful for adjusting tree shadows to match the appearance of shadows created using standard shadow mapping techniques.

Best practices when using this variable include:

  1. Start with the default value of 1.0 and adjust incrementally.
  2. Test the changes in various lighting conditions and with different types of two-sided meshes.
  3. Be mindful of performance implications when modifying shadow calculations.
  4. Document any changes made to this setting for your project, as it may affect the visual consistency of shadows across different scenes.

Regarding the associated variable GDFShadowTwoSidedMeshDistanceBiasScale:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldShadowing.cpp:75

Scope: file

Source code excerpt:

float GDFShadowTwoSidedMeshDistanceBiasScale = 1.0f;
FAutoConsoleVariableRef CVarShadowTwoSidedMeshDistanceBiasScale(
	TEXT("r.DFShadow.TwoSidedMeshDistanceBiasScale"),
	GDFShadowTwoSidedMeshDistanceBiasScale,
	TEXT("Scale applied to distance bias when calculating distance field shadows of two sided meshes. This is useful to get tree shadows to match up with standard shadow mapping."),
	ECVF_RenderThreadSafe
	);

int32 GAverageObjectsPerShadowCullTile = 128;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldShadowing.cpp:73

Scope: file

Source code excerpt:

	);

float GDFShadowTwoSidedMeshDistanceBiasScale = 1.0f;
FAutoConsoleVariableRef CVarShadowTwoSidedMeshDistanceBiasScale(
	TEXT("r.DFShadow.TwoSidedMeshDistanceBiasScale"),
	GDFShadowTwoSidedMeshDistanceBiasScale,
	TEXT("Scale applied to distance bias when calculating distance field shadows of two sided meshes. This is useful to get tree shadows to match up with standard shadow mapping."),
	ECVF_RenderThreadSafe
	);

int32 GAverageObjectsPerShadowCullTile = 128;
FAutoConsoleVariableRef CVarAverageObjectsPerShadowCullTile(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldShadowing.cpp:804

Scope (from outer to inner):

file
function     void RayTraceShadows

Source code excerpt:

		PassParameters->HeightFieldAtlasParameters = HeightFieldAtlasParameters;
		PassParameters->TranslatedWorldToShadow = FMatrix44f(FTranslationMatrix(ProjectedShadowInfo->PreShadowTranslation - View.ViewMatrices.GetPreViewTranslation()) * FMatrix(ProjectedShadowInfo->TranslatedWorldToClipInnerMatrix));
		PassParameters->TwoSidedMeshDistanceBiasScale = GDFShadowTwoSidedMeshDistanceBiasScale;
		PassParameters->Substrate = Substrate::BindSubstrateGlobalUniformParameters(View);

		if (ProjectedShadowInfo->bDirectionalLight)
		{
			PassParameters->MinDepth = ProjectedShadowInfo->CascadeSettings.SplitNear - ProjectedShadowInfo->CascadeSettings.SplitNearFadeRegion;
			PassParameters->MaxDepth = ProjectedShadowInfo->CascadeSettings.SplitFar;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Lumen/LumenSceneDirectLighting.cpp:1227

Scope (from outer to inner):

file
function     void TraceDistanceFieldShadows

Source code excerpt:

{
	extern int32 GDistanceFieldOffsetDataStructure;
	extern float GDFShadowTwoSidedMeshDistanceBiasScale;

	auto SetCommonParameters = [&](
		FLumenSceneDirectLightingTraceDistanceFieldShadowsCS::FParameters* PassParameters,
		const FLightTileIntersectionParameters& LightTileIntersectionParameters,
		const FMatrix& WorldToMeshSDFShadowValue)
	{

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Lumen/LumenSceneDirectLighting.cpp:1251

Scope (from outer to inner):

file
function     void TraceDistanceFieldShadows
lambda-function

Source code excerpt:

		PassParameters->DistanceFieldAtlasParameters = DistanceFieldAtlasParameters;
		PassParameters->TranslatedWorldToShadow = FMatrix44f(FTranslationMatrix(-View.ViewMatrices.GetPreViewTranslation()) * WorldToMeshSDFShadowValue);
		PassParameters->TwoSidedMeshDistanceBiasScale = GDFShadowTwoSidedMeshDistanceBiasScale;

		PassParameters->MaxTraceDistance = Lumen::GetMaxTraceDistance(View);
		PassParameters->StepFactor = FMath::Clamp(GOffscreenShadowingTraceStepFactor, .1f, 10.0f);
		PassParameters->MeshSDFShadowRayBias = LumenSceneDirectLighting::GetMeshSDFShadowRayBias();
		PassParameters->HeightfieldShadowRayBias = LumenSceneDirectLighting::GetHeightfieldShadowRayBias();
		PassParameters->GlobalSDFShadowRayBias = LumenSceneDirectLighting::GetGlobalSDFShadowRayBias();