r.Shadow.SpotLightReceiverBias

r.Shadow.SpotLightReceiverBias

#Overview

name: r.Shadow.SpotLightReceiverBias

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.SpotLightReceiverBias is to control the receiver bias used by spotlights in the shadow rendering system. This setting variable is part of Unreal Engine 5’s rendering system, specifically the shadow rendering subsystem.

The Unreal Engine subsystem that relies on this setting variable is the Renderer module, as evidenced by its location in the ShadowRendering.cpp file within the Runtime/Renderer/Private directory.

The value of this variable is set through a console variable (CVar) system. It is initialized with a default value of 0.5f and can be changed at runtime. The variable is defined as render thread safe, meaning it can be safely accessed and modified from the render thread.

This variable interacts with other shadow receiver bias variables for different light types, such as directional lights (CSMShadowReceiverBias) and rect lights (RectLightShadowReceiverBias). It is specifically used for spotlight shadows.

Developers must be aware that:

  1. The value should be between 0 and 1, as stated in the variable’s description.
  2. This bias affects the appearance of shadows cast by spotlights, potentially reducing shadow acne or other artifacts.
  3. Changes to this value will affect the rendering performance and visual quality of spotlight shadows.

Best practices when using this variable include:

  1. Fine-tuning the value based on the specific needs of the scene and the desired shadow quality.
  2. Testing different values to find the optimal balance between shadow quality and performance.
  3. Considering the interaction with other shadow-related settings for a cohesive shadow rendering result.

Regarding the associated variable CVarSpotLightShadowReceiverBias:

This is the actual console variable that stores and provides access to the r.Shadow.SpotLightReceiverBias value. It is used to retrieve the current value of the spotlight shadow receiver bias in the rendering code, specifically in the GetShaderReceiverDepthBias function of the FProjectedShadowInfo class.

The purpose of CVarSpotLightShadowReceiverBias is to provide a thread-safe way to access and modify the spotlight shadow receiver bias value at runtime. It allows for easy adjustment of the bias through console commands or game code without recompiling the engine.

Developers should be aware that:

  1. This variable is accessed using GetValueOnRenderThread(), ensuring thread-safe access in rendering code.
  2. Changes to this variable will immediately affect the shadow rendering for spotlights.

Best practices for using CVarSpotLightShadowReceiverBias include:

  1. Using it to dynamically adjust shadow bias based on scene conditions or performance requirements.
  2. Implementing user-facing controls that modify this value for real-time adjustments during development or as part of graphics settings.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarSpotLightShadowReceiverBias(
	TEXT("r.Shadow.SpotLightReceiverBias"),
	0.5f,
	TEXT("Receiver bias used by spotlights. Value between 0 and 1."),
	ECVF_RenderThreadSafe);


///////////////////////////////////////////////////////////////////////////////////////////////////

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarSpotLightShadowReceiverBias(
	TEXT("r.Shadow.SpotLightReceiverBias"),
	0.5f,
	TEXT("Receiver bias used by spotlights. Value between 0 and 1."),
	ECVF_RenderThreadSafe);

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

Scope (from outer to inner):

file
function     float FProjectedShadowInfo::GetShaderReceiverDepthBias

Source code excerpt:

		case LightType_Directional	: ShadowReceiverBias = CVarCSMShadowReceiverBias.GetValueOnRenderThread(); break;
		case LightType_Rect			: ShadowReceiverBias = CVarRectLightShadowReceiverBias.GetValueOnRenderThread(); break;
		case LightType_Spot			: ShadowReceiverBias = CVarSpotLightShadowReceiverBias.GetValueOnRenderThread(); break;
		case LightType_Point		: ShadowReceiverBias = GetShaderSlopeDepthBias(); break;
		}
	}

	// Return the min lerp value for depth biasing
	// 0 : max bias when NoL == 0