r.Shadow.ShadowMaxSlopeScaleDepthBias

r.Shadow.ShadowMaxSlopeScaleDepthBias

#Overview

name: r.Shadow.ShadowMaxSlopeScaleDepthBias

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.ShadowMaxSlopeScaleDepthBias is to control the maximum slope depth bias used for shadows across all lights in the rendering system. This setting is part of Unreal Engine 5’s shadow rendering subsystem.

The Unreal Engine renderer module relies on this setting variable, specifically in the shadow rendering component. It’s used within the ShadowRendering.cpp file, which is part of the core rendering system.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1.0f but can be modified at runtime through console commands or configuration files.

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

Developers must be aware that this variable affects the quality of self-shadowing in the scene. Higher values can provide better self-shadowing, but they also increase the risk of self-shadowing artifacts. Therefore, careful tuning is necessary to achieve the desired visual quality without introducing noticeable artifacts.

Best practices when using this variable include:

  1. Start with the default value and adjust incrementally.
  2. Test the changes in various lighting conditions and with different types of geometry.
  3. Be mindful of performance implications, as higher values might affect rendering performance.
  4. Document any changes made to this variable in project settings or configuration files for consistency across the development team.

Regarding the associated variable CVarShadowMaxSlopeScaleDepthBias:

The purpose of CVarShadowMaxSlopeScaleDepthBias is identical to r.Shadow.ShadowMaxSlopeScaleDepthBias. It’s an internal representation of the console variable used within the C++ code.

This variable is used directly in the FProjectedShadowInfo::UpdateShaderDepthBias function to set the ShaderMaxSlopeDepthBias value. This function is likely called during the shadow projection and rendering process.

The value of CVarShadowMaxSlopeScaleDepthBias is retrieved using the GetValueOnRenderThread() method, ensuring thread-safe access to the current value.

Developers should be aware that changes to this variable will take effect on the render thread, which means there might be a slight delay before seeing the results in the rendered output.

Best practices for CVarShadowMaxSlopeScaleDepthBias are the same as for r.Shadow.ShadowMaxSlopeScaleDepthBias, as they represent the same setting. However, when accessing this variable in C++ code, always use the GetValueOnRenderThread() method to ensure thread-safety.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarShadowMaxSlopeScaleDepthBias(
	TEXT("r.Shadow.ShadowMaxSlopeScaleDepthBias"),
	1.0f,
	TEXT("Max Slope depth bias used for shadows for all lights\n")
	TEXT("Higher values give better self-shadowing, but increase self-shadowing artifacts"),
	ECVF_RenderThreadSafe);

FForwardScreenSpaceShadowMaskTextureMobileOutputs GScreenSpaceShadowMaskTextureMobileOutputs;

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarShadowMaxSlopeScaleDepthBias(
	TEXT("r.Shadow.ShadowMaxSlopeScaleDepthBias"),
	1.0f,
	TEXT("Max Slope depth bias used for shadows for all lights\n")
	TEXT("Higher values give better self-shadowing, but increase self-shadowing artifacts"),
	ECVF_RenderThreadSafe);

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

Scope (from outer to inner):

file
function     void FProjectedShadowInfo::UpdateShaderDepthBias

Source code excerpt:

	ShaderDepthBias = FMath::Max(DepthBias, 0.0f);
	ShaderSlopeDepthBias = FMath::Max(DepthBias * SlopeScaleDepthBias, 0.0f);
	ShaderMaxSlopeDepthBias = CVarShadowMaxSlopeScaleDepthBias.GetValueOnRenderThread();
}

float FProjectedShadowInfo::ComputeTransitionSize() const
{
	float TransitionSize = 1.0f;