r.Shadow.RectLightDepthBias

r.Shadow.RectLightDepthBias

#Overview

name: r.Shadow.RectLightDepthBias

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.RectLightDepthBias is to control the depth bias applied in the depth pass for shadows from rectangular lights in Unreal Engine’s rendering system. This setting helps to mitigate shadow artifacts such as peter paning and shadow acne.

This setting variable is primarily used by the Renderer module of Unreal Engine, specifically in the shadow rendering subsystem. It’s referenced in the ShadowRendering.cpp file, which is part of the core rendering code.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0.025f, but can be adjusted at runtime using console commands or through project settings.

The r.Shadow.RectLightDepthBias interacts closely with another variable, r.Shadow.RectLightSlopeScaleDepthBias. These two variables work together to fine-tune the shadow rendering for rectangular lights.

Developers should be aware that adjusting this variable can have a significant impact on the visual quality of shadows from rectangular lights. A value that’s too low might result in peter paning (shadows detaching from objects), while a value that’s too high might cause shadow acne (small dark artifacts on shadowed surfaces).

Best practices when using this variable include:

  1. Start with the default value (0.025f) and make small adjustments.
  2. Test the changes in various lighting scenarios to ensure a good balance between peter paning and shadow acne.
  3. Consider the relationship with r.Shadow.RectLightSlopeScaleDepthBias when making adjustments.

Regarding the associated variable CVarRectLightShadowDepthBias:

This is the actual C++ variable that stores the value of r.Shadow.RectLightDepthBias. It’s defined as a TAutoConsoleVariable, which is Unreal Engine’s way of exposing settings to the console and config files.

The purpose of CVarRectLightShadowDepthBias is to provide programmatic access to the r.Shadow.RectLightDepthBias setting within the C++ code.

This variable is used in the Renderer module, specifically in the UpdateShaderDepthBias function of the FProjectedShadowInfo class. Here, it’s used to set the depth bias for rectangular light shadows.

The value of CVarRectLightShadowDepthBias is set when the r.Shadow.RectLightDepthBias console variable is changed, either through console commands or config files.

Developers should be aware that this variable is accessed using the GetValueOnRenderThread() method, which suggests it should only be read from the render thread for thread safety.

Best practices for using CVarRectLightShadowDepthBias include:

  1. Always access it using GetValueOnRenderThread() when in render thread code.
  2. Avoid directly modifying this variable; instead, change the r.Shadow.RectLightDepthBias console variable.
  3. Be cautious when caching its value, as it can be changed at runtime.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:93

Scope: file

Source code excerpt:

// Rect light
static TAutoConsoleVariable<float> CVarRectLightShadowDepthBias(
	TEXT("r.Shadow.RectLightDepthBias"),
	0.025f,
	TEXT("Depth bias that is applied in the depth pass for shadows from rect lights. (0.03 avoids peter paning but has some shadow acne)"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarRectLightShadowSlopeScaleDepthBias(
	TEXT("r.Shadow.RectLightSlopeScaleDepthBias"),

#Associated Variable and Callsites

This variable is associated with another variable named CVarRectLightShadowDepthBias. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:92

Scope: file

Source code excerpt:

///////////////////////////////////////////////////////////////////////////////////////////////////
// Rect light
static TAutoConsoleVariable<float> CVarRectLightShadowDepthBias(
	TEXT("r.Shadow.RectLightDepthBias"),
	0.025f,
	TEXT("Depth bias that is applied in the depth pass for shadows from rect lights. (0.03 avoids peter paning but has some shadow acne)"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarRectLightShadowSlopeScaleDepthBias(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:1820

Scope (from outer to inner):

file
function     void FProjectedShadowInfo::UpdateShaderDepthBias

Source code excerpt:

		if (bIsRectLight)
		{
			DeptBiasConstant = CVarRectLightShadowDepthBias.GetValueOnRenderThread();
			SlopeDepthBiasConstant = CVarRectLightShadowSlopeScaleDepthBias.GetValueOnRenderThread();
		}
		else
		{
			DeptBiasConstant = CVarPointLightShadowDepthBias.GetValueOnRenderThread();
			SlopeDepthBiasConstant = CVarPointLightShadowSlopeScaleDepthBias.GetValueOnRenderThread();