r.Shadow.PerObjectDirectionalDepthBias

r.Shadow.PerObjectDirectionalDepthBias

#Overview

name: r.Shadow.PerObjectDirectionalDepthBias

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.PerObjectDirectionalDepthBias is to control the constant depth bias used for per-object shadows from directional lights in Unreal Engine’s rendering system. This setting variable is crucial for fine-tuning shadow rendering quality and performance.

This setting variable is primarily used by the Renderer module of Unreal Engine, specifically in the shadow rendering subsystem. Based on the callsites, it’s evident that this variable is utilized in the ShadowRendering.cpp file, which is responsible for handling various aspects of shadow rendering.

The value of this variable is set through the console variable system (CVarPerObjectDirectionalShadowDepthBias). It has a default value of 10.0f, but can be adjusted at runtime or through configuration files.

The associated variable CVarPerObjectDirectionalShadowDepthBias directly interacts with r.Shadow.PerObjectDirectionalDepthBias. They share the same value and purpose.

Developers must be aware of the following when using this variable:

  1. Lower values provide better shadow contact but can increase self-shadowing artifacts.
  2. The value is used in calculations that affect the depth bias of directional light shadows, which can impact both visual quality and performance.
  3. Changes to this value will affect all per-object shadows from directional lights in the scene.

Best practices when using this variable include:

  1. Fine-tune the value based on the specific needs of your scene and the desired balance between shadow quality and performance.
  2. Test different values in various lighting conditions to ensure optimal results across different scenarios.
  3. Consider the relationship between this variable and other shadow-related settings for a holistic approach to shadow quality.
  4. Document any custom values used in your project for consistency and easier troubleshooting.

Regarding the associated variable CVarPerObjectDirectionalShadowDepthBias:

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarPerObjectDirectionalShadowDepthBias(
	TEXT("r.Shadow.PerObjectDirectionalDepthBias"),
	10.0f,
	TEXT("Constant depth bias used by per-object shadows from directional lights\n")
	TEXT("Lower values give better shadow contact, but increase self-shadowing artifacts"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarPerObjectDirectionalShadowSlopeScaleDepthBias(

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarPerObjectDirectionalShadowDepthBias(
	TEXT("r.Shadow.PerObjectDirectionalDepthBias"),
	10.0f,
	TEXT("Constant depth bias used by per-object shadows from directional lights\n")
	TEXT("Lower values give better shadow contact, but increase self-shadowing artifacts"),
	ECVF_RenderThreadSafe);

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

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 = CVarPerObjectDirectionalShadowDepthBias.GetValueOnRenderThread() / (MaxSubjectZ - MinSubjectZ);

			float WorldSpaceTexelScale = ShadowBounds.W / FMath::Max(ResolutionX, ResolutionY);
		
			DepthBias *= WorldSpaceTexelScale;
			DepthBias *= 0.5f;	// avg GetUserShadowBias, in that case we don't want this adjustable