r.Shadow.PointLightDepthBias

r.Shadow.PointLightDepthBias

#Overview

name: r.Shadow.PointLightDepthBias

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.PointLightDepthBias is to control the depth bias applied in the depth pass for shadows from point lights in Unreal Engine 5’s rendering system. This setting is crucial for managing shadow quality and preventing visual artifacts like peter paning and shadow acne.

This setting variable is primarily used in 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 pipeline.

The value of this variable is set as a console variable with a default value of 0.02f. It can be modified at runtime through the console or configuration files.

The r.Shadow.PointLightDepthBias interacts closely with another variable, r.Shadow.PointLightSlopeScaleDepthBias. These two variables work together to fine-tune shadow rendering for point lights.

Developers must be aware that adjusting this variable affects the trade-off between peter paning (shadows detaching from objects) and shadow acne (incorrect self-shadowing patterns). A value of 0.03 is noted to avoid peter paning but may introduce some shadow acne.

Best practices when using this variable include:

  1. Carefully balancing it with r.Shadow.PointLightSlopeScaleDepthBias for optimal shadow quality.
  2. Testing changes across various lighting scenarios and environments.
  3. Considering performance implications, as adjusting shadow bias can affect rendering performance.

Regarding the associated variable CVarPointLightShadowDepthBias:

This is the internal C++ representation of the r.Shadow.PointLightDepthBias console variable. It’s defined as a TAutoConsoleVariable, which allows it to be easily accessed and modified at runtime.

The purpose of CVarPointLightShadowDepthBias is to provide a programmatic interface to the r.Shadow.PointLightDepthBias setting within the engine’s C++ code.

It’s used in the UpdateShaderDepthBias function of the FProjectedShadowInfo class, where its value is retrieved on the render thread and used to calculate the final depth bias for point light shadows.

Developers working directly with the engine’s C++ code should use CVarPointLightShadowDepthBias.GetValueOnRenderThread() to access the current value of this setting in render thread-safe contexts.

Best practices for using CVarPointLightShadowDepthBias in C++ code include:

  1. Always access it using GetValueOnRenderThread() when in render thread contexts.
  2. Consider caching the value if it’s used frequently in performance-critical sections.
  3. Be aware that changes to this value can affect shadow rendering quality and performance.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

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

static TAutoConsoleVariable<float> CVarPointLightShadowSlopeScaleDepthBias(
	TEXT("r.Shadow.PointLightSlopeScaleDepthBias"),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

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

static TAutoConsoleVariable<float> CVarPointLightShadowSlopeScaleDepthBias(

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

Scope (from outer to inner):

file
function     void FProjectedShadowInfo::UpdateShaderDepthBias

Source code excerpt:

		else
		{
			DeptBiasConstant = CVarPointLightShadowDepthBias.GetValueOnRenderThread();
			SlopeDepthBiasConstant = CVarPointLightShadowSlopeScaleDepthBias.GetValueOnRenderThread();
		}

		DepthBias = DeptBiasConstant * 512.0f / FMath::Max(ResolutionX, ResolutionY);
		// * 2.0f to be compatible with the system we had before ShadowBias
		DepthBias *= 2.0f * LightSceneInfo->Proxy->GetUserShadowBias();