r.Roughness.Min

r.Roughness.Min

#Overview

name: r.Roughness.Min

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.Roughness.Min is to allow quick material testing by remapping the minimum roughness value in materials. It is primarily used for the rendering system, specifically for material shading.

This setting variable is utilized by the Unreal Engine’s rendering module, particularly in the scene view setup process. It’s part of the engine’s core rendering pipeline.

The value of this variable is set through a console variable (CVar) system, which allows for runtime modification. It’s defined with a default value of 0.0f, meaning by default, it doesn’t affect the roughness values.

This variable interacts closely with another variable, r.Roughness.Max. Together, they form a range for remapping roughness values in materials.

Developers must be aware that this variable is marked with ECVF_Cheat and ECVF_RenderThreadSafe flags. The ECVF_Cheat flag indicates that it should not be used in shipping builds, as it’s intended for testing and debugging purposes only. The ECVF_RenderThreadSafe flag means it can be safely accessed from the render thread.

Best practices when using this variable include:

  1. Only use it for testing and debugging, never in shipping builds.
  2. Be cautious when modifying it at runtime, as it can significantly affect the appearance of materials in the scene.
  3. Always consider its interaction with r.Roughness.Max to ensure a valid range.

Regarding the associated variable CVarRoughnessMin:

The purpose of CVarRoughnessMin is to store and provide access to the r.Roughness.Min value within the engine’s C++ code. It’s the actual console variable object that manages the r.Roughness.Min setting.

This variable is used in the FSceneView::SetupCommonViewUniformBufferParameters function to adjust the roughness values before they’re passed to the shader. It’s accessed using the GetValueOnRenderThread() method, ensuring thread-safe access in the render thread.

The value of CVarRoughnessMin is set when the r.Roughness.Min console command is used, either through the console or configuration files.

Developers should be aware that modifying CVarRoughnessMin directly in C++ code is generally not recommended. Instead, they should use the console variable system to modify r.Roughness.Min, which will in turn update CVarRoughnessMin.

Best practices for CVarRoughnessMin include:

  1. Access its value using GetValueOnRenderThread() when in render thread code.
  2. Don’t modify it directly; use the console variable system instead.
  3. Be aware of its performance implications, as it’s accessed during the view setup for each frame.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

	);
static TAutoConsoleVariable<float> CVarRoughnessMin(
	TEXT("r.Roughness.Min"),
	0.0f,
	TEXT("Allows quick material test by remapping the roughness at 0 to a new value (0..1), Only for non shipping built!\n")
	TEXT("0: (default)"),
	ECVF_Cheat | ECVF_RenderThreadSafe
	);
static TAutoConsoleVariable<float> CVarRoughnessMax(

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_Cheat | ECVF_RenderThreadSafe
	);
static TAutoConsoleVariable<float> CVarRoughnessMin(
	TEXT("r.Roughness.Min"),
	0.0f,
	TEXT("Allows quick material test by remapping the roughness at 0 to a new value (0..1), Only for non shipping built!\n")
	TEXT("0: (default)"),
	ECVF_Cheat | ECVF_RenderThreadSafe
	);

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

Scope (from outer to inner):

file
function     void FSceneView::SetupCommonViewUniformBufferParameters

Source code excerpt:

		float MaxValue = MinValue + LocalRoughnessOverrideParameter.Y;

		float NewMinValue = FMath::Max(MinValue, CVarRoughnessMin.GetValueOnRenderThread());
		float NewMaxValue = FMath::Min(MaxValue, CVarRoughnessMax.GetValueOnRenderThread());

		LocalRoughnessOverrideParameter.X = NewMinValue;
		LocalRoughnessOverrideParameter.Y = NewMaxValue - NewMinValue;
	}
#endif