r.Shadow.MaxSoftKernelSize
r.Shadow.MaxSoftKernelSize
#Overview
name: r.Shadow.MaxSoftKernelSize
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Mazimum size of the softening kernels in pixels.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.MaxSoftKernelSize is to control the maximum size of softening kernels for shadow rendering in Unreal Engine 5. It sets an upper limit on the kernel size used for shadow softening effects, which directly impacts the visual quality and performance of soft shadows in the game.
This setting variable is primarily used by the Renderer module, specifically within the shadow rendering subsystem. It’s referenced in the ShadowRendering.cpp and ShadowRendering.h files, which are part of the core rendering pipeline for shadows in Unreal Engine.
The value of this variable is set using a TAutoConsoleVariable, which means it can be adjusted at runtime through the console or configuration files. The default value is set to 40 pixels.
This variable interacts with other shadow-related variables and calculations, particularly those involved in Percentage Closer Soft Shadows (PCSS) techniques. It’s used in conjunction with calculations involving light source angles, shadow bounds, and resolution to determine the appropriate softening effect for shadows.
Developers must be aware that this variable directly affects the trade-off between shadow quality and performance. A larger kernel size can result in softer, more realistic shadows but at the cost of increased computational overhead. Conversely, a smaller kernel size may improve performance but could lead to harder, less natural-looking shadow edges.
Best practices when using this variable include:
- Balancing it with other shadow-related settings to achieve the desired visual quality without overly impacting performance.
- Testing different values across various hardware configurations to ensure consistent performance across target platforms.
- Considering dynamic adjustment of this value based on the scene complexity or distance from the camera to optimize performance.
- Using it in conjunction with other shadow optimization techniques, such as cascaded shadow maps or distance field shadows, for best results.
- Documenting any changes to this value in project settings to maintain consistency across the development team.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:183
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarMaxSoftKernelSize(
TEXT("r.Shadow.MaxSoftKernelSize"),
40,
TEXT("Mazimum size of the softening kernels in pixels."),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarShadowMaxSlopeScaleDepthBias(
TEXT("r.Shadow.ShadowMaxSlopeScaleDepthBias"),
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.h:1704
Scope (from outer to inner):
file
class class TDirectionalPercentageCloserShadowProjectionPS : public TShadowProjectionPS<Quality, bUseFadePlane>
function void SetParameters
Source code excerpt:
float TanLightSourceAngle = FMath::Tan(0.5 * FMath::DegreesToRadians(ShadowInfo->GetLightSceneInfo().Proxy->GetLightSourceAngle()));
static IConsoleVariable* CVarMaxSoftShadowKernelSize = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shadow.MaxSoftKernelSize"));
check(CVarMaxSoftShadowKernelSize);
int32 MaxKernelSize = CVarMaxSoftShadowKernelSize->GetInt();
float SW = 2.0 * ShadowInfo->ShadowBounds.W;
float SZ = ShadowInfo->MaxSubjectZ - ShadowInfo->MinSubjectZ;
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.h:1758
Scope (from outer to inner):
file
class class TSpotPercentageCloserShadowProjectionPS : public TShadowProjectionPS<Quality, bUseFadePlane>
function void SetParameters
Source code excerpt:
TShadowProjectionPS<Quality, bUseFadePlane>::SetParameters(BatchedParameters, ViewIndex, View, ShadowInfo, bUseLightFunctionAtlas);
static IConsoleVariable* CVarMaxSoftShadowKernelSize = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shadow.MaxSoftKernelSize"));
check(CVarMaxSoftShadowKernelSize);
int32 MaxKernelSize = CVarMaxSoftShadowKernelSize->GetInt();
FVector4f PCSSParameterValues = FVector4f(0, MaxKernelSize / float(ShadowInfo->ResolutionX), 0, 0);
SetShaderValue(BatchedParameters, PCSSParameters, PCSSParameterValues);
}