r.DistanceFieldShadowing

r.DistanceFieldShadowing

#Overview

name: r.DistanceFieldShadowing

The value of this variable can be defined or overridden in .ini config files. 5 .ini config files referencing this setting variable.

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.DistanceFieldShadowing is to control whether the distance field shadowing feature is allowed in Unreal Engine 5. This setting variable is primarily used for the rendering system, specifically for shadow rendering.

This setting variable is primarily used by the Renderer module of Unreal Engine 5. It’s also referenced in the MetalRHI module for Apple platforms and the Engine module, specifically in the DirectionalLightComponent.

The value of this variable is set through the console variable system. It’s initialized with a default value of 1 (enabled) in the DistanceFieldShadowing.cpp file. However, it can be changed at runtime using console commands or through game settings.

The associated variable GDistanceFieldShadowing directly interacts with r.DistanceFieldShadowing. They share the same value, with GDistanceFieldShadowing being the actual int32 variable used in the C++ code, while r.DistanceFieldShadowing is the console variable name used for external access and configuration.

Developers must be aware that this variable affects the rendering performance and visual quality of the game. Enabling distance field shadowing can provide more accurate and higher quality shadows, especially for large-scale environments, but it comes with a performance cost.

Best practices when using this variable include:

  1. Consider the target hardware when deciding to enable or disable this feature.
  2. Test the performance impact in various scenarios before finalizing the setting.
  3. Provide an in-game option for players to toggle this feature if performance is a concern on lower-end systems.

Regarding the associated variable GDistanceFieldShadowing:

The purpose of GDistanceFieldShadowing is to serve as the internal C++ representation of the r.DistanceFieldShadowing setting. It’s used directly in the code to check if distance field shadowing is enabled.

This variable is primarily used in the Renderer module, specifically in the DistanceFieldShadowing.cpp file.

The value of GDistanceFieldShadowing is set through the console variable system, mirroring the value of r.DistanceFieldShadowing.

It interacts directly with the console variable r.DistanceFieldShadowing, and is used in functions like SupportsDistanceFieldShadows to determine if the feature should be active.

Developers should be aware that modifying GDistanceFieldShadowing directly in code is not recommended. Instead, they should use the console variable r.DistanceFieldShadowing to ensure consistency across the engine.

Best practices include using GDistanceFieldShadowing for internal checks in rendering code, but relying on the console variable system for any runtime changes or user-facing settings.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseScalability.ini:137, section: [ShadowQuality@0]

Location: <Workspace>/Engine/Config/BaseScalability.ini:161, section: [ShadowQuality@1]

Location: <Workspace>/Engine/Config/BaseScalability.ini:185, section: [ShadowQuality@2]

Location: <Workspace>/Engine/Config/BaseScalability.ini:212, section: [ShadowQuality@3]

Location: <Workspace>/Engine/Config/BaseScalability.ini:239, section: [ShadowQuality@Cine]

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

int32 GDistanceFieldShadowing = 1;
FAutoConsoleVariableRef CVarDistanceFieldShadowing(
	TEXT("r.DistanceFieldShadowing"),
	GDistanceFieldShadowing,
	TEXT("Whether the distance field shadowing feature is allowed."),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

int32 GDFShadowQuality = 3;

#Loc: <Workspace>/Engine/Source/Runtime/Apple/MetalRHI/Private/MetalRHI.cpp:508

Scope: file

Source code excerpt:

		}
		
		static auto CVarDistanceFieldShadowing = IConsoleManager::Get().FindConsoleVariable(TEXT("r.DistanceFieldShadowing"));
		if(CVarDistanceFieldShadowing && CVarDistanceFieldShadowing->GetInt() != 0)
		{
			CVarDistanceFieldShadowing->Set(0);
		}
	}
	

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/DirectionalLightComponent.cpp:549

Scope (from outer to inner):

file
class        class FDirectionalLightSceneProxy : public FLightSceneProxy
function     virtual bool ShouldCreateRayTracedCascade

Source code excerpt:

	virtual bool ShouldCreateRayTracedCascade(ERHIFeatureLevel::Type InFeatureLevel, bool bPrecomputedLightingIsValid, int32 MaxNearCascades) const override
	{
		static auto CVarDistanceFieldShadowing = IConsoleManager::Get().FindConsoleVariable(TEXT("r.DistanceFieldShadowing"));
		static IConsoleVariable* CVarHFShadowing = IConsoleManager::Get().FindConsoleVariable(TEXT("r.HeightFieldShadowing"));

		if (CVarDistanceFieldShadowing != nullptr && CVarDistanceFieldShadowing->GetInt() == 0 && (!CVarHFShadowing || !CVarHFShadowing->GetInt()))
		{
			return false;
		}

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

#include "PixelShaderUtils.h"

int32 GDistanceFieldShadowing = 1;
FAutoConsoleVariableRef CVarDistanceFieldShadowing(
	TEXT("r.DistanceFieldShadowing"),
	GDistanceFieldShadowing,
	TEXT("Whether the distance field shadowing feature is allowed."),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

int32 GDFShadowQuality = 3;
FAutoConsoleVariableRef CVarDFShadowQuality(

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

Scope (from outer to inner):

file
function     bool SupportsDistanceFieldShadows

Source code excerpt:

bool SupportsDistanceFieldShadows(ERHIFeatureLevel::Type FeatureLevel, EShaderPlatform ShaderPlatform)
{
	return GDistanceFieldShadowing 
		&& GetDFShadowQuality() > 0
		&& DoesPlatformSupportDistanceFieldShadowing(ShaderPlatform);
}

bool SupportsHeightFieldShadows(ERHIFeatureLevel::Type FeatureLevel, EShaderPlatform ShaderPlatform)
{