r.ClearSceneMethod
r.ClearSceneMethod
#Overview
name: r.ClearSceneMethod
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Select how the g-buffer is cleared in game mode (only affects deferred shading).\n 0: No clear\n 1: RHIClear (default)\n 2: Quad at max z
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.ClearSceneMethod is to control how the g-buffer is cleared in game mode, specifically for deferred shading rendering.
This setting variable is primarily used in the rendering system of Unreal Engine 5. Based on the callsites, it’s utilized in the BasePassRendering module, which is responsible for rendering the base pass of the scene.
The value of this variable is set through the console variable system, as indicated by the TAutoConsoleVariable declaration in ConsoleManager.cpp. It can also be configured through the RendererSettings class, which suggests it can be set in the project settings or through configuration files.
The r.ClearSceneMethod variable interacts with other rendering-related variables and systems, particularly those involved in the base pass rendering and g-buffer management.
Developers should be aware that:
- This variable only affects deferred shading.
- It has three possible values: 0 (No clear), 1 (RHIClear, default), and 2 (Quad at max z).
- The setting can impact rendering performance and visual quality.
Best practices when using this variable include:
- Use the default value (1) unless there’s a specific need to change it.
- When optimizing performance, experiment with different values to find the best balance between rendering speed and visual quality for your specific project.
- Be cautious when changing this value, as it can affect the entire rendering pipeline.
- Test thoroughly in various scenarios when modifying this setting, as its effects may not be immediately apparent in all situations.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/HAL/ConsoleManager.cpp:3594
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarSetClearSceneMethod(
TEXT("r.ClearSceneMethod"),
1,
TEXT("Select how the g-buffer is cleared in game mode (only affects deferred shading).\n"
" 0: No clear\n"
" 1: RHIClear (default)\n"
" 2: Quad at max z"),
ECVF_RenderThreadSafe);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/RendererSettings.h:793
Scope (from outer to inner):
file
class class URendererSettings : public UDeveloperSettings
Source code excerpt:
UPROPERTY(config, EditAnywhere, Category=Optimizations, meta=(
ConsoleVariable="r.ClearSceneMethod",DisplayName="Clear Scene",
ToolTip="Select how the g-buffer is cleared in game mode (only affects deferred shading)."))
TEnumAsByte<EClearSceneOptions::Type> ClearSceneMethod;
UPROPERTY(config, EditAnywhere, Category = Optimizations, meta = (
ConsoleVariable = "r.VelocityOutputPass", DisplayName = "Velocity Pass",
ToolTip = "When to write velocity buffer. Changing this setting requires restarting the editor.",
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/BasePassRendering.cpp:994
Scope (from outer to inner):
file
function void FDeferredShadingSceneRenderer::RenderBasePass
Source code excerpt:
const bool bEnableParallelBasePasses = GRHICommandList.UseParallelAlgorithms() && CVarParallelBasePass.GetValueOnRenderThread();
static const auto ClearMethodCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.ClearSceneMethod"));
bool bRequiresRHIClear = true;
bool bRequiresFarZQuadClear = false;
if (ClearMethodCVar)
{
int32 ClearMethod = ClearMethodCVar->GetValueOnRenderThread();