r.Shadow.SpotLightSlopeDepthBias

r.Shadow.SpotLightSlopeDepthBias

#Overview

name: r.Shadow.SpotLightSlopeDepthBias

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.SpotLightSlopeDepthBias is to control the slope scale depth bias applied in the depth pass for whole-scene projected shadows from spot lights in Unreal Engine’s rendering system.

This setting variable is primarily used by the rendering subsystem, specifically in the shadow rendering module. It’s part of the shadow rendering pipeline for spot lights.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 3.0f, but can be changed at runtime through console commands or programmatically.

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

Developers must be aware that this variable affects the quality and appearance of shadows cast by spot lights. Adjusting this value can help reduce shadow acne (self-shadowing artifacts) but may also introduce peter-panning (shadows detaching from objects) if set too high.

Best practices when using this variable include:

  1. Fine-tuning the value based on the specific needs of your scene and lighting setup.
  2. Testing different values to find the optimal balance between reducing shadow artifacts and maintaining shadow accuracy.
  3. Considering the performance impact, as higher values may require more processing.

Regarding the associated variable CVarSpotLightShadowSlopeScaleDepthBias:

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarSpotLightShadowSlopeScaleDepthBias(
	TEXT("r.Shadow.SpotLightSlopeDepthBias"),
	3.0f,
	TEXT("Slope scale depth bias that is applied in the depth pass for whole-scene projected shadows from spot lights"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarPerObjectSpotLightShadowDepthBias(
	TEXT("r.Shadow.PerObjectSpotLightDepthBias"),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarSpotLightShadowSlopeScaleDepthBias(
	TEXT("r.Shadow.SpotLightSlopeDepthBias"),
	3.0f,
	TEXT("Slope scale depth bias that is applied in the depth pass for whole-scene projected shadows from spot lights"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarPerObjectSpotLightShadowDepthBias(

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

Scope (from outer to inner):

file
function     void FProjectedShadowInfo::UpdateShaderDepthBias

Source code excerpt:

			DepthBias *= 2.0f * LightSceneInfo->Proxy->GetUserShadowBias();

			SlopeScaleDepthBias = CVarSpotLightShadowSlopeScaleDepthBias.GetValueOnRenderThread();
			SlopeScaleDepthBias *= LightSceneInfo->Proxy->GetUserShadowSlopeBias();
		}
		}

		// Prevent a large depth bias due to low resolution from causing near plane clipping
		DepthBias = FMath::Min(DepthBias, .1f);