r.ManyLights.Sampling.MinWeight

r.ManyLights.Sampling.MinWeight

#Overview

name: r.ManyLights.Sampling.MinWeight

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.Sampling.MinWeight is to determine the minimal sample influence on final pixels in the Many Lights rendering system. It is used to optimize performance by skipping samples that would have minimal impact on the final image, even if the light is fully visible.

This setting variable is primarily used in the rendering system, specifically in the Many Lights subsystem of Unreal Engine 5. Based on the callsites, it is used in the Renderer module, particularly in the ManyLights.cpp file.

The value of this variable is set through a console variable (CVar) named CVarManyLightsSamplingMinWeight. It has a default value of 0.001f, which can be changed at runtime or through configuration files.

The variable interacts with the ManyLightsParameters struct, where its value is assigned to the SamplingMinWeight field. This struct is likely used to pass parameters to the Many Lights rendering system.

Developers should be aware that this variable affects rendering performance and quality. Setting it too high might result in visible artifacts or loss of subtle lighting details, while setting it too low might negatively impact performance without noticeable visual improvements.

Best practices when using this variable include:

  1. Experimenting with different values to find the optimal balance between performance and visual quality for your specific scene.
  2. Consider exposing this setting to end-users as a scalability option, allowing them to adjust it based on their hardware capabilities.
  3. Be cautious when modifying this value, as it can affect the visual consistency of your game across different hardware configurations.

Regarding the associated variable CVarManyLightsSamplingMinWeight:

This is the actual console variable that stores and manages the r.ManyLights.Sampling.MinWeight value. It is defined as a TAutoConsoleVariable, which means it can be modified at runtime through console commands or configuration files.

The CVarManyLightsSamplingMinWeight is used directly in the rendering code to retrieve the current value of the setting. It has the ECVF_Scalability and ECVF_RenderThreadSafe flags, indicating that it’s safe to modify on the render thread and can be used as a scalability option.

When working with this variable, developers should:

  1. Use the GetValueOnRenderThread() method to retrieve its value safely in render thread code.
  2. Consider caching the value if it’s used frequently, to avoid potential performance overhead from repeated CVar lookups.
  3. Be aware that changes to this CVar will take effect immediately, which could cause visual changes during gameplay if modified.

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarManyLightsSamplingMinWeight(
	TEXT("r.ManyLights.Sampling.MinWeight"),
	0.001f,
	TEXT("Determines minimal sample influence on final pixels. Used to skip samples which would have minimal impact to the final image even if light is fully visible."),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int32> CVarManyLightsTemporal(

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<float> CVarManyLightsSamplingMinWeight(
	TEXT("r.ManyLights.Sampling.MinWeight"),
	0.001f,
	TEXT("Determines minimal sample influence on final pixels. Used to skip samples which would have minimal impact to the final image even if light is fully visible."),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

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

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderManyLights

Source code excerpt:

		ManyLightsParameters.ShadingTileGridSize = ShadingTileGridSize;
		ManyLightsParameters.DownsampledBufferInvSize = FVector2f(1.0f) / DownsampledBufferSize;
		ManyLightsParameters.SamplingMinWeight = FMath::Max(CVarManyLightsSamplingMinWeight.GetValueOnRenderThread(), 0.0f);
		ManyLightsParameters.TileDataStride = TileDataStride;
		ManyLightsParameters.DownsampledTileDataStride = DownsampledTileDataStride;
		ManyLightsParameters.TemporalMaxFramesAccumulated = FMath::Max(CVarManyLightsTemporalMaxFramesAccumulated.GetValueOnRenderThread(), 0.0f);
		ManyLightsParameters.TemporalNeighborhoodClampScale = CVarManyLightsTemporalNeighborhoodClampScale.GetValueOnRenderThread();
		ManyLightsParameters.TemporalAdvanceFrame = View.ViewState && !View.bStatePrevViewInfoIsReadOnly ? 1 : 0;
		ManyLightsParameters.DebugMode = ManyLights::GetDebugMode();