r.VRS.LightFunctions

r.VRS.LightFunctions

#Overview

name: r.VRS.LightFunctions

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.VRS.LightFunctions is to enable and control Variable Rate Shading (VRS) for light functions in Unreal Engine 5’s rendering system.

This setting variable is primarily used by the rendering subsystem of Unreal Engine 5, specifically in the Variable Rate Shading module. It is implemented in the VariableRateShadingImageManager.cpp file, which is part of the Renderer module.

The value of this variable is set through a console variable (CVarVRSLightFunctions) with three possible options: 0: Disabled 1: Full (default) 2: Conservative

This variable interacts with other VRS-related variables in the engine, as it’s part of a larger system controlling Variable Rate Shading for different rendering passes. It’s associated with CVarVRSLightFunctions, which shares the same value and is used to control the behavior in the code.

Developers should be aware that changing this variable will affect the rendering performance and quality of light functions in the scene. Using VRS can improve performance by reducing shading resolution in less important areas, but it may also impact visual quality if not configured correctly.

Best practices when using this variable include:

  1. Testing different settings to find the optimal balance between performance and visual quality for your specific project.
  2. Considering the impact on different hardware, as VRS support may vary across GPUs.
  3. Using it in conjunction with other VRS settings for a comprehensive approach to optimization.

Regarding the associated variable CVarVRSLightFunctions:

The purpose of CVarVRSLightFunctions is to provide a programmatic interface for controlling the r.VRS.LightFunctions setting within the engine’s code.

This variable is used directly in the rendering subsystem, specifically in the FDebugVariableRateShadingCS class, which is likely responsible for debugging and controlling VRS behavior.

The value of CVarVRSLightFunctions is set through the console variable system and can be accessed on the render thread using GetValueOnRenderThread().

It interacts with other VRS-related variables in the CVarByPassType array, which suggests it’s part of a larger system for controlling VRS across different rendering passes.

Developers should be aware that this variable is used in render thread operations and should be accessed accordingly to avoid threading issues.

Best practices for using CVarVRSLightFunctions include:

  1. Accessing its value on the render thread when needed for VRS-related calculations.
  2. Using it in conjunction with other VRS pass type variables for consistent control over the VRS system.
  3. Considering its impact on performance and visual quality when implementing custom rendering features that involve light functions.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/VariableRateShadingImageManager.cpp:141

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);
TAutoConsoleVariable<int32> CVarVRSLightFunctions(
	TEXT("r.VRS.LightFunctions"),
	1,
	TEXT("Enables Variable Rate Shading for light functions\n")
	TEXT("0: Disabled")
	TEXT("1: Full (default)")
	TEXT("2: Conservative"),
	FConsoleVariableDelegate::CreateStatic(&CVarVRSImagePassTypeCallback),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/VariableRateShadingImageManager.cpp:140

Scope: file

Source code excerpt:

	FConsoleVariableDelegate::CreateStatic(&CVarVRSImagePassTypeCallback),
	ECVF_RenderThreadSafe);
TAutoConsoleVariable<int32> CVarVRSLightFunctions(
	TEXT("r.VRS.LightFunctions"),
	1,
	TEXT("Enables Variable Rate Shading for light functions\n")
	TEXT("0: Disabled")
	TEXT("1: Full (default)")
	TEXT("2: Conservative"),

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/VariableRateShadingImageManager.cpp:774

Scope (from outer to inner):

file
class        class FDebugVariableRateShadingCS : public FGlobalShader

Source code excerpt:

			CVarByPassType[EVRSPassType::SSR] = &CVarVRS_SSR;
			CVarByPassType[EVRSPassType::ReflectionEnvironmentAndSky] = &CVarVRSReflectionEnvironmentSky;
			CVarByPassType[EVRSPassType::LightFunctions] = &CVarVRSLightFunctions;
			CVarByPassType[EVRSPassType::Decals] = &CVarVRSDecals;
		}
	} StaticData;

	uint32 ImageTypeAsInt = StaticData.CVarByPassType[PassType]->GetValueOnRenderThread();
	if (ImageTypeAsInt >= 0 && ImageTypeAsInt <= EVRSImageType::Conservative)