r.PathTracing.LightGridMaxCount

r.PathTracing.LightGridMaxCount

#Overview

name: r.PathTracing.LightGridMaxCount

This variable is created as a Console Variable (cvar).

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.PathTracing.LightGridMaxCount is to control the maximum number of lights per cell in the 2D light grid used in path tracing rendering. This setting variable is primarily used in the rendering system, specifically for path tracing calculations.

This setting variable is relied upon by the Renderer module of Unreal Engine, particularly within the path tracing subsystem. It’s used in the PathTracing.cpp file, which is part of the core rendering functionality.

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

The associated variable CVarPathTracingLightGridMaxCount directly interacts with r.PathTracing.LightGridMaxCount. They share the same value and purpose.

Developers must be aware that this variable affects the performance and quality of path tracing. A higher value allows for more accurate lighting calculations but may impact performance. The actual number of lights used per cell is the minimum of this value and the total number of lights in the scene.

Best practices when using this variable include:

  1. Adjust it based on the scene complexity and performance requirements.
  2. Consider the trade-off between lighting accuracy and rendering performance.
  3. Test different values to find the optimal balance for your specific scene.

Regarding the associated variable CVarPathTracingLightGridMaxCount:

The purpose of CVarPathTracingLightGridMaxCount is identical to r.PathTracing.LightGridMaxCount. It’s the C++ representation of the console variable.

This variable is used within the Renderer module, specifically in the path tracing implementation.

The value is set when the console variable is initialized and can be accessed using the GetValueOnRenderThread() method.

It interacts directly with r.PathTracing.LightGridMaxCount and is used in the actual path tracing calculations.

Developers should be aware that this variable is used in performance-critical code and its value is clamped between 1 and the minimum of the number of finite lights in the scene and a maximum constant (RAY_TRACING_LIGHT_COUNT_MAXIMUM).

Best practices include:

  1. Use GetValueOnRenderThread() to access the current value in render thread code.
  2. Be cautious when modifying this value, as it can significantly impact rendering performance and quality.
  3. Consider the interaction with other path tracing settings when adjusting this value.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracing.cpp:266

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarPathTracingLightGridMaxCount(
	TEXT("r.PathTracing.LightGridMaxCount"),
	128,
	TEXT("Controls the maximum number of lights per cell in the 2D light grid. The minimum of this value and the number of lights in the scene is used. (default = 128)\n"),
	ECVF_RenderThreadSafe
);

TAutoConsoleVariable<int32> CVarPathTracingLightGridVisualize(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracing.cpp:265

Scope: file

Source code excerpt:

);

TAutoConsoleVariable<int32> CVarPathTracingLightGridMaxCount(
	TEXT("r.PathTracing.LightGridMaxCount"),
	128,
	TEXT("Controls the maximum number of lights per cell in the 2D light grid. The minimum of this value and the number of lights in the scene is used. (default = 128)\n"),
	ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracing.cpp:1948

Scope (from outer to inner):

file
function     void PrepareLightGrid

Source code excerpt:

		const uint32 Resolution = FMath::RoundUpToPowerOfTwo(CVarPathTracingLightGridResolution.GetValueOnRenderThread());
		const uint32 MaxCount = FMath::Clamp(
			CVarPathTracingLightGridMaxCount.GetValueOnRenderThread(),
			1,
			FMath::Min(NumFiniteLights, RAY_TRACING_LIGHT_COUNT_MAXIMUM)
		);
		LightGridParameters->LightGridResolution = Resolution;
		LightGridParameters->LightGridMaxCount = MaxCount;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracing.cpp:2514

Scope: file

Source code excerpt:


	Config.LightGridResolution = FMath::RoundUpToPowerOfTwo(CVarPathTracingLightGridResolution.GetValueOnRenderThread());
	Config.LightGridMaxCount = FMath::Clamp(CVarPathTracingLightGridMaxCount.GetValueOnRenderThread(), 1, RAY_TRACING_LIGHT_COUNT_MAXIMUM);

	Config.PathTracingData.MaxSamples = MaxSPP;

	bool FirstTime = false;
	if (!View.ViewState->PathTracingState.IsValid())
	{