r.Color.Max

r.Color.Max

#Overview

name: r.Color.Max

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.Color.Max is to define the upper limit of color values after color grading in the rendering pipeline. It allows developers to control how the brightest parts of an image are mapped after color grading has been applied.

This setting variable is primarily used in the rendering system, specifically in the post-processing stage of color grading. Based on the callsites, it’s part of the Renderer module in Unreal Engine 5.

The value of this variable is set through the console variable system, with a default value of 1.0f. It can be adjusted at runtime using console commands or through code.

The r.Color.Max variable interacts with two other variables: r.Color.Min and r.Color.Mid. Together, these three variables define a color mapping polynomial used in the color grading process.

Developers should be aware that this variable affects the overall brightness and contrast of the final rendered image. Values smaller than 1.0 will darken the highlights, while values larger than 1.0 will push more colors towards white.

Best practices when using this variable include:

  1. Keep the value close to 1.0 for a natural look.
  2. Use in conjunction with r.Color.Min and r.Color.Mid for balanced color grading.
  3. Be cautious when setting values outside the range of 0.0 to 2.0, as extreme values may lead to unrealistic results.
  4. Test the effects in various lighting conditions to ensure consistent visual quality.

Regarding the associated variable CVarColorMax:

The purpose of CVarColorMax is to provide a programmatic interface to the r.Color.Max console variable. It allows C++ code to read and potentially modify the value of r.Color.Max.

CVarColorMax is used in the Renderer module, specifically in the color grading post-process step. It’s defined and used in the PostProcessCombineLUTs.cpp file.

The value of CVarColorMax is set when the r.Color.Max console variable is modified, either through console commands or code.

CVarColorMax interacts directly with the r.Color.Max console variable, and its value is used in calculations alongside CVarColorMin and CVarColorMid.

Developers should be aware that CVarColorMax.GetValueOnRenderThread() is used to retrieve the current value of r.Color.Max in render thread-safe manner.

Best practices for using CVarColorMax include:

  1. Always access the value using GetValueOnRenderThread() when in render thread code.
  2. Be aware of potential performance implications when frequently reading this value.
  3. Consider caching the value if it’s used multiple times in performance-critical sections.
  4. Use FMath::Clamp when applying the value to ensure it stays within a reasonable range.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessCombineLUTs.cpp:27

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:


TAutoConsoleVariable<float> CVarColorMax(
	TEXT("r.Color.Max"),
	1.0f,
	TEXT("Allows to define where the value 1.0 in the color channels is mapped to after color grading.\n")
	TEXT("Value should be around 1, smaller values darken the highlights, larger values move more colors towards white, Default: 1"),
	ECVF_RenderThreadSafe);

TAutoConsoleVariable<int32> CVarLUTSize(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessCombineLUTs.cpp:26

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:

	ECVF_RenderThreadSafe);

TAutoConsoleVariable<float> CVarColorMax(
	TEXT("r.Color.Max"),
	1.0f,
	TEXT("Allows to define where the value 1.0 in the color channels is mapped to after color grading.\n")
	TEXT("Value should be around 1, smaller values darken the highlights, larger values move more colors towards white, Default: 1"),
	ECVF_RenderThreadSafe);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessCombineLUTs.cpp:86

Scope (from outer to inner):

file
function     FVector3f GetMappingPolynomial

Source code excerpt:

	ColorTransform.MinValue = FMath::Clamp(CVarColorMin.GetValueOnRenderThread(), -10.0f, 10.0f);
	ColorTransform.MidValue = FMath::Clamp(CVarColorMid.GetValueOnRenderThread(), -10.0f, 10.0f);
	ColorTransform.MaxValue = FMath::Clamp(CVarColorMax.GetValueOnRenderThread(), -10.0f, 10.0f);

	// x is the input value, y the output value
	// RGB = a, b, c where y = a * x*x + b * x + c
	float c = ColorTransform.MinValue;
	float b = 4 * ColorTransform.MidValue - 3 * ColorTransform.MinValue - ColorTransform.MaxValue;
	float a = ColorTransform.MaxValue - ColorTransform.MinValue - b;