r.Shadow.MaxResolution

r.Shadow.MaxResolution

#Overview

name: r.Shadow.MaxResolution

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

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 r.Shadow.MaxResolution is to set the maximum square dimensions (in texels) allowed for rendering shadow depths in Unreal Engine 5. This setting variable is primarily used for the rendering system, specifically for shadow rendering.

This setting variable is relied upon by the Unreal Engine’s rendering subsystem, particularly in the shadow rendering module. It’s referenced in the Core, Engine, and Renderer modules of Unreal Engine.

The value of this variable is set through the console variable system. It’s initialized with a default value of 2048 in the ConsoleManager.cpp file.

r.Shadow.MaxResolution interacts with other shadow-related variables, such as r.Shadow.MaxCSMResolution and the ShadowResolutionScale property of light components. It also affects the behavior of the GetMaxShadowResolution function in the rendering system.

Developers must be aware that this variable directly impacts the quality and performance trade-off of shadow rendering. Higher values result in better quality shadows but at a performance cost. The value is clamped between 4 and the hardware limit.

Best practices when using this variable include:

  1. Adjusting it based on the target hardware capabilities and performance requirements.
  2. Using it in conjunction with other shadow-related settings for optimal results.
  3. Consider scaling it dynamically based on the scene complexity or distance from the camera.
  4. Be mindful of its impact on memory usage, as larger shadow maps require more memory.
  5. Test thoroughly across different hardware configurations to ensure a good balance between quality and performance.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseDeviceProfiles.ini:897, section: [Android_Vulkan_SM5 DeviceProfile]

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

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

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

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

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

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/HAL/ConsoleManager.cpp:3862

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarShadowMaxResolution(
	TEXT("r.Shadow.MaxResolution"),
	2048,
	TEXT("Max square dimensions (in texels) allowed for rendering shadow depths. Range 4 to hardware limit. Higher = better quality shadows but at a performance cost."),
	ECVF_Scalability | ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarShadowMaxCSMShadowResolution(
	TEXT("r.Shadow.MaxCSMResolution"),

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Components/LightComponent.h:82

Scope: file

Source code excerpt:

	 * Scales the resolution of shadowmaps used to shadow this light.  By default shadowmap resolution is chosen based on screen size of the caster. 
	 * Setting the scale to zero disables shadow maps, but does not disable, e.g., contact shadows.
	 * Note: shadowmap resolution is still clamped by 'r.Shadow.MaxResolution'
	 */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Light, AdvancedDisplay, meta=(UIMin = ".125", UIMax = "8"))
	float ShadowResolutionScale;

	/** 
	 * Controls how accurate self shadowing of whole scene shadows from this light are.  
	 * At 0, shadows will start at the their caster surface, but there will be many self shadowing artifacts.
	 * larger values, shadows will start further from their caster, and there won't be self shadowing artifacts but object might appear to fly.
	 * around 0.5 seems to be a good tradeoff. This also affects the soft transition of shadows
	 */

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:758

Scope (from outer to inner):

file
function     void ScalabilityCVarsSinkCallback

Source code excerpt:


	{
		static const auto* MaxShadowResolution = ConsoleMan.FindTConsoleVariableDataInt(TEXT("r.Shadow.MaxResolution"));
		LocalScalabilityCVars.MaxShadowResolution = MaxShadowResolution->GetValueOnGameThread();
	}

	{
		static const auto* MaxCSMShadowResolution = ConsoleMan.FindTConsoleVariableDataInt(TEXT("r.Shadow.MaxCSMResolution"));
		LocalScalabilityCVars.MaxCSMShadowResolution = MaxCSMShadowResolution->GetValueOnGameThread();

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:606

Scope (from outer to inner):

file
function     int32 GetMaxShadowResolution

Source code excerpt:

int32 GetMaxShadowResolution(ERHIFeatureLevel::Type FeatureLevel)
{
	static const auto* MaxShadowResolutionCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Shadow.MaxResolution"));
	int32 MaxShadowResolution = MaxShadowResolutionCVar->GetValueOnRenderThread();

	if (FeatureLevel < ERHIFeatureLevel::SM5)
	{
		// ensure there is always enough space for mobile renderer's tiled shadow maps
		// by reducing the shadow map resolution.