r.Color.Mid

r.Color.Mid

#Overview

name: r.Color.Mid

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.Mid is to control the mapping of midtones in color grading within the Unreal Engine 5 rendering system. It allows developers to adjust where the value 0.5 in color channels is mapped after color grading, similar to a gamma correction.

This setting variable is primarily used in the Renderer module of Unreal Engine 5, specifically in the post-processing subsystem for color grading and LUT (Look-Up Table) combination.

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

The r.Color.Mid variable interacts with other color grading variables, such as r.Color.Min and r.Color.Max, to define the overall color transformation curve. These variables work together to adjust the dark, mid, and bright tones of the rendered image.

Developers must be aware that this variable affects the global color grading of the entire scene. Changing its value will impact the overall look and feel of the rendered image, particularly in the midtone regions.

Best practices when using this variable include:

  1. Keep the value close to 0.5 for a neutral effect.
  2. Use smaller values to darken midtones and larger values to brighten them.
  3. Test changes in various lighting conditions to ensure desired results.
  4. Consider using in conjunction with r.Color.Min and r.Color.Max for a complete color grading solution.

Regarding the associated variable CVarColorMid:

The purpose of CVarColorMid is to provide a programmatic interface to the r.Color.Mid console variable within the C++ code of Unreal Engine 5.

This variable is used in the Renderer module, specifically in the post-processing subsystem for color grading and LUT combination.

The value of CVarColorMid is set when the r.Color.Mid console variable is modified, either through console commands or C++ code.

CVarColorMid interacts directly with the r.Color.Mid console variable and is used in the GetMappingPolynomial() function to calculate color transformation values.

Developers should be aware that CVarColorMid is a TAutoConsoleVariable, which means it’s thread-safe and can be accessed from the render thread.

Best practices for using CVarColorMid include:

  1. Access its value using GetValueOnRenderThread() when in render thread context.
  2. Use FMath::Clamp() to ensure the value stays within a reasonable range (-10.0f to 10.0f in this case).
  3. Consider the performance impact of frequently accessing this variable in performance-critical code paths.

#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:20

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:


TAutoConsoleVariable<float> CVarColorMid(
	TEXT("r.Color.Mid"),
	0.5f,
	TEXT("Allows to define where the value 0.5 in the color channels is mapped to after color grading (This is similar to a gamma correction).\n")
	TEXT("Value should be around 0.5, smaller values darken the mid tones, larger values brighten the mid tones, Default: 0.5"),
	ECVF_RenderThreadSafe);

TAutoConsoleVariable<float> CVarColorMax(

#Associated Variable and Callsites

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

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

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:

	ECVF_RenderThreadSafe);

TAutoConsoleVariable<float> CVarColorMid(
	TEXT("r.Color.Mid"),
	0.5f,
	TEXT("Allows to define where the value 0.5 in the color channels is mapped to after color grading (This is similar to a gamma correction).\n")
	TEXT("Value should be around 0.5, smaller values darken the mid tones, larger values brighten the mid tones, Default: 0.5"),
	ECVF_RenderThreadSafe);

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

Scope (from outer to inner):

file
function     FVector3f GetMappingPolynomial

Source code excerpt:

	FColorTransform ColorTransform;
	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;