r.Shadow.MinPreShadowResolution

r.Shadow.MinPreShadowResolution

#Overview

name: r.Shadow.MinPreShadowResolution

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.MinPreShadowResolution is to set the minimum dimensions (in texels) allowed for rendering preshadow depths in Unreal Engine 5’s rendering system.

This setting variable is primarily used in the Renderer subsystem of Unreal Engine 5. It is specifically utilized in the shadow rendering process, particularly for preshadows.

The value of this variable is set in two locations:

  1. It is initially set to 8 in the ShadowSetup.cpp file.
  2. It can be overridden to 16 in the SystemSettings.cpp file when applying system overrides.

The variable interacts with other shadow-related variables, such as r.Shadow.PreShadowFadeResolution, r.Shadow.MinShadowResolution, and r.Shadow.ShadowFadeResolution. These variables work together to control various aspects of shadow rendering.

Developers must be aware that this variable directly affects the minimum resolution of preshadows. Increasing this value can potentially improve shadow quality but may also impact performance.

Best practices when using this variable include:

  1. Balancing between shadow quality and performance.
  2. Testing different values to find the optimal setting for your specific project.
  3. Considering the target hardware capabilities when adjusting this value.

Regarding the associated variable CVarMinPreShadowResolution:

The purpose of CVarMinPreShadowResolution is to provide a programmatic interface for the r.Shadow.MinPreShadowResolution setting within the engine’s code.

This variable is used directly in the Renderer module, specifically in the shadow setup and creation processes.

The value of CVarMinPreShadowResolution is set when r.Shadow.MinPreShadowResolution is initialized, and it’s accessed using the GetValueOnRenderThread() method.

CVarMinPreShadowResolution interacts closely with other shadow-related console variables like CVarMinShadowResolution, CVarShadowFadeResolution, and CVarPreShadowFadeResolution.

Developers should be aware that this variable is used in performance-critical rendering code, so frequent access or modification could potentially impact rendering performance.

Best practices for using CVarMinPreShadowResolution include:

  1. Accessing its value on the render thread when needed.
  2. Avoiding frequent changes to its value during runtime.
  3. Using it in conjunction with other shadow-related variables for a comprehensive shadow quality control system.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMinPreShadowResolution(
	TEXT("r.Shadow.MinPreShadowResolution"),
	8,
	TEXT("Minimum dimensions (in texels) allowed for rendering preshadow depths"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarParallelGatherShadowPrimitives(
	TEXT("r.ParallelGatherShadowPrimitives"),

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

Scope (from outer to inner):

file
function     void FSystemSettings::ApplyOverrides

Source code excerpt:

		// Increase minimum preshadow resolution
		{
			static auto CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shadow.MinPreShadowResolution"));
			CVar->Set(16, SetBy);
		}

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

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarMinPreShadowResolution(
	TEXT("r.Shadow.MinPreShadowResolution"),
	8,
	TEXT("Minimum dimensions (in texels) allowed for rendering preshadow depths"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarParallelGatherShadowPrimitives(

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

Scope (from outer to inner):

file
function     void FSceneRenderer::CreatePerObjectProjectedShadow

Source code excerpt:

	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;
	float MaxScreenPercent = 0;
	TArray<float, TInlineAllocator<2> > ResolutionFadeAlphas;