r.Shadow.PreShadowResolutionFactor

r.Shadow.PreShadowResolutionFactor

#Overview

name: r.Shadow.PreShadowResolutionFactor

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 9 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Shadow.PreShadowResolutionFactor is to control the resolution of pre-shadows in Unreal Engine’s rendering system. It acts as a multiplier for the pre-shadow resolution, allowing developers to adjust the quality and performance of shadow rendering.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically in the shadow rendering and setup components. It’s referenced in files such as ShadowSetup.cpp and ShadowRendering.cpp, which are part of the core rendering pipeline.

The value of this variable is initially set to 0.5f in the engine’s source code, but it can be modified at runtime through the console variable system. It’s defined as a TAutoConsoleVariable, which means it can be adjusted during gameplay or development without recompiling the engine.

The associated variable CVarPreShadowResolutionFactor interacts directly with r.Shadow.PreShadowResolutionFactor. They share the same value and are used interchangeably in the code.

Developers should be aware that this variable affects the performance and visual quality of pre-shadows. A higher value will result in higher resolution shadows but may impact performance, while a lower value will improve performance at the cost of shadow quality.

Best practices when using this variable include:

  1. Balancing between visual quality and performance based on the target hardware.
  2. Testing different values to find the optimal setting for your specific game or application.
  3. Considering adjusting this value dynamically based on the scene complexity or distance from the camera.

Regarding the associated variable CVarPreShadowResolutionFactor:

When working with either variable, it’s important to consider the impact on both visual quality and performance, and to test thoroughly on various hardware configurations to ensure a good balance is achieved.

#Setting Variables

#References In INI files

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

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

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

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

Location: <Workspace>/Engine/Config/BaseScalability.ini:238, 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/ShadowSetup.cpp:199

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarPreShadowResolutionFactor(
	TEXT("r.Shadow.PreShadowResolutionFactor"),
	0.5f,
	TEXT("Mulitplier for preshadow resolution"),
	ECVF_Scalability | ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarShadowTexelsPerPixel(
	TEXT("r.Shadow.TexelsPerPixel"),

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

Scope (from outer to inner):

file
function     void FSystemSettings::ApplyOverrides

Source code excerpt:

		// Don't downsample preshadows
		{
			static auto CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shadow.PreShadowResolutionFactor"));
			CVar->Set(1.0f, SetBy);
		}
	}
}

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:1389

Scope: file

Source code excerpt:

			else if (LocalQuality > 2 && !bWholeSceneShadow)
			{
				static auto CVarPreShadowResolutionFactor = IConsoleManager::Get().FindTConsoleVariableDataFloat(TEXT("r.Shadow.PreShadowResolutionFactor"));
				const int32 TargetResolution = bPreShadow ? FMath::TruncToInt(512 * CVarPreShadowResolutionFactor->GetValueOnRenderThread()) : 512;

				int32 Reduce = 0;

				{
					int32 Res = ResolutionX;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:1389

Scope: file

Source code excerpt:

			else if (LocalQuality > 2 && !bWholeSceneShadow)
			{
				static auto CVarPreShadowResolutionFactor = IConsoleManager::Get().FindTConsoleVariableDataFloat(TEXT("r.Shadow.PreShadowResolutionFactor"));
				const int32 TargetResolution = bPreShadow ? FMath::TruncToInt(512 * CVarPreShadowResolutionFactor->GetValueOnRenderThread()) : 512;

				int32 Reduce = 0;

				{
					int32 Res = ResolutionX;

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

Scope: file

Source code excerpt:

	);

static TAutoConsoleVariable<float> CVarPreShadowResolutionFactor(
	TEXT("r.Shadow.PreShadowResolutionFactor"),
	0.5f,
	TEXT("Mulitplier for preshadow resolution"),
	ECVF_Scalability | ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarShadowTexelsPerPixel(

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

Scope (from outer to inner):

file
function     static FIntPoint GetPreShadowCacheTextureResolution

Source code excerpt:

	const int32 ExpandFactor = GetTranslucentShadowDownsampleFactor();

	float Factor = CVarPreShadowResolutionFactor.GetValueOnRenderThread();

	FIntPoint Ret;

	Ret.X = FMath::Clamp(FMath::TruncToInt(ShadowDepthResolution.X * Factor) * ExpandFactor, 1, (int32)GMaxShadowDepthBufferSizeX);
	Ret.Y = FMath::Clamp(FMath::TruncToInt(ShadowDepthResolution.Y * Factor) * ExpandFactor, 1, (int32)GMaxShadowDepthBufferSizeY);

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

Scope (from outer to inner):

file
function     void FSceneRenderer::CreatePerObjectProjectedShadow

Source code excerpt:

		ResolutionFadeAlphas.Add(ViewSpecificAlpha);

		const float ViewSpecificPreShadowAlpha = CalculateShadowFadeAlpha(UnclampedResolution * CVarPreShadowResolutionFactor.GetValueOnRenderThread(), PreShadowFadeResolution, MinPreShadowResolution) * LightSceneInfo->Proxy->GetShadowAmount();
		MaxResolutionPreShadowFadeAlpha = FMath::Max(MaxResolutionPreShadowFadeAlpha, ViewSpecificPreShadowAlpha);
		ResolutionPreShadowFadeAlphas.Add(ViewSpecificPreShadowAlpha);

		const float ShadowResolutionScale = LightSceneInfo->Proxy->GetShadowResolutionScale();

		float ClampedResolution = UnclampedResolution;

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

Scope (from outer to inner):

file
function     void FSceneRenderer::CreatePerObjectProjectedShadow

Source code excerpt:

		{
			// Round down to the nearest power of two so that resolution changes are always doubling or halving the resolution, which increases filtering stability.
			int32 PreshadowSizeX = 1 << (FMath::CeilLogTwo(FMath::TruncToInt(MaxDesiredResolution * CVarPreShadowResolutionFactor.GetValueOnRenderThread())) - 1);

			const FIntPoint PreshadowCacheResolution = GetPreShadowCacheTextureResolution(FeatureLevel);
			checkSlow(PreshadowSizeX <= PreshadowCacheResolution.X);
			bool bIsOutsideWholeSceneShadow = true;

			for (int32 i = 0; i < ViewDependentWholeSceneShadows.Num(); i++)

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

Scope (from outer to inner):

file
function     void FSceneRenderer::CreatePerObjectProjectedShadow

Source code excerpt:

						true,				// preshadow
						PreshadowSizeX,
						FMath::TruncToInt(MaxShadowResolutionY * CVarPreShadowResolutionFactor.GetValueOnRenderThread()),
						SHADOW_BORDER,
						MaxScreenPercent,
						false				// not translucent shadow
						);
				}