r.Shadow.CSMSlopeScaleDepthBias

r.Shadow.CSMSlopeScaleDepthBias

#Overview

name: r.Shadow.CSMSlopeScaleDepthBias

This variable is created as a Console Variable (cvar).

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:

  1. Start with the default value (3.0f) and adjust gradually.
  2. Test the changes in various lighting conditions and with different types of geometry.
  3. Balance between reducing shadow artifacts and maintaining shadow accuracy.
  4. Consider adjusting this value in conjunction with other shadow-related settings for optimal results.

Regarding the associated variable CVarCSMShadowSlopeScaleDepthBias:

#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;