r.VRS.ContrastAdaptiveShading.EdgeThreshold
r.VRS.ContrastAdaptiveShading.EdgeThreshold
#Overview
name: r.VRS.ContrastAdaptiveShading.EdgeThreshold
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.EdgeThreshold is to control the edge detection sensitivity in the Variable Rate Shading (VRS) system, specifically for Contrast Adaptive Shading (CAS). This setting is part of Unreal Engine 5’s rendering system, particularly the VRS feature which aims to optimize performance by varying the shading rate across different parts of the image.
This setting variable is primarily used in the Renderer module of Unreal Engine 5, specifically within the Variable Rate Shading subsystem. It’s utilized in the ContrastAdaptiveImageGenerator.cpp file, which is responsible for generating the shading rate image based on contrast information.
The value of this variable is set through a console variable (CVarCASEdgeThreshold) with a default value of 0.2. It can be modified at runtime through console commands or project settings.
The variable interacts closely with other VRS-related settings, particularly CVarCASConservativeEdgeThreshold. It’s also affected by a correction value (CVarCAS_HDR10CorrectionMultiplier) when HDR10 is in use.
Developers should be aware that this threshold directly impacts the sensitivity of edge detection in the VRS system. A lower value will result in more edges being detected, potentially leading to higher quality but less performance optimization. Conversely, a higher value will detect fewer edges, potentially improving performance at the cost of visual quality.
Best practices when using this variable include:
- Carefully balancing it with other VRS settings for optimal performance and visual quality.
- Testing different values in various scenarios to find the best setting for your specific game or application.
- Considering the impact of HDR when adjusting this value, as it’s affected by the HDR10 correction multiplier.
Regarding the associated variable CVarCASEdgeThreshold:
The purpose of CVarCASEdgeThreshold is to provide a programmatic interface to the r.VRS.ContrastAdaptiveShading.EdgeThreshold setting. It’s used within the engine code to access and modify the edge threshold value.
This variable is used in the same Renderer module and VRS subsystem as the console variable. It’s primarily accessed in the FCalculateShadingRateImageCS class, which is responsible for calculating the shading rate image.
The value of CVarCASEdgeThreshold is set when the console variable is initialized and can be accessed or modified at runtime using the GetValueOnRenderThread() method.
CVarCASEdgeThreshold interacts directly with the HDR correction multiplier and is used in conjunction with the conservative edge threshold to calculate the final edge detection parameters.
Developers should be aware that modifying CVarCASEdgeThreshold will have the same effect as changing the console variable. It’s important to ensure that any runtime modifications are thread-safe, as indicated by the ECVF_RenderThreadSafe flag.
Best practices for using CVarCASEdgeThreshold include:
- Accessing it using GetValueOnRenderThread() when in render thread contexts.
- Considering the potential impact on performance and visual quality when modifying it.
- Coordinating any changes with other VRS settings for consistent results.
#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:37
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe);
TAutoConsoleVariable<float> CVarCASEdgeThreshold(
TEXT("r.VRS.ContrastAdaptiveShading.EdgeThreshold"),
0.2,
TEXT(""),
ECVF_RenderThreadSafe);
TAutoConsoleVariable<float> CVarCASConservativeEdgeThreshold(
TEXT("r.VRS.ContrastAdaptiveShading.ConservativeEdgeThreshold"),
0.1,
#Associated Variable and Callsites
This variable is associated with another variable named CVarCASEdgeThreshold
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/ContrastAdaptiveImageGenerator.cpp:36
Scope: file
Source code excerpt:
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,
TEXT(""),
ECVF_RenderThreadSafe);
TAutoConsoleVariable<float> CVarCASConservativeEdgeThreshold(
TEXT("r.VRS.ContrastAdaptiveShading.ConservativeEdgeThreshold"),
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/ContrastAdaptiveImageGenerator.cpp:119
Scope (from outer to inner):
file
class class FCalculateShadingRateImageCS : public FGlobalShader
function static void InitParameters
Source code excerpt:
Parameters.ViewRect = FVector4f(ViewRect.Min.X, ViewRect.Min.Y, ViewRect.Max.X, ViewRect.Max.Y);
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);