r.VRS.ContrastAdaptiveShading
r.VRS.ContrastAdaptiveShading
#Overview
name: r.VRS.ContrastAdaptiveShading
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Enables using Variable Rate Shading based on the luminance from the previous frame\'s post process output \n
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.VRS.ContrastAdaptiveShading is to enable Variable Rate Shading (VRS) based on the luminance from the previous frame’s post-process output. This setting is part of the rendering system in Unreal Engine 5, specifically related to performance optimization techniques.
This setting variable is primarily used in the Renderer module of Unreal Engine, particularly in the Variable Rate Shading subsystem. Based on the callsites, it’s implemented in the ContrastAdaptiveImageGenerator.cpp file, which is part of the VariableRateShading feature.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0, meaning it’s disabled by default. Developers can change this value at runtime or in configuration files.
The associated variable CVarCASContrastAdaptiveShading directly interacts with r.VRS.ContrastAdaptiveShading. They share the same value and purpose. This variable is used in the IsEnabled() function of the FContrastAdaptiveImageGenerator class to determine if the feature should be active.
Developers must be aware that:
- This feature is render thread safe, as indicated by the ECVF_RenderThreadSafe flag.
- It’s a boolean-like setting (0 for off, any positive value for on).
- It affects the rendering performance and quality, so it should be tested thoroughly in different scenarios.
Best practices when using this variable include:
- Enable it only when targeting hardware that supports Variable Rate Shading.
- Test the performance impact in various scenes and with different content types.
- Consider the trade-off between performance gain and potential quality loss.
- Use in conjunction with other VRS settings for optimal results.
Regarding the associated variable CVarCASContrastAdaptiveShading:
The purpose of CVarCASContrastAdaptiveShading is identical to r.VRS.ContrastAdaptiveShading. It’s the internal representation of the console variable in the C++ code.
This variable is used directly in the Renderer module, specifically in the ContrastAdaptiveImageGenerator class. It’s queried in the IsEnabled() function to determine if the Contrast Adaptive Shading feature should be active.
The value is set through the console variable system, initialized with the same default value (0) as r.VRS.ContrastAdaptiveShading.
CVarCASContrastAdaptiveShading interacts directly with r.VRS.ContrastAdaptiveShading, effectively serving as its in-code representation.
Developers should be aware that this variable is accessed on the render thread (GetValueOnRenderThread()), which is important for thread safety considerations.
Best practices for using CVarCASContrastAdaptiveShading align with those for r.VRS.ContrastAdaptiveShading, as they represent the same setting. Developers should primarily interact with the r.VRS.ContrastAdaptiveShading console variable rather than directly manipulating CVarCASContrastAdaptiveShading in code, unless there’s a specific need to do so.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/ContrastAdaptiveImageGenerator.cpp:32
Scope: file
Source code excerpt:
TAutoConsoleVariable<int32> CVarCASContrastAdaptiveShading(
TEXT("r.VRS.ContrastAdaptiveShading"),
0,
TEXT("Enables using Variable Rate Shading based on the luminance from the previous frame's post process output \n"),
ECVF_RenderThreadSafe);
TAutoConsoleVariable<float> CVarCASEdgeThreshold(
TEXT("r.VRS.ContrastAdaptiveShading.EdgeThreshold"),
0.2,
#Associated Variable and Callsites
This variable is associated with another variable named CVarCASContrastAdaptiveShading
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/ContrastAdaptiveImageGenerator.cpp:31
Scope: file
Source code excerpt:
*/
TAutoConsoleVariable<int32> CVarCASContrastAdaptiveShading(
TEXT("r.VRS.ContrastAdaptiveShading"),
0,
TEXT("Enables using Variable Rate Shading based on the luminance from the previous frame's post process output \n"),
ECVF_RenderThreadSafe);
TAutoConsoleVariable<float> CVarCASEdgeThreshold(
TEXT("r.VRS.ContrastAdaptiveShading.EdgeThreshold"),
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/ContrastAdaptiveImageGenerator.cpp:535
Scope (from outer to inner):
file
function bool FContrastAdaptiveImageGenerator::IsEnabled
Source code excerpt:
bool FContrastAdaptiveImageGenerator::IsEnabled() const
{
return CVarCASContrastAdaptiveShading.GetValueOnRenderThread() > 0;
}
bool FContrastAdaptiveImageGenerator::IsSupportedByView(const FSceneView& View) const
{
EDisplayOutputFormat DisplayOutputFormat = GetDisplayOutputFormat(View);
const bool bCompatibleWithOutputType = (DisplayOutputFormat == EDisplayOutputFormat::SDR_sRGB) || IsHDR10(DisplayOutputFormat);