r.Shadow.CSMReceiverBias

r.Shadow.CSMReceiverBias

#Overview

name: r.Shadow.CSMReceiverBias

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.CSMReceiverBias is to control the receiver bias used by Cascaded Shadow Maps (CSM) in the Unreal Engine 5 rendering system. This setting variable is specifically designed for the shadow rendering subsystem.

The Unreal Engine’s rendering module, particularly the shadow rendering component, relies on this setting variable. It is used within the ShadowRendering.cpp file, which is part of the Renderer private implementation.

The value of this variable is set as a console variable with a default value of 0.9f. It can be modified at runtime through console commands or programmatically.

This variable interacts with an associated variable named CVarCSMShadowReceiverBias. They share the same value and are used interchangeably in the code.

Developers must be aware that this variable affects the bias applied to shadow receivers when using Cascaded Shadow Maps. The value should be between 0 and 1, as indicated in the variable’s description. Changing this value can impact the visual quality and performance of shadow rendering in the engine.

Best practices when using this variable include:

  1. Carefully adjusting the value to balance between shadow quality and performance.
  2. Testing the impact of different values in various lighting scenarios.
  3. Considering the interaction with other shadow-related settings.
  4. Using the console variable for quick iterations during development.

Regarding the associated variable CVarCSMShadowReceiverBias:

The purpose of CVarCSMShadowReceiverBias is the same as r.Shadow.CSMReceiverBias, serving as the actual console variable implementation for controlling the CSM receiver bias.

This variable is used directly in the GetShaderReceiverDepthBias function of the FProjectedShadowInfo class to determine the shadow receiver bias for directional lights.

The value of CVarCSMShadowReceiverBias is set through the console variable system and can be accessed using the GetValueOnRenderThread() method.

Developers should be aware that this variable is accessed on the render thread, which is important for thread-safety considerations.

Best practices for CVarCSMShadowReceiverBias include:

  1. Accessing the value using GetValueOnRenderThread() when needed in render thread operations.
  2. Considering the performance impact of frequently querying this value.
  3. Using this variable in conjunction with other light-type specific shadow receiver bias variables for a consistent shadow rendering approach across different light types.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarCSMShadowReceiverBias(
	TEXT("r.Shadow.CSMReceiverBias"),
	0.9f,
	TEXT("Receiver bias used by CSM. Value between 0 and 1."),
	ECVF_RenderThreadSafe);


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

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarCSMShadowReceiverBias(
	TEXT("r.Shadow.CSMReceiverBias"),
	0.9f,
	TEXT("Receiver bias used by CSM. Value between 0 and 1."),
	ECVF_RenderThreadSafe);

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

Scope (from outer to inner):

file
function     float FProjectedShadowInfo::GetShaderReceiverDepthBias

Source code excerpt:

		switch (GetLightSceneInfo().Proxy->GetLightType())
		{
		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;
		}
	}