r.MinRoughnessOverride

r.MinRoughnessOverride

#Overview

name: r.MinRoughnessOverride

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.MinRoughnessOverride is to set a global limit for roughness in direct lighting calculations within the rendering system. This setting is designed to help reduce the occurrence of fireflies (bright specks) in rendered images, particularly when anti-aliasing is not in use.

This setting variable is primarily used in the Unreal Engine’s rendering system, specifically within the SceneView module. It’s part of the engine’s core rendering pipeline and affects how materials and surfaces are rendered in terms of their roughness properties.

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

The associated variable CVarGlobalMinRoughnessOverride directly interacts with r.MinRoughnessOverride. They share the same value and purpose, with CVarGlobalMinRoughnessOverride being the actual C++ variable that stores and provides access to the value set by r.MinRoughnessOverride.

Developers must be aware of several important aspects when using this variable:

  1. It’s marked as an experimental feature, which means it may change or be removed in future engine versions.
  2. The default value is 0.0, which means no change to the original roughness calculations.
  3. When set to a non-zero value, it will override the minimum roughness globally for all materials in the scene.
  4. It affects direct lighting calculations, which can have a significant impact on the final rendered image.

Best practices when using this variable include:

  1. Use it cautiously, as it’s an experimental feature.
  2. Start with small values (slightly above 0.0) and gradually increase if needed to find the right balance between reducing fireflies and maintaining material detail.
  3. Be aware that it may affect the intended look of materials, especially those designed with very low roughness values.
  4. Consider it as a temporary solution and aim to address the root cause of fireflies (e.g., improving lighting setup or material properties) for a more robust long-term solution.

Regarding the associated variable CVarGlobalMinRoughnessOverride:

This C++ variable is the actual implementation of the r.MinRoughnessOverride setting. It’s used internally by the engine to store and retrieve the value set by r.MinRoughnessOverride. The variable is applied in the FSceneView::SetupCommonViewUniformBufferParameters function, where it’s clamped between 0.02 and 1.0 before being assigned to ViewUniformShaderParameters.MinRoughness. This ensures that the minimum roughness value stays within a reasonable range for rendering calculations.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SceneView.cpp:56

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarGlobalMinRoughnessOverride(
	TEXT("r.MinRoughnessOverride"),
	0.0f,
	TEXT("WARNING: This is an experimental feature that may change at any time.\n")
	TEXT("Sets a global limit for roughness when used in the direct lighting calculations.\n")
	TEXT("This can be used to limit the amount of fireflies caused by low roughness, in particular when AA is not in use.\n")
	TEXT(" 0.0: no change (default)"),
	ECVF_Scalability | ECVF_RenderThreadSafe);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SceneView.cpp:55

Scope: file

Source code excerpt:



static TAutoConsoleVariable<float> CVarGlobalMinRoughnessOverride(
	TEXT("r.MinRoughnessOverride"),
	0.0f,
	TEXT("WARNING: This is an experimental feature that may change at any time.\n")
	TEXT("Sets a global limit for roughness when used in the direct lighting calculations.\n")
	TEXT("This can be used to limit the amount of fireflies caused by low roughness, in particular when AA is not in use.\n")
	TEXT(" 0.0: no change (default)"),

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SceneView.cpp:2758

Scope (from outer to inner):

file
function     void FSceneView::SetupCommonViewUniformBufferParameters

Source code excerpt:

	ViewUniformShaderParameters.CameraCut = bCameraCut ? 1 : (InViewMatrices.IsPerspectiveProjection() != InPrevViewMatrices.IsPerspectiveProjection());

	ViewUniformShaderParameters.MinRoughness = FMath::Clamp(CVarGlobalMinRoughnessOverride.GetValueOnRenderThread(), 0.02f, 1.0f);

	//to tail call keep the order and number of parameters of the caller function
	SetupViewRectUniformBufferParameters(ViewUniformShaderParameters, BufferSize, EffectiveViewRect, InViewMatrices, InPrevViewMatrices);
}

bool FSceneView::HasValidEyeAdaptationTexture() const