r.Shadow.MaxNumFarShadowCascades
r.Shadow.MaxNumFarShadowCascades
#Overview
name: r.Shadow.MaxNumFarShadowCascades
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Max number of far shadow cascades that can be cast from a directional light
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.MaxNumFarShadowCascades is to control the maximum number of far shadow cascades that can be cast from a directional light in Unreal Engine 5. This setting variable is primarily used for the rendering system, specifically for managing shadow quality and performance in directional lighting.
This setting variable is primarily used in the Engine module, specifically within the DirectionalLightComponent. It’s part of the shadow rendering system for directional lights.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 10, but can be changed at runtime or through configuration files.
The associated variable CVarMaxNumFarShadowCascades interacts directly with r.Shadow.MaxNumFarShadowCascades. They share the same value and are used interchangeably in the code.
Developers must be aware that this variable affects both rendering quality and performance. Increasing the number of far shadow cascades can improve shadow quality at a distance but may impact performance.
Best practices when using this variable include:
- Balancing quality and performance based on the target hardware.
- Considering the game’s visual style and how important distant shadows are to the overall look.
- Testing different values to find the optimal balance for your specific game.
Regarding the associated variable CVarMaxNumFarShadowCascades:
The purpose of CVarMaxNumFarShadowCascades is the same as r.Shadow.MaxNumFarShadowCascades. It’s used internally in the C++ code to access and manipulate the value set by r.Shadow.MaxNumFarShadowCascades.
This variable is used directly in the FDirectionalLightSceneProxy class, which is part of the rendering system for directional lights. It’s used to calculate the number of shadow cascades and split distances for shadow mapping.
The value of CVarMaxNumFarShadowCascades is set automatically when r.Shadow.MaxNumFarShadowCascades is set.
Developers should be aware that changes to r.Shadow.MaxNumFarShadowCascades will directly affect the behavior of code using CVarMaxNumFarShadowCascades.
Best practices for CVarMaxNumFarShadowCascades are the same as for r.Shadow.MaxNumFarShadowCascades, as they represent the same setting. Developers working directly with the C++ code should use CVarMaxNumFarShadowCascades.GetValueOnAnyThread() to access the current value safely from any thread.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/DirectionalLightComponent.cpp:60
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<int32> CVarMaxNumFarShadowCascades(
TEXT("r.Shadow.MaxNumFarShadowCascades"),
10,
TEXT("Max number of far shadow cascades that can be cast from a directional light"),
ECVF_RenderThreadSafe | ECVF_Scalability );
ENGINE_API int32 GFarShadowStaticMeshLODBias = 0;
FAutoConsoleVariableRef CVarFarShadowStaticMeshLODBias(
#Associated Variable and Callsites
This variable is associated with another variable named CVarMaxNumFarShadowCascades
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/DirectionalLightComponent.cpp:59
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe
);
static TAutoConsoleVariable<int32> CVarMaxNumFarShadowCascades(
TEXT("r.Shadow.MaxNumFarShadowCascades"),
10,
TEXT("Max number of far shadow cascades that can be cast from a directional light"),
ECVF_RenderThreadSafe | ECVF_Scalability );
ENGINE_API int32 GFarShadowStaticMeshLODBias = 0;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/DirectionalLightComponent.cpp:460
Scope (from outer to inner):
file
class class FDirectionalLightSceneProxy : public FLightSceneProxy
function virtual uint32 GetNumViewDependentWholeSceneShadows
Source code excerpt:
virtual uint32 GetNumViewDependentWholeSceneShadows(const FSceneView& View, bool bPrecomputedLightingIsValid) const override
{
uint32 ClampedFarShadowCascadeCount = FMath::Min((uint32)CVarMaxNumFarShadowCascades.GetValueOnAnyThread(), FarShadowCascadeCount);
uint32 TotalCascades = GetNumShadowMappedCascades(View.MaxShadowCascades, bPrecomputedLightingIsValid) + ClampedFarShadowCascadeCount;
return TotalCascades;
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/DirectionalLightComponent.cpp:787
Scope (from outer to inner):
file
class class FDirectionalLightSceneProxy : public FLightSceneProxy
function inline float GetSplitDistance
Source code excerpt:
{
// the far cascades start at the after the near cascades
uint32 ClampedFarShadowCascadeCount = FMath::Min((uint32)CVarMaxNumFarShadowCascades.GetValueOnAnyThread(), FarShadowCascadeCount);
return CascadeDistanceWithoutFar + ComputeAccumulatedScale(EffectiveCascadeDistributionExponent, SplitIndex - NumNearCascades, ClampedFarShadowCascadeCount) * ((CVarFarShadowDistanceOverride.GetValueOnAnyThread() > 0.0f ? CVarFarShadowDistanceOverride.GetValueOnAnyThread() : FarShadowDistance) - CascadeDistanceWithoutFar);
}
}
else
{