r.Shadow.CSMDepthBias
r.Shadow.CSMDepthBias
#Overview
name: r.Shadow.CSMDepthBias
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Constant depth bias used by CSM
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.CSMDepthBias is to control the constant depth bias used by Cascaded Shadow Maps (CSM) in Unreal Engine 5’s rendering system. This setting variable is crucial for managing shadow rendering quality and preventing shadow acne artifacts.
This setting variable is primarily used in the Renderer module of Unreal Engine 5, 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 through a console variable (CVarCSMShadowDepthBias) with a default value of 10.0f. It can be modified at runtime through console commands or programmatically.
The r.Shadow.CSMDepthBias interacts closely with another variable called CVarCSMShadowSlopeScaleDepthBias, which controls the slope-scale depth bias for CSM shadows. Together, these variables work to fine-tune shadow rendering quality.
Developers should be aware that this variable directly affects the visual quality of shadows in the game. Adjusting it 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 it in conjunction with r.Shadow.CSMSlopeScaleDepthBias for optimal results.
- Testing shadow quality across various lighting conditions and environments.
- Considering performance implications, as higher values may impact rendering performance.
Regarding the associated variable CVarCSMShadowDepthBias:
The purpose of CVarCSMShadowDepthBias is to provide a programmatic interface to control the r.Shadow.CSMDepthBias setting within the engine’s C++ code.
This variable is used within the Renderer module, specifically in the shadow rendering system. It’s defined and used in the ShadowRendering.cpp file.
The value of CVarCSMShadowDepthBias is set when the engine initializes the console variable system, with a default value of 10.0f.
CVarCSMShadowDepthBias interacts directly with the r.Shadow.CSMDepthBias setting, effectively serving as its C++ representation within the engine code.
Developers should be aware that modifying CVarCSMShadowDepthBias in code will have the same effect as changing r.Shadow.CSMDepthBias through console commands or configuration files.
Best practices for using CVarCSMShadowDepthBias include:
- Accessing its value using GetValueOnRenderThread() when used in render thread operations.
- Considering thread safety when modifying or reading this value, as it’s marked with ECVF_RenderThreadSafe.
- Using it in conjunction with other shadow-related variables for comprehensive shadow quality control.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:25
Scope: file
Source code excerpt:
// Directional light
static TAutoConsoleVariable<float> CVarCSMShadowDepthBias(
TEXT("r.Shadow.CSMDepthBias"),
10.0f,
TEXT("Constant depth bias used by CSM"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarCSMShadowSlopeScaleDepthBias(
TEXT("r.Shadow.CSMSlopeScaleDepthBias"),
#Associated Variable and Callsites
This variable is associated with another variable named CVarCSMShadowDepthBias
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:24
Scope: file
Source code excerpt:
///////////////////////////////////////////////////////////////////////////////////////////////////
// Directional light
static TAutoConsoleVariable<float> CVarCSMShadowDepthBias(
TEXT("r.Shadow.CSMDepthBias"),
10.0f,
TEXT("Constant depth bias used by CSM"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarCSMShadowSlopeScaleDepthBias(
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:1841
Scope (from outer to inner):
file
function void FProjectedShadowInfo::UpdateShaderDepthBias
Source code excerpt:
// the z range is adjusted to we need to adjust here as well
DepthBias = CVarCSMShadowDepthBias.GetValueOnRenderThread() / (MaxSubjectZ - MinSubjectZ);
const float WorldSpaceTexelScale = ShadowBounds.W / ResolutionX;
DepthBias = FMath::Lerp(DepthBias, DepthBias * WorldSpaceTexelScale, CascadeSettings.CascadeBiasDistribution);
DepthBias *= LightSceneInfo->Proxy->GetUserShadowBias();
SlopeScaleDepthBias = CVarCSMShadowSlopeScaleDepthBias.GetValueOnRenderThread();
SlopeScaleDepthBias *= LightSceneInfo->Proxy->GetUserShadowSlopeBias();
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:1929
Scope (from outer to inner):
file
function float FProjectedShadowInfo::ComputeTransitionSize
Source code excerpt:
// the z range is adjusted to we need to adjust here as well
TransitionSize = CVarCSMShadowDepthBias.GetValueOnRenderThread() / (MaxSubjectZ - MinSubjectZ);
float WorldSpaceTexelScale = ShadowBounds.W / ResolutionX;
TransitionSize *= WorldSpaceTexelScale;
TransitionSize *= LightSceneInfo->Proxy->GetUserShadowBias();
}