r.Lumen.DiffuseIndirect.MeshSDF.RadiusThreshold

r.Lumen.DiffuseIndirect.MeshSDF.RadiusThreshold

#Overview

name: r.Lumen.DiffuseIndirect.MeshSDF.RadiusThreshold

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.Lumen.DiffuseIndirect.MeshSDF.RadiusThreshold is to control the radius threshold for Mesh Signed Distance Field (SDF) objects in Lumen’s diffuse indirect lighting system. This setting is part of Unreal Engine 5’s Lumen global illumination system, specifically for the rendering subsystem.

The Lumen rendering subsystem relies on this setting variable, as evidenced by its use in the LumenMeshSDFCulling.cpp file. This file is part of the Renderer module in the Engine’s source code.

The value of this variable is set using an FAutoConsoleVariableRef, which allows it to be modified at runtime through console commands. It’s initialized with a default value of 30.

This variable interacts directly with GMeshSDFRadiusThreshold, which is the associated C++ variable that stores the actual value. They share the same value and are linked through the FAutoConsoleVariableRef.

Developers should be aware that this variable is marked with ECVF_Scalability and ECVF_RenderThreadSafe flags. This means it can be adjusted for different scalability settings and is safe to modify from the render thread.

When using this variable, developers should consider the following best practices:

  1. Understand that changing this value will affect the culling of Mesh SDF objects in the Lumen system.
  2. Be cautious when modifying it, as it may impact performance and visual quality.
  3. Test thoroughly with different values to find the optimal balance between performance and visual fidelity for your specific use case.

Regarding the associated variable GMeshSDFRadiusThreshold:

The purpose of GMeshSDFRadiusThreshold is to store the actual value of the radius threshold for Mesh SDF objects in the Lumen system. It’s a float variable that directly corresponds to the console variable r.Lumen.DiffuseIndirect.MeshSDF.RadiusThreshold.

This variable is used in the CullMeshSDFObjectsForView function, where it’s divided by the LumenSceneDetail setting from the view’s post-process settings. This calculation adjusts the threshold based on the scene detail level, potentially affecting the culling of Mesh SDF objects.

Developers should be aware that:

  1. Changes to r.Lumen.DiffuseIndirect.MeshSDF.RadiusThreshold will directly affect GMeshSDFRadiusThreshold.
  2. The actual threshold used in culling is further modified by the LumenSceneDetail setting.
  3. This variable plays a crucial role in determining which Mesh SDF objects are considered for Lumen’s diffuse indirect lighting calculations.

Best practices for using GMeshSDFRadiusThreshold include:

  1. Consider the interaction with LumenSceneDetail when adjusting this value.
  2. Monitor performance and visual quality when modifying this threshold, as it can significantly impact both.
  3. Use the console variable r.Lumen.DiffuseIndirect.MeshSDF.RadiusThreshold for runtime adjustments rather than directly modifying the C++ variable.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Lumen/LumenMeshSDFCulling.cpp:25

Scope: file

Source code excerpt:

float GMeshSDFRadiusThreshold = 30;
FAutoConsoleVariableRef CVarMeshSDFRadiusThreshold(
	TEXT("r.Lumen.DiffuseIndirect.MeshSDF.RadiusThreshold"),
	GMeshSDFRadiusThreshold,
	TEXT(""),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

float GMeshSDFNotCoveredExpandSurfaceScale = .6f;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Lumen/LumenMeshSDFCulling.cpp:23

Scope: file

Source code excerpt:

);

float GMeshSDFRadiusThreshold = 30;
FAutoConsoleVariableRef CVarMeshSDFRadiusThreshold(
	TEXT("r.Lumen.DiffuseIndirect.MeshSDF.RadiusThreshold"),
	GMeshSDFRadiusThreshold,
	TEXT(""),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

float GMeshSDFNotCoveredExpandSurfaceScale = .6f;
FAutoConsoleVariableRef CVarMeshSDFNotCoveredExpandSurfaceScale(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Lumen/LumenMeshSDFCulling.cpp:609

Scope (from outer to inner):

file
function     void CullMeshSDFObjectsForView

Source code excerpt:

		PassParameters->CardTraceEndDistanceFromCamera = CardTraceEndDistanceFromCamera;
		PassParameters->MaxMeshSDFInfluenceRadius = MaxMeshSDFInfluenceRadius;
		PassParameters->MeshSDFRadiusThreshold = GMeshSDFRadiusThreshold / FMath::Clamp(View.FinalPostProcessSettings.LumenSceneDetail, .01f, 100.0f);

		auto ComputeShader = View.ShaderMap->GetShader<FCullMeshSDFObjectsForViewCS>();

		const int32 GroupSize = FMath::DivideAndRoundUp<int32>(DistanceFieldSceneData.NumObjectsInBuffer, CullMeshSDFObjectsForViewGroupSize);

		FComputeShaderUtils::AddPass(