r.NormalCurvatureToRoughnessScale

r.NormalCurvatureToRoughnessScale

#Overview

name: r.NormalCurvatureToRoughnessScale

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.NormalCurvatureToRoughnessScale is to scale the roughness resulting from screen space normal changes for materials with NormalCurvatureToRoughness enabled. It is primarily used in the rendering system of Unreal Engine 5.

This setting variable is relied upon by the Renderer module, specifically within the scene rendering subsystem. It is used to adjust the appearance of materials that utilize the NormalCurvatureToRoughness feature.

The value of this variable is set through the CVarNormalCurvatureToRoughnessScale console variable. It is defined with a default value of 1.0f and can be changed at runtime.

This variable interacts with other related variables such as CVarNormalCurvatureToRoughnessBias and CVarNormalCurvatureToRoughnessExponent, which together control the behavior of the NormalCurvatureToRoughness feature.

Developers must be aware that this variable has a valid range of [0, 2]. Values outside this range will be clamped. The variable is marked as render thread safe and scalable, meaning it can be adjusted dynamically without causing synchronization issues.

Best practices when using this variable include:

  1. Staying within the valid range of 0 to 2.
  2. Using it in conjunction with the other related variables for fine-tuning material appearance.
  3. Being mindful of its performance impact, as it affects per-pixel calculations in the rendering pipeline.

Regarding the associated variable CVarNormalCurvatureToRoughnessScale:

This is the actual console variable that stores and provides access to the r.NormalCurvatureToRoughnessScale value. It is defined as a TAutoConsoleVariable, which allows it to be easily accessed and modified through the console or code.

The variable is used in the FViewInfo::SetupUniformBufferParameters function to set up shader parameters. Its value is retrieved using GetValueOnAnyThread() and then clamped to the valid range before being assigned to ViewUniformShaderParameters.NormalCurvatureToRoughnessScaleBias.X.

Developers should note that this variable is thread-safe and can be accessed from any thread. However, changes to its value will only take effect in the next frame or when the uniform buffer parameters are next updated.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:331

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarNormalCurvatureToRoughnessScale(
	TEXT("r.NormalCurvatureToRoughnessScale"),
	1.0f,
	TEXT("Scales the roughness resulting from screen space normal changes for materials with NormalCurvatureToRoughness enabled.  Valid range [0, 2]"),
	ECVF_RenderThreadSafe | ECVF_Scalability);

static TAutoConsoleVariable<int32> CVarEnableMultiGPUForkAndJoin(
	TEXT("r.EnableMultiGPUForkAndJoin"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:330

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe | ECVF_Scalability);

static TAutoConsoleVariable<float> CVarNormalCurvatureToRoughnessScale(
	TEXT("r.NormalCurvatureToRoughnessScale"),
	1.0f,
	TEXT("Scales the roughness resulting from screen space normal changes for materials with NormalCurvatureToRoughness enabled.  Valid range [0, 2]"),
	ECVF_RenderThreadSafe | ECVF_Scalability);

static TAutoConsoleVariable<int32> CVarEnableMultiGPUForkAndJoin(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:1809

Scope (from outer to inner):

file
function     void FViewInfo::SetupUniformBufferParameters

Source code excerpt:

	}

	ViewUniformShaderParameters.NormalCurvatureToRoughnessScaleBias.X = FMath::Clamp(CVarNormalCurvatureToRoughnessScale.GetValueOnAnyThread(), 0.0f, 2.0f);
	ViewUniformShaderParameters.NormalCurvatureToRoughnessScaleBias.Y = FMath::Clamp(CVarNormalCurvatureToRoughnessBias.GetValueOnAnyThread(), -1.0f, 1.0f);
	ViewUniformShaderParameters.NormalCurvatureToRoughnessScaleBias.Z = FMath::Clamp(CVarNormalCurvatureToRoughnessExponent.GetValueOnAnyThread(), .05f, 20.0f);

	ViewUniformShaderParameters.RenderingReflectionCaptureMask = bIsReflectionCapture ? 1.0f : 0.0f;
	ViewUniformShaderParameters.RealTimeReflectionCapture = 0.0f;
	ViewUniformShaderParameters.RealTimeReflectionCapturePreExposure = 1.0f; // This must be 1 for now. If changed, we need to update the SkyLight AverageExposure and take it into account when sampling sky specular and diffuse irradiance.