r.ManyLights.ResetEveryNthFrame

r.ManyLights.ResetEveryNthFrame

#Overview

name: r.ManyLights.ResetEveryNthFrame

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.ManyLights.ResetEveryNthFrame is to control the periodic resetting of history in the Many Lights system for debugging purposes. This setting variable is part of the rendering system in Unreal Engine 5, specifically related to the management of multiple light sources in a scene.

The Unreal Engine subsystem that relies on this setting variable is the Renderer module, particularly the Many Lights system. This can be seen from the file path where the variable is defined and used: Engine/Source/Runtime/Renderer/Private/ManyLights/ManyLights.cpp.

The value of this variable is set through the console variable system in Unreal Engine. It’s defined as an FAutoConsoleVariableRef, which means it can be modified at runtime through console commands or configuration files.

This variable interacts with another variable named GManyLightsResetEveryNthFrame. They share the same value, with r.ManyLights.ResetEveryNthFrame being the console-accessible name and GManyLightsResetEveryNthFrame being the internal C++ variable.

Developers must be aware that this variable is intended for debugging purposes. It should not be used in production builds or for gameplay-critical features. The variable is marked as ECVF_RenderThreadSafe, indicating it’s safe to modify from the render thread.

Best practices when using this variable include:

  1. Only enable it when debugging lighting issues.
  2. Be aware that frequent history resets may impact performance.
  3. Use in conjunction with other debugging tools to isolate lighting-related problems.

Regarding the associated variable GManyLightsResetEveryNthFrame:

The purpose of GManyLightsResetEveryNthFrame is to store the value set by r.ManyLights.ResetEveryNthFrame and make it accessible within the C++ code of the Many Lights system.

This variable is used in the RenderManyLights function of the FDeferredShadingSceneRenderer class. It determines whether the lighting history should be reset on a given frame based on the frame number.

The value of GManyLightsResetEveryNthFrame is set directly by the console variable system when r.ManyLights.ResetEveryNthFrame is modified.

Developers should be aware that changing this variable will affect the frequency of history resets in the Many Lights system, which could impact both visual results and performance during debugging sessions.

Best practices for using GManyLightsResetEveryNthFrame include:

  1. Avoid modifying it directly in code; instead, use the r.ManyLights.ResetEveryNthFrame console variable.
  2. When debugging, start with larger values (less frequent resets) and decrease as needed to isolate issues.
  3. Remember to set it back to 0 (disabled) when not actively debugging to avoid unnecessary performance impact.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ManyLights/ManyLights.cpp:108

Scope: file

Source code excerpt:

int32 GManyLightsResetEveryNthFrame = 0;
	FAutoConsoleVariableRef CVarManyLightsResetEveryNthFrame(
	TEXT("r.ManyLights.ResetEveryNthFrame"),
		GManyLightsResetEveryNthFrame,
	TEXT("Reset history every Nth frame for debugging."),
	ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int> CVarManyLightsFixedStateFrameIndex(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ManyLights/ManyLights.cpp:106

Scope: file

Source code excerpt:

);

int32 GManyLightsResetEveryNthFrame = 0;
	FAutoConsoleVariableRef CVarManyLightsResetEveryNthFrame(
	TEXT("r.ManyLights.ResetEveryNthFrame"),
		GManyLightsResetEveryNthFrame,
	TEXT("Reset history every Nth frame for debugging."),
	ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int> CVarManyLightsFixedStateFrameIndex(
	TEXT("r.ManyLights.FixedStateFrameIndex"),

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ManyLights/ManyLights.cpp:641

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderManyLights

Source code excerpt:

	bool bResetHistory = false;

	if (GManyLightsResetEveryNthFrame > 0 && (ViewFamily.FrameNumber % (uint32)GManyLightsResetEveryNthFrame) == 0)
	{
		bResetHistory = true;
	}

	if (GManyLightsReset != 0)
	{