r.Shadow.PreShadowFadeResolution
r.Shadow.PreShadowFadeResolution
#Overview
name: r.Shadow.PreShadowFadeResolution
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Resolution in texels below which preshadows are faded out
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.PreShadowFadeResolution is to control the resolution threshold at which preshadows are faded out in Unreal Engine 5’s rendering system. This setting is part of the shadow rendering subsystem and affects the visual quality and performance of pre-computed shadows.
This setting variable is primarily used in the Renderer module of Unreal Engine 5, specifically in the shadow setup and rendering process. It’s referenced in the ShadowSetup.cpp file, which is responsible for managing shadow calculations and rendering.
The value of this variable is set through the console variable system. It’s initialized with a default value of 16 texels in the ShadowSetup.cpp file. However, it can be overridden in the SystemSettings.cpp file, where it’s set to 1 in certain conditions to disable preshadow fading out over distance.
The r.Shadow.PreShadowFadeResolution variable interacts closely with other shadow-related variables, such as r.Shadow.FadeResolution and r.Shadow.MinPreShadowResolution. These variables work together to control various aspects of shadow rendering and fading behavior.
Developers must be aware that this variable directly impacts the visual quality and performance of preshadows in the game. A lower value will result in preshadows fading out at lower resolutions, which can improve performance but may reduce shadow quality at a distance.
Best practices when using this variable include:
- Balancing it with other shadow-related settings for optimal visual quality and performance.
- Testing different values in various game scenarios to find the best trade-off between shadow quality and performance.
- Considering platform-specific adjustments, as shadow performance can vary significantly between different hardware.
The associated variable CVarPreShadowFadeResolution is the actual console variable object that stores and manages the r.Shadow.PreShadowFadeResolution setting. It’s defined as a static TAutoConsoleVariable
This variable is used directly in the CreatePerObjectProjectedShadow function of the FSceneRenderer class. Here, it’s retrieved using GetValueOnRenderThread() to determine the preshadow fade resolution for the current frame.
When working with CVarPreShadowFadeResolution, developers should:
- Access its value using the GetValueOnRenderThread() method when in render thread context.
- Be aware that changes to this variable will affect all preshadows in the scene.
- Consider exposing this setting to artists or implementing dynamic adjustment based on performance metrics if needed.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:229
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarPreShadowFadeResolution(
TEXT("r.Shadow.PreShadowFadeResolution"),
16,
TEXT("Resolution in texels below which preshadows are faded out"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarShadowFadeResolution(
TEXT("r.Shadow.FadeResolution"),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SystemSettings.cpp:299
Scope (from outer to inner):
file
function void FSystemSettings::ApplyOverrides
Source code excerpt:
// Disable preshadow fading out over distance
{
static auto CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shadow.PreShadowFadeResolution"));
CVar->Set(1, SetBy);
}
// Increase shadow texel density
{
static auto CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shadow.TexelsPerPixel"));
#Associated Variable and Callsites
This variable is associated with another variable named CVarPreShadowFadeResolution
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:228
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarPreShadowFadeResolution(
TEXT("r.Shadow.PreShadowFadeResolution"),
16,
TEXT("Resolution in texels below which preshadows are faded out"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarShadowFadeResolution(
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:3318
Scope (from outer to inner):
file
function void FSceneRenderer::CreatePerObjectProjectedShadow
Source code excerpt:
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;
TArray<float, TInlineAllocator<2> > ResolutionPreShadowFadeAlphas;