r.Shadow.PerObjectDirectionalSlopeDepthBias
r.Shadow.PerObjectDirectionalSlopeDepthBias
#Overview
name: r.Shadow.PerObjectDirectionalSlopeDepthBias
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Slope scale depth bias used by per-object shadows from directional lights\nLower values give better shadow contact, but increase self-shadowing artifacts
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.PerObjectDirectionalSlopeDepthBias is to control the slope scale depth bias used for per-object shadows cast by directional lights in Unreal Engine’s rendering system. This setting helps to improve the visual quality of shadows by reducing self-shadowing artifacts while maintaining good shadow contact.
This setting variable is primarily used in the Renderer module of Unreal Engine, specifically within the shadow rendering subsystem. It’s referenced in the ShadowRendering.cpp file, which is responsible for handling various aspects of shadow rendering.
The value of this variable is set using a console variable (CVar) system. It’s initialized with a default value of 3.0f, but can be adjusted at runtime through console commands or project settings.
The associated variable CVarPerObjectDirectionalShadowSlopeScaleDepthBias directly interacts with r.Shadow.PerObjectDirectionalSlopeDepthBias. They share the same value and purpose.
Developers should be aware that adjusting this variable involves a trade-off between shadow contact quality and self-shadowing artifacts. Lower values will provide better shadow contact but may increase self-shadowing artifacts, while higher values will reduce artifacts but may result in less precise shadow edges.
Best practices when using this variable include:
- Fine-tuning the value based on the specific needs of your scene and lighting setup.
- Testing different values to find the optimal balance between shadow quality and performance.
- Considering the impact on different types of objects and materials in your scene.
- Using this in conjunction with other shadow-related settings for best results.
Regarding the associated variable CVarPerObjectDirectionalShadowSlopeScaleDepthBias:
- Its purpose is identical to r.Shadow.PerObjectDirectionalSlopeDepthBias, as they share the same value.
- It’s used directly in the UpdateShaderDepthBias function of the FProjectedShadowInfo class, which is part of the shadow rendering process.
- The value is retrieved on the render thread using GetValueOnRenderThread() method, ensuring thread-safe access.
- It’s multiplied by the user shadow slope bias set for the light, allowing for further customization per light source.
- Developers should be aware that this variable affects only directional lights and is not applied to spot lights or point lights.
- Best practices include considering the interaction between this global setting and per-light shadow bias settings for fine-tuned control over shadow appearance.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:44
Scope: file
Source code excerpt:
static TAutoConsoleVariable<float> CVarPerObjectDirectionalShadowSlopeScaleDepthBias(
TEXT("r.Shadow.PerObjectDirectionalSlopeDepthBias"),
3.0f,
TEXT("Slope scale depth bias used by per-object shadows from directional lights\n")
TEXT("Lower values give better shadow contact, but increase self-shadowing artifacts"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarCSMSplitPenumbraScale(
#Associated Variable and Callsites
This variable is associated with another variable named CVarPerObjectDirectionalShadowSlopeScaleDepthBias
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:43
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarPerObjectDirectionalShadowSlopeScaleDepthBias(
TEXT("r.Shadow.PerObjectDirectionalSlopeDepthBias"),
3.0f,
TEXT("Slope scale depth bias used by per-object shadows from directional lights\n")
TEXT("Lower values give better shadow contact, but increase self-shadowing artifacts"),
ECVF_RenderThreadSafe);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:1870
Scope (from outer to inner):
file
function void FProjectedShadowInfo::UpdateShaderDepthBias
Source code excerpt:
DepthBias *= 0.5f; // avg GetUserShadowBias, in that case we don't want this adjustable
SlopeScaleDepthBias = CVarPerObjectDirectionalShadowSlopeScaleDepthBias.GetValueOnRenderThread();
SlopeScaleDepthBias *= LightSceneInfo->Proxy->GetUserShadowSlopeBias();
}
else // Only spot-lights left (both whole-scene and per-object), as point-lights dont have per-object shadowing
{
ensure(!bDirectionalLight);
ensure(!bOnePassPointLightShadow);