r.Shadow.CSMSlopeScaleDepthBias
r.Shadow.CSMSlopeScaleDepthBias
#Overview
name: r.Shadow.CSMSlopeScaleDepthBias
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Slope scale depth bias used by CSM
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.CSMSlopeScaleDepthBias is to control the slope scale depth bias used by Cascaded Shadow Maps (CSM) in Unreal Engine’s rendering system. This setting is crucial for managing shadow quality and preventing shadow artifacts.
This setting variable is primarily used by the rendering system, specifically in the shadow rendering module of Unreal Engine 5. Based on the callsites, it’s clear that this variable is utilized within the ShadowRendering.cpp file, which is part of the Renderer module.
The value of this variable is set through a console variable (CVarCSMShadowSlopeScaleDepthBias) with a default value of 3.0f. It can be modified at runtime using console commands or through engine configuration files.
The associated variable CVarCSMShadowSlopeScaleDepthBias directly interacts with r.Shadow.CSMSlopeScaleDepthBias. They share the same value and purpose.
Developers must be aware that this variable affects the visual quality of shadows in the game. Adjusting this value can help reduce shadow acne (shadow artifacts) but may also introduce peter-panning (shadows detaching from objects) if set too high.
Best practices when using this variable include:
- Start with the default value (3.0f) and adjust gradually.
- Test the changes in various lighting conditions and with different types of geometry.
- Balance between reducing shadow artifacts and maintaining shadow accuracy.
- Consider adjusting this value in conjunction with other shadow-related settings for optimal results.
Regarding the associated variable CVarCSMShadowSlopeScaleDepthBias:
- Its purpose is identical to r.Shadow.CSMSlopeScaleDepthBias, serving as the C++ representation of the console variable.
- It’s used within the Renderer module, specifically in shadow rendering calculations.
- The value is set when the engine initializes the console variable system.
- It interacts directly with r.Shadow.CSMSlopeScaleDepthBias and is used in shadow rendering calculations, as seen in the UpdateShaderDepthBias function.
- Developers should be aware that modifying this variable programmatically will have the same effect as changing r.Shadow.CSMSlopeScaleDepthBias through console commands.
- Best practices include using this variable for runtime adjustments of shadow bias in response to specific game conditions or player preferences.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:31
Scope: file
Source code excerpt:
static TAutoConsoleVariable<float> CVarCSMShadowSlopeScaleDepthBias(
TEXT("r.Shadow.CSMSlopeScaleDepthBias"),
3.0f,
TEXT("Slope scale depth bias used by CSM"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarPerObjectDirectionalShadowDepthBias(
TEXT("r.Shadow.PerObjectDirectionalDepthBias"),
#Associated Variable and Callsites
This variable is associated with another variable named CVarCSMShadowSlopeScaleDepthBias
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:30
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarCSMShadowSlopeScaleDepthBias(
TEXT("r.Shadow.CSMSlopeScaleDepthBias"),
3.0f,
TEXT("Slope scale depth bias used by CSM"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarPerObjectDirectionalShadowDepthBias(
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:1846
Scope (from outer to inner):
file
function void FProjectedShadowInfo::UpdateShaderDepthBias
Source code excerpt:
DepthBias *= LightSceneInfo->Proxy->GetUserShadowBias();
SlopeScaleDepthBias = CVarCSMShadowSlopeScaleDepthBias.GetValueOnRenderThread();
SlopeScaleDepthBias *= LightSceneInfo->Proxy->GetUserShadowSlopeBias();
}
else if (bPreShadow)
{
// Preshadows don't need a depth bias since there is no self shadowing
DepthBias = 0;