r.Shadow.PerObjectSpotLightSlopeDepthBias
r.Shadow.PerObjectSpotLightSlopeDepthBias
#Overview
name: r.Shadow.PerObjectSpotLightSlopeDepthBias
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Slope scale depth bias that is applied in the depth pass for per-object projected shadows from spot lights
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.PerObjectSpotLightSlopeDepthBias is to control the slope scale depth bias applied in the depth pass for per-object projected shadows from spot lights in Unreal Engine 5’s rendering system.
This setting variable is primarily used by the Renderer module of Unreal Engine 5, specifically in the shadow rendering subsystem. It’s referenced in the ShadowRendering.cpp file, which is part of the core rendering implementation.
The value of this variable is set as a console variable with a default value of 3.0f. It can be modified at runtime through the console or configuration files.
This variable interacts closely with its associated variable CVarPerObjectSpotLightShadowSlopeScaleDepthBias. They share the same value and purpose, with CVarPerObjectSpotLightShadowSlopeScaleDepthBias being the actual TAutoConsoleVariable instance used in the code.
Developers must be aware that this variable directly affects the quality and appearance of shadows cast by spot lights in the scene. Adjusting this value can help reduce shadow acne (self-shadowing artifacts) but may also introduce peter-panning (shadows detaching from objects) if set too high.
Best practices when using this variable include:
- Fine-tuning the value based on the specific needs of the scene and the distance of objects from spot lights.
- Testing different values in various lighting scenarios to find the optimal balance between shadow quality and performance.
- Considering the interaction with other shadow-related settings, such as the user shadow bias set on light actors.
Regarding the associated variable CVarPerObjectSpotLightShadowSlopeScaleDepthBias:
The purpose of CVarPerObjectSpotLightShadowSlopeScaleDepthBias is identical to r.Shadow.PerObjectSpotLightSlopeDepthBias, as they represent the same setting.
It is used in the UpdateShaderDepthBias function of the FProjectedShadowInfo class, which is part of the shadow rendering pipeline. This function is responsible for calculating the appropriate depth bias for shadow rendering.
The value of this variable is set and accessed using the GetValueOnRenderThread() method, ensuring thread-safe access in the render thread.
This variable interacts with the light’s user shadow slope bias, as seen in the code where its value is multiplied by LightSceneInfo->Proxy->GetUserShadowSlopeBias().
Developers should be aware that changes to this variable will affect all per-object spot light shadows in the scene. It’s a global setting that can have a significant impact on shadow quality and performance.
Best practices for using CVarPerObjectSpotLightShadowSlopeScaleDepthBias include:
- Coordinating its value with other shadow-related settings for consistent shadow quality across different light types.
- Profiling the performance impact of different values, especially in scenes with many spot lights.
- Documenting any custom values used in production to ensure 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:131
Scope: file
Source code excerpt:
static TAutoConsoleVariable<float> CVarPerObjectSpotLightShadowSlopeScaleDepthBias(
TEXT("r.Shadow.PerObjectSpotLightSlopeDepthBias"),
3.0f,
TEXT("Slope scale depth bias that is applied in the depth pass for per-object projected shadows from spot lights"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarSpotLightShadowTransitionScale(
TEXT("r.Shadow.SpotLightTransitionScale"),
#Associated Variable and Callsites
This variable is associated with another variable named CVarPerObjectSpotLightShadowSlopeScaleDepthBias
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:130
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarPerObjectSpotLightShadowSlopeScaleDepthBias(
TEXT("r.Shadow.PerObjectSpotLightSlopeDepthBias"),
3.0f,
TEXT("Slope scale depth bias that is applied in the depth pass for per-object projected shadows from spot lights"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarSpotLightShadowTransitionScale(
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:1885
Scope (from outer to inner):
file
function void FProjectedShadowInfo::UpdateShaderDepthBias
Source code excerpt:
DepthBias *= 2.0f * LightSceneInfo->Proxy->GetUserShadowBias();
SlopeScaleDepthBias = CVarPerObjectSpotLightShadowSlopeScaleDepthBias.GetValueOnRenderThread();
SlopeScaleDepthBias *= LightSceneInfo->Proxy->GetUserShadowSlopeBias();
}
else
{
// spot lights (old code, might need to be improved)
const float LightTypeDepthBias = CVarSpotLightShadowDepthBias.GetValueOnRenderThread();