r.ManyLights.Debug.LightId

r.ManyLights.Debug.LightId

#Overview

name: r.ManyLights.Debug.LightId

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.Debug.LightId is to provide a debugging tool for the rendering system, specifically for the Many Lights rendering technique in Unreal Engine 5. This variable allows developers to select a specific light for which to display debug information.

This setting variable is primarily used in the Renderer module of Unreal Engine, particularly in the Many Lights subsystem. The code references are found in the ManyLights.cpp file, which is part of the rendering pipeline.

The value of this variable is set through a console variable (CVarManyLightsDebugLightId) with a default value of -1. It can be changed at runtime using console commands or through code.

The associated variable CVarManyLightsDebugLightId interacts directly with r.ManyLights.Debug.LightId, as they share the same value. This console variable is used to retrieve the current value of the debug light ID in the rendering thread.

Developers must be aware that:

  1. Setting this variable to -1 will use the currently selected light in the editor for debugging.
  2. The variable is render thread safe, meaning it can be accessed safely from the render thread without causing race conditions.

Best practices when using this variable include:

  1. Use it temporarily for debugging purposes and not in production builds.
  2. Be cautious when setting high values, as it might impact performance if debug information is being generated for many lights.
  3. Remember to reset the value to -1 after debugging to avoid unexpected behavior.

Regarding the associated variable CVarManyLightsDebugLightId:

The purpose of CVarManyLightsDebugLightId is to provide a programmatic way to access and modify the r.ManyLights.Debug.LightId setting. It’s a console variable wrapper that allows for thread-safe access to the debug light ID.

This variable is used within the Renderer module, specifically in the Many Lights rendering system. It’s typically accessed in the RenderManyLights function of the FDeferredShadingSceneRenderer class.

The value of CVarManyLightsDebugLightId is set when the r.ManyLights.Debug.LightId console variable is modified. It can be retrieved using the GetValueOnRenderThread() method, which ensures thread-safe access in the rendering pipeline.

Developers should be aware that:

  1. This variable provides render thread safe access to the debug light ID.
  2. It’s used to populate the DebugLightId field in the ManyLightsParameters struct, which is likely used for debug visualization or logging.

Best practices for using CVarManyLightsDebugLightId include:

  1. Always access it using GetValueOnRenderThread() when in rendering code to ensure thread safety.
  2. Use it in conjunction with other debugging tools and visualizations in the Many Lights system for comprehensive debugging.
  3. Be mindful of performance implications when frequently accessing this variable in performance-critical sections of code.

#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:92

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarManyLightsDebugLightId(
	TEXT("r.ManyLights.Debug.LightId"),
	-1,
	TEXT("Which light to show debug info for. When set to -1, uses the currently selected light in editor."),
	ECVF_RenderThreadSafe
);

int32 GManyLightsReset = 0;

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarManyLightsDebugLightId(
	TEXT("r.ManyLights.Debug.LightId"),
	-1,
	TEXT("Which light to show debug info for. When set to -1, uses the currently selected light in editor."),
	ECVF_RenderThreadSafe
);

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

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderManyLights

Source code excerpt:

			ShaderPrint::SetParameters(GraphBuilder, View.ShaderPrintData, ManyLightsParameters.ShaderPrintUniformBuffer);

			ManyLightsParameters.DebugLightId = CVarManyLightsDebugLightId.GetValueOnRenderThread();

			if (ManyLightsParameters.DebugLightId < 0)
			{
				for (auto LightIt = Scene->Lights.CreateConstIterator(); LightIt; ++LightIt)
				{
					const FLightSceneInfoCompact& LightSceneInfoCompact = *LightIt;