r.VRS.ContrastAdaptiveShading.ConservativeEdgeThreshold
r.VRS.ContrastAdaptiveShading.ConservativeEdgeThreshold
#Overview
name: r.VRS.ContrastAdaptiveShading.ConservativeEdgeThreshold
This variable is created as a Console Variable (cvar).
- type:
Var
- help: ``
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.VRS.ContrastAdaptiveShading.ConservativeEdgeThreshold is to control the contrast adaptive shading feature in Unreal Engine’s Variable Rate Shading (VRS) system. This setting is specifically used to define a conservative threshold for edge detection in the contrast adaptive shading algorithm.
This setting variable is primarily used in the Renderer module of Unreal Engine, specifically within the Variable Rate Shading subsystem. It’s part of the Contrast Adaptive Shading (CAS) feature, which is a technique used to optimize rendering performance by adjusting shading rates based on image content.
The value of this variable is set through the Unreal Engine console or configuration files. It’s defined as a TAutoConsoleVariable with a default value of 0.1.
This variable interacts closely with other VRS-related variables, particularly CVarCASEdgeThreshold and CVarCAS_HDR10CorrectionMultiplier. These variables work together to fine-tune the edge detection and shading rate calculation process.
Developers should be aware that this variable affects the performance-quality tradeoff in VRS. A higher value will result in more conservative edge detection, potentially improving image quality but reducing the performance benefits of VRS. Conversely, a lower value may increase performance but could lead to more noticeable artifacts in areas with subtle contrast changes.
Best practices when using this variable include:
- Carefully balancing it with other VRS settings for optimal performance and visual quality.
- Testing across a variety of scenes and viewing conditions to ensure consistent results.
- Considering platform-specific adjustments, as VRS behavior can vary between different graphics hardware.
Regarding the associated variable CVarCASConservativeEdgeThreshold:
The purpose of CVarCASConservativeEdgeThreshold is to provide a programmatic interface to the r.VRS.ContrastAdaptiveShading.ConservativeEdgeThreshold setting within the engine’s C++ code.
This variable is used directly in the Renderer module, specifically in the ContrastAdaptiveImageGenerator.cpp file. It’s part of the implementation of the Contrast Adaptive Shading feature in the Variable Rate Shading system.
The value of CVarCASConservativeEdgeThreshold is set when the r.VRS.ContrastAdaptiveShading.ConservativeEdgeThreshold console variable is initialized or modified.
It interacts with other variables in the CAS system, particularly in the FCalculateShadingRateImageCS class where it’s used alongside CVarCASEdgeThreshold and CVarCAS_HDR10CorrectionMultiplier to calculate shading rates.
Developers should be aware that this variable is accessed on the render thread (GetValueOnRenderThread()), which is important for thread safety in rendering code.
Best practices for using CVarCASConservativeEdgeThreshold include:
- Ensuring any modifications are thread-safe and done at appropriate times in the rendering pipeline.
- Using it consistently with other VRS-related variables for coherent behavior.
- Considering performance implications when frequently accessing or modifying this value, as it may impact render thread performance.
#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:42
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe);
TAutoConsoleVariable<float> CVarCASConservativeEdgeThreshold(
TEXT("r.VRS.ContrastAdaptiveShading.ConservativeEdgeThreshold"),
0.1,
TEXT(""),
ECVF_RenderThreadSafe);
TAutoConsoleVariable<float> CVarCAS_HDR10CorrectionMultiplier(
TEXT("r.VRS.ContrastAdaptiveShading.HDR10CorrectionMultiplier"),
0.55,
#Associated Variable and Callsites
This variable is associated with another variable named CVarCASConservativeEdgeThreshold
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/ContrastAdaptiveImageGenerator.cpp:41
Scope: file
Source code excerpt:
TEXT(""),
ECVF_RenderThreadSafe);
TAutoConsoleVariable<float> CVarCASConservativeEdgeThreshold(
TEXT("r.VRS.ContrastAdaptiveShading.ConservativeEdgeThreshold"),
0.1,
TEXT(""),
ECVF_RenderThreadSafe);
TAutoConsoleVariable<float> CVarCAS_HDR10CorrectionMultiplier(
TEXT("r.VRS.ContrastAdaptiveShading.HDR10CorrectionMultiplier"),
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/ContrastAdaptiveImageGenerator.cpp:120
Scope (from outer to inner):
file
class class FCalculateShadingRateImageCS : public FGlobalShader
function static void InitParameters
Source code excerpt:
const float cEdgeThresholdCorrectionValue = bIsHDR10 ? CVarCAS_HDR10CorrectionMultiplier.GetValueOnRenderThread() : 1.0;
Parameters.EdgeThreshold = cEdgeThresholdCorrectionValue * CVarCASEdgeThreshold.GetValueOnRenderThread();
Parameters.ConservativeEdgeThreshold = cEdgeThresholdCorrectionValue * CVarCASConservativeEdgeThreshold.GetValueOnRenderThread();
Parameters.HardwareShadingRateImage = HardwareShadingRateImage;
Parameters.SoftwareShadingRateImage = SoftwareShadingRateImage;
}
};
IMPLEMENT_GLOBAL_SHADER(FCalculateShadingRateImageCS, "/Engine/Private/VariableRateShading/VRSShadingRateCalculate.usf", "CalculateShadingRateImage", SF_Compute);