r.Shadow.SpotLightTransitionScale
r.Shadow.SpotLightTransitionScale
#Overview
name: r.Shadow.SpotLightTransitionScale
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Transition scale for spotlights
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.SpotLightTransitionScale is to control the transition scale for spotlight shadows in the Unreal Engine 5 rendering system. This variable is specifically used for managing the soft transition between shadowed and non-shadowed areas cast by spotlights.
This setting variable is primarily used in the Renderer module of Unreal Engine 5, specifically within the shadow rendering subsystem. The code references are found in the ShadowRendering.cpp file, which is part of the core rendering functionality.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 60.0f, but can be changed at runtime through console commands or programmatically.
The r.Shadow.SpotLightTransitionScale variable interacts closely with its associated variable CVarSpotLightShadowTransitionScale. They share the same value and are used interchangeably in the code.
Developers should be aware that this variable directly affects the visual quality and performance of spotlight shadows. A higher value will result in a sharper transition between shadowed and non-shadowed areas, while a lower value will create a softer, more gradual transition.
Best practices when using this variable include:
- Adjusting it carefully to balance between visual quality and performance.
- Testing different values in various lighting scenarios to find the optimal setting for your specific game or application.
- Considering the interaction with other shadow-related variables, such as the user shadow bias.
Regarding the associated variable CVarSpotLightShadowTransitionScale:
The purpose of CVarSpotLightShadowTransitionScale is identical to r.Shadow.SpotLightTransitionScale. It’s an implementation detail that allows the engine to access the same value through the CVar system.
This variable is used in the ComputeTransitionSize() function of the FProjectedShadowInfo class. It’s specifically used for non-directional lights (i.e., spotlights) to calculate the transition size for shadow rendering.
The value is accessed using the GetValueOnRenderThread() method, ensuring thread-safe access in the render thread.
Developers should be aware that modifying CVarSpotLightShadowTransitionScale will have the same effect as modifying r.Shadow.SpotLightTransitionScale. They should treat these variables as one and the same when considering shadow quality and performance optimizations.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:137
Scope: file
Source code excerpt:
static TAutoConsoleVariable<float> CVarSpotLightShadowTransitionScale(
TEXT("r.Shadow.SpotLightTransitionScale"),
60.0f,
TEXT("Transition scale for spotlights"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarSpotLightShadowReceiverBias(
TEXT("r.Shadow.SpotLightReceiverBias"),
#Associated Variable and Callsites
This variable is associated with another variable named CVarSpotLightShadowTransitionScale
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:136
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarSpotLightShadowTransitionScale(
TEXT("r.Shadow.SpotLightTransitionScale"),
60.0f,
TEXT("Transition scale for spotlights"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarSpotLightShadowReceiverBias(
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:1917
Scope (from outer to inner):
file
function float FProjectedShadowInfo::ComputeTransitionSize
Source code excerpt:
{
// todo: optimize
TransitionSize = bDirectionalLight ? (1.0f / CVarShadowTransitionScale.GetValueOnRenderThread()) : (1.0f / CVarSpotLightShadowTransitionScale.GetValueOnRenderThread());
// * 2.0f to be compatible with the system we had before ShadowBias
TransitionSize *= 2.0f * LightSceneInfo->Proxy->GetUserShadowBias();
}
else if (IsWholeSceneDirectionalShadow())
{
check(CascadeSettings.ShadowSplitIndex >= 0);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:1944
Scope (from outer to inner):
file
function float FProjectedShadowInfo::ComputeTransitionSize
Source code excerpt:
{
// todo: optimize
TransitionSize = bDirectionalLight ? (1.0f / CVarShadowTransitionScale.GetValueOnRenderThread()) : (1.0f / CVarSpotLightShadowTransitionScale.GetValueOnRenderThread());
// * 2.0f to be compatible with the system we had before ShadowBias
TransitionSize *= 2.0f * LightSceneInfo->Proxy->GetUserShadowBias();
}
// Make sure that shadow soft transition size is greater than zero so 1/TransitionSize shader parameter won't be INF.
const float MinTransitionSize = 0.00001f;