r.Shadow.FadeExponent

r.Shadow.FadeExponent

#Overview

name: r.Shadow.FadeExponent

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.FadeExponent is to control the rate at which shadows are faded out in the rendering system of Unreal Engine 5. This setting variable is primarily used in the shadow rendering subsystem.

The Unreal Engine subsystem that relies on this setting variable is the Renderer module, specifically the shadow setup and rendering components. This can be seen from the file location “Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp”.

The value of this variable is set as a console variable with a default value of 0.25f. It can be modified at runtime through the console or configuration files.

This variable interacts with another variable named CVarShadowFadeExponent, which is the actual TAutoConsoleVariable instance that stores and manages the value of r.Shadow.FadeExponent.

Developers must be aware that this variable affects the visual quality and performance of shadow rendering. A higher value will cause shadows to fade out more quickly, while a lower value will make the transition more gradual. This can impact both the visual fidelity of the shadows and the performance of the rendering system.

Best practices when using this variable include:

  1. Fine-tuning the value to achieve the desired balance between visual quality and performance.
  2. Testing the effects of different values in various lighting scenarios to ensure consistent shadow quality across the game.
  3. Considering the target hardware capabilities when setting this value, as it can affect rendering performance.

Regarding the associated variable CVarShadowFadeExponent:

The purpose of CVarShadowFadeExponent is to provide a console-variable interface for the r.Shadow.FadeExponent setting. It allows for runtime modification and access to the shadow fade exponent value.

This variable is part of the Renderer module and is used directly in the shadow setup calculations.

The value of CVarShadowFadeExponent is set when the TAutoConsoleVariable is initialized, with a default value of 0.25f. It can be modified through console commands or configuration files.

CVarShadowFadeExponent interacts directly with the CalculateShadowFadeAlpha function, where its value is retrieved and used in shadow fade calculations.

Developers should be aware that changes to CVarShadowFadeExponent will immediately affect shadow rendering. It’s marked as ECVF_RenderThreadSafe, meaning it’s safe to modify from the render thread.

Best practices for using CVarShadowFadeExponent include:

  1. Using the console variable interface for debugging and fine-tuning shadow fading behavior.
  2. Documenting any non-default values used in production to ensure consistency across development and release builds.
  3. Considering the impact on different hardware configurations when modifying this value.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:139

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarShadowFadeExponent(
	TEXT("r.Shadow.FadeExponent"),
	0.25f,
	TEXT("Controls the rate at which shadows are faded out"),
	ECVF_RenderThreadSafe);

static int32 GShadowLightViewConvexHullCull = 1;
static FAutoConsoleVariableRef CVarShadowLightViewConvexHullCull(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:138

Scope: file

Source code excerpt:

	);

static TAutoConsoleVariable<float> CVarShadowFadeExponent(
	TEXT("r.Shadow.FadeExponent"),
	0.25f,
	TEXT("Controls the rate at which shadows are faded out"),
	ECVF_RenderThreadSafe);

static int32 GShadowLightViewConvexHullCull = 1;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:444

Scope (from outer to inner):

file
function     float CalculateShadowFadeAlpha

Source code excerpt:

	else if (MaxUnclampedResolution > MinShadowResolution)
	{
		const float Exponent = CVarShadowFadeExponent.GetValueOnRenderThread();
		
		// Use the limit case ShadowFadeResolution = MinShadowResolution
		// to gracefully handle this case.
		if (MinShadowResolution >= ShadowFadeResolution)
		{
			const float SizeRatio = (float)(MaxUnclampedResolution - MinShadowResolution);