r.Shadow.MinResolution

r.Shadow.MinResolution

#Overview

name: r.Shadow.MinResolution

This variable is created as a Console Variable (cvar).

It is referenced in 9 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Shadow.MinResolution is to set the minimum dimensions (in texels) allowed for rendering shadow subject depths in Unreal Engine 5’s rendering system. This setting variable is primarily used in the shadow rendering subsystem of the engine.

The Unreal Engine subsystems that rely on this setting variable are primarily the Renderer module and the Engine module. This can be seen from the file paths where the variable is referenced, such as ‘Runtime/Renderer/Private/ShadowSetup.cpp’ and ‘Runtime/Engine/Private/SystemSettings.cpp’.

The value of this variable is set in multiple places:

  1. It’s initially set to 32 in the ‘ShadowSetup.cpp’ file.
  2. It can be overridden in the ‘SystemSettings.cpp’ file, where it’s set to 16 when applying overrides.
  3. It can be modified at runtime through the console variable system.

The associated variable CVarMinShadowResolution interacts closely with r.Shadow.MinResolution. They share the same value and are often used interchangeably in the code.

Developers must be aware that this variable affects the minimum resolution of shadow maps. Setting it too low might result in poor shadow quality, while setting it too high might impact performance.

Best practices when using this variable include:

  1. Balancing between shadow quality and performance.
  2. Consider the target hardware when setting this value.
  3. Use in conjunction with other shadow-related settings for optimal results.

Regarding the associated variable CVarMinShadowResolution:

The purpose of CVarMinShadowResolution is to provide a programmatic way to access and modify the r.Shadow.MinResolution setting within the C++ code.

This variable is used in various parts of the Renderer module, particularly in shadow-related calculations and setup procedures.

The value of CVarMinShadowResolution is set by reading the value of r.Shadow.MinResolution through the console variable system.

CVarMinShadowResolution interacts directly with r.Shadow.MinResolution, effectively serving as its in-code representation.

Developers should be aware that changes to CVarMinShadowResolution will affect shadow rendering throughout the engine.

Best practices for using CVarMinShadowResolution include:

  1. Use it for runtime modifications of the minimum shadow resolution.
  2. Ensure any modifications are thread-safe, as it’s often accessed on the render thread.
  3. Consider caching its value if used frequently to avoid repeated console variable lookups.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMinShadowResolution(
	TEXT("r.Shadow.MinResolution"),
	32,
	TEXT("Minimum dimensions (in texels) allowed for rendering shadow subject depths"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarMinPreShadowResolution(
	TEXT("r.Shadow.MinPreShadowResolution"),

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SystemSettings.cpp:281

Scope (from outer to inner):

file
function     void FSystemSettings::ApplyOverrides

Source code excerpt:

		// Modify various system settings to get the best quality regardless of performance impact
		{
			static auto CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shadow.MinResolution"));
			CVar->Set(16, SetBy);
		}

		// Disable shadow fading out over distance
		{
			static auto CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shadow.FadeResolution"));

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightFunctionRendering.cpp:190

Scope (from outer to inner):

file
function     float GetLightFunctionFadeFraction

Source code excerpt:


	// Override the global settings with the light's settings if the light has them specified
	static auto CVarMinShadowResolution = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Shadow.MinResolution"));
	static auto CVarShadowFadeResolution = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Shadow.FadeResolution"));

	const uint32 MinShadowResolution  = FMath::Max<int32>(0, CVarMinShadowResolution->GetValueOnRenderThread());
	const uint32 ShadowFadeResolution = FMath::Max<int32>(0, CVarShadowFadeResolution->GetValueOnRenderThread());

	// Project the bounds onto the view

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightFunctionRendering.cpp:190

Scope (from outer to inner):

file
function     float GetLightFunctionFadeFraction

Source code excerpt:


	// Override the global settings with the light's settings if the light has them specified
	static auto CVarMinShadowResolution = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Shadow.MinResolution"));
	static auto CVarShadowFadeResolution = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Shadow.FadeResolution"));

	const uint32 MinShadowResolution  = FMath::Max<int32>(0, CVarMinShadowResolution->GetValueOnRenderThread());
	const uint32 ShadowFadeResolution = FMath::Max<int32>(0, CVarShadowFadeResolution->GetValueOnRenderThread());

	// Project the bounds onto the view
	const FVector4 ScreenPosition = View.WorldToScreen(LightBounds.Center);

	int32 SizeX = View.ViewRect.Width();

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

Scope: file

Source code excerpt:

	ECVF_Scalability | ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarMinShadowResolution(
	TEXT("r.Shadow.MinResolution"),
	32,
	TEXT("Minimum dimensions (in texels) allowed for rendering shadow subject depths"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarMinPreShadowResolution(

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

Scope (from outer to inner):

file
function     static int32 GetCubeShadowDepthZIndex

Source code excerpt:

		ObjectShadowBufferResolution.X / 4,
		ObjectShadowBufferResolution.X / 8,
		CVarMinShadowResolution.GetValueOnRenderThread()
	};

	for (int32 SearchIndex = 0; SearchIndex < NumCubeShadowDepthSurfaces; SearchIndex++)
	{
		if (ShadowResolution >= SurfaceSizes[SearchIndex])
		{

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

Scope (from outer to inner):

file
function     static int32 GetCubeShadowDepthZResolution

Source code excerpt:

		FMath::Max(ObjectShadowBufferResolution.X / 4, 1),
		FMath::Max(ObjectShadowBufferResolution.X / 8, 1),
		CVarMinShadowResolution.GetValueOnRenderThread()
	};
	return SurfaceSizes[ShadowIndex];
}


FProjectedShadowInfo::FProjectedShadowInfo()

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

Scope (from outer to inner):

file
function     void FSceneRenderer::CreatePerObjectProjectedShadow

Source code excerpt:

	const uint32 MaxShadowResolution = FMath::Min<int32>(MaxShadowResolutionSetting, ShadowBufferResolution.X) - SHADOW_BORDER * 2;
	const uint32 MaxShadowResolutionY = FMath::Min<int32>(MaxShadowResolutionSetting, ShadowBufferResolution.Y) - SHADOW_BORDER * 2;
	const uint32 MinShadowResolution     = FMath::Max<int32>(0, CVarMinShadowResolution.GetValueOnRenderThread());
	const uint32 ShadowFadeResolution    = FMath::Max<int32>(0, CVarShadowFadeResolution.GetValueOnRenderThread());
	const uint32 MinPreShadowResolution  = FMath::Max<int32>(0, CVarMinPreShadowResolution.GetValueOnRenderThread());
	const uint32 PreShadowFadeResolution = FMath::Max<int32>(0, CVarPreShadowFadeResolution.GetValueOnRenderThread());
	
	// Compute the maximum resolution required for the shadow by any view. Also keep track of the unclamped resolution for fading.
	uint32 MaxDesiredResolution = 0;

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

Scope (from outer to inner):

file
function     void FSceneRenderer::CreateWholeSceneProjectedShadow

Source code excerpt:

		const uint32 ShadowBorder = ProjectedShadowInitializers[0].bOnePassPointLightShadow ? 0 : SHADOW_BORDER;
		const uint32 EffectiveDoubleShadowBorder = ShadowBorder * 2;
		const uint32 MinShadowResolution = FMath::Max<int32>(0, CVarMinShadowResolution.GetValueOnRenderThread());
		const int32 MaxShadowResolutionSetting = GetCachedScalabilityCVars().MaxShadowResolution;
		const FIntPoint ShadowBufferResolution = GetShadowDepthTextureResolution(FeatureLevel);
		const uint32 MaxShadowResolution = FMath::Min(MaxShadowResolutionSetting, ShadowBufferResolution.X) - EffectiveDoubleShadowBorder;
		const uint32 MaxShadowResolutionY = FMath::Min(MaxShadowResolutionSetting, ShadowBufferResolution.Y) - EffectiveDoubleShadowBorder;
		const uint32 ShadowFadeResolution = FMath::Max<int32>(0, CVarShadowFadeResolution.GetValueOnRenderThread());