r.ReflectionEnvironmentEndMixingRoughness

r.ReflectionEnvironmentEndMixingRoughness

#Overview

name: r.ReflectionEnvironmentEndMixingRoughness

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.ReflectionEnvironmentEndMixingRoughness is to control the upper limit of the roughness range for mixing reflection captures with lightmap indirect diffuse in the reflection environment system.

This setting variable is primarily used in the rendering system of Unreal Engine 5, specifically in the reflection environment subsystem. It is part of the Renderer module, as evident from its location in the ReflectionEnvironment.cpp file.

The value of this variable is set through the console variable system in Unreal Engine. It’s initialized with a default value of 0.3f and can be modified at runtime using console commands or through project settings.

The variable interacts closely with another variable called GReflectionEnvironmentBeginMixingRoughness (not shown in the provided code snippet but implied by its usage). Together, these two variables define a range of roughness values where the mixing of reflection captures and lightmap indirect diffuse occurs.

Developers must be aware that this variable affects the visual quality and performance of reflections in the game. Setting it too low might result in abrupt transitions in reflection quality, while setting it too high might unnecessarily increase the computational cost of reflections on rougher surfaces.

Best practices when using this variable include:

  1. Adjusting it in tandem with GReflectionEnvironmentBeginMixingRoughness to create a smooth transition.
  2. Testing different values to find the optimal balance between visual quality and performance for your specific project.
  3. Considering the target hardware when setting this value, as it can impact performance on lower-end devices.

Regarding the associated variable GReflectionEnvironmentEndMixingRoughness:

The purpose of GReflectionEnvironmentEndMixingRoughness is to store the actual value used by the engine for the end mixing roughness. It’s the C++ variable that holds the value set by the console variable r.ReflectionEnvironmentEndMixingRoughness.

This variable is used directly in the rendering calculations, specifically in the GetReflectionEnvironmentRoughnessMixingScaleBiasAndLargestWeight function. This function appears to calculate parameters for the reflection environment mixing based on the roughness range defined by the begin and end mixing roughness values.

The value of GReflectionEnvironmentEndMixingRoughness is set by the console variable system, allowing it to be changed dynamically during runtime or through configuration files.

Developers should be aware that modifying GReflectionEnvironmentEndMixingRoughness directly in C++ code is not recommended. Instead, they should use the console variable r.ReflectionEnvironmentEndMixingRoughness to ensure proper synchronization and to take advantage of the engine’s variable management system.

Best practices for using GReflectionEnvironmentEndMixingRoughness include:

  1. Accessing its value through getter functions or the console variable system rather than directly.
  2. Considering its impact on reflection calculations when optimizing rendering performance.
  3. Documenting any custom logic that relies on this variable to aid in future maintenance and debugging.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ReflectionEnvironment.cpp:72

Scope: file

Source code excerpt:

float GReflectionEnvironmentEndMixingRoughness = .3f;
FAutoConsoleVariableRef CVarReflectionEnvironmentEndMixingRoughness(
	TEXT("r.ReflectionEnvironmentEndMixingRoughness"),
	GReflectionEnvironmentEndMixingRoughness,
	TEXT("Min roughness value at which to end mixing reflection captures with lightmap indirect diffuse."),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

int32 GReflectionEnvironmentLightmapMixLargestWeight = 10000;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ReflectionEnvironment.cpp:70

Scope: file

Source code excerpt:

	);

float GReflectionEnvironmentEndMixingRoughness = .3f;
FAutoConsoleVariableRef CVarReflectionEnvironmentEndMixingRoughness(
	TEXT("r.ReflectionEnvironmentEndMixingRoughness"),
	GReflectionEnvironmentEndMixingRoughness,
	TEXT("Min roughness value at which to end mixing reflection captures with lightmap indirect diffuse."),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

int32 GReflectionEnvironmentLightmapMixLargestWeight = 10000;
FAutoConsoleVariableRef CVarReflectionEnvironmentLightmapMixLargestWeight(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ReflectionEnvironment.cpp:113

Scope (from outer to inner):

file
function     FVector GetReflectionEnvironmentRoughnessMixingScaleBiasAndLargestWeight

Source code excerpt:

FVector GetReflectionEnvironmentRoughnessMixingScaleBiasAndLargestWeight()
{
	float RoughnessMixingRange = 1.0f / FMath::Max(GReflectionEnvironmentEndMixingRoughness - GReflectionEnvironmentBeginMixingRoughness, .001f);

	if (GReflectionEnvironmentLightmapMixing == 0)
	{
		return FVector(0, 0, GReflectionEnvironmentLightmapMixLargestWeight);
	}

	if (GReflectionEnvironmentEndMixingRoughness == 0.0f && GReflectionEnvironmentBeginMixingRoughness == 0.0f)
	{
		// Make sure a Roughness of 0 results in full mixing when disabling roughness-based mixing
		return FVector(0, 1, GReflectionEnvironmentLightmapMixLargestWeight);
	}

	if (!GReflectionEnvironmentLightmapMixBasedOnRoughness)