r.VelocityOutputPass

r.VelocityOutputPass

#Overview

name: r.VelocityOutputPass

This variable is created as a Console Variable (cvar).

It is referenced in 8 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.VelocityOutputPass is to control when and how the velocity buffer is written in the rendering pipeline. This setting variable is primarily used in the rendering system of Unreal Engine 5.

The Unreal Engine subsystems that rely on this setting variable are:

  1. Renderer module
  2. RenderCore module
  3. Engine module
  4. TargetPlatform module

The value of this variable is set through the console variable system, initialized with a default value of 0. It can be changed at runtime, but changing it causes a full shader recompile.

This variable interacts with other variables and systems:

  1. It’s associated with CVarVelocityOutputPass, which shares the same value.
  2. It interacts with CVarVelocityEnableVertexDeformation in determining if vertex deformation outputs velocity.
  3. It affects the behavior of depth pass and base pass rendering.

Developers must be aware of the following when using this variable:

  1. The variable has three possible values (0, 1, 2), each with different implications for rendering performance and quality.
  2. Changing this value at runtime will trigger a full shader recompile, which can be expensive.
  3. The choice of value can affect the rendering pipeline structure, potentially impacting performance and compatibility with other rendering features.

Best practices when using this variable include:

  1. Consider the target platform and rendering path (forward or deferred) when choosing a value.
  2. Be cautious about changing this value at runtime due to the shader recompile cost.
  3. Test thoroughly with different values to ensure compatibility with other rendering features in your project.

Regarding the associated variable CVarVelocityOutputPass:

The purpose of CVarVelocityOutputPass is to serve as the actual console variable implementation of r.VelocityOutputPass. It’s used internally by the engine to access and modify the velocity output pass setting.

This variable is primarily used in the Renderer module, specifically in velocity rendering-related functions.

The value of CVarVelocityOutputPass is set when the console variable is registered, with the same default value and description as r.VelocityOutputPass.

CVarVelocityOutputPass directly interacts with r.VelocityOutputPass, as they represent the same setting. It’s also used in conjunction with other rendering-related variables to determine velocity rendering behavior.

Developers should be aware that CVarVelocityOutputPass is the internal representation of the r.VelocityOutputPass setting, and changes to one will affect the other.

Best practices for CVarVelocityOutputPass are similar to those for r.VelocityOutputPass, as they represent the same setting. Developers should primarily interact with r.VelocityOutputPass rather than CVarVelocityOutputPass directly, unless they’re working on low-level engine modifications.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VelocityRendering.cpp:28

Scope: file

Source code excerpt:

// Changing this causes a full shader recompile
static TAutoConsoleVariable<int32> CVarVelocityOutputPass(
	TEXT("r.VelocityOutputPass"),
	0,
	TEXT("When to write velocity buffer.\n") \
	TEXT(" 0: Renders during the depth pass. This splits the depth pass into 2 phases: with and without velocity.\n") \
	TEXT(" 1: Renders during the regular base pass. This adds an extra GBuffer target during base pass rendering.") \
	TEXT(" 2: Renders after the regular base pass.\n"), \
	ECVF_ReadOnly | ECVF_RenderThreadSafe);

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Private/TargetPlatformBase.cpp:29

Scope (from outer to inner):

file
function     bool FTargetPlatformBase::UsesBasePassVelocity

Source code excerpt:

bool FTargetPlatformBase::UsesBasePassVelocity() const
{
	static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VelocityOutputPass"));
	return CVar ? (CVar->GetInt() == 1) : false;
}

bool FTargetPlatformBase::VelocityEncodeDepth() const
{
	return true;

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Private/TargetPlatformSettingsBase.cpp:18

Scope (from outer to inner):

file
function     bool FTargetPlatformSettingsBase::UsesBasePassVelocity

Source code excerpt:

bool FTargetPlatformSettingsBase::UsesBasePassVelocity() const
{
	static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VelocityOutputPass"));
	return CVar ? (CVar->GetInt() == 1) : false;
}

bool FTargetPlatformSettingsBase::VelocityEncodeDepth() const
{
	return true;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PrimitiveSceneProxy.cpp:203

Scope (from outer to inner):

file
function     static bool VertexDeformationOutputsVelocity

Source code excerpt:

static bool VertexDeformationOutputsVelocity()
{
	static const auto CVarVelocityOutputPass = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VelocityOutputPass"));
	const bool bVertexDeformationOutputsVelocityDefault = CVarVelocityOutputPass && CVarVelocityOutputPass->GetInt() != 2;
	const int32 VertexDeformationOutputsVelocity = CVarVelocityEnableVertexDeformation.GetValueOnAnyThread();
	return VertexDeformationOutputsVelocity == 1 || (VertexDeformationOutputsVelocity == 2 && bVertexDeformationOutputsVelocityDefault);
}

static FBoxSphereBounds PadBounds(const FBoxSphereBounds& InBounds, float PadAmount)

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:1478

Scope (from outer to inner):

file
function     bool IsUsingBasePassVelocity

Source code excerpt:

bool IsUsingBasePassVelocity(const FStaticShaderPlatform Platform)
{
	static FShaderPlatformCachedIniValue<int32> PerPlatformCVar(TEXT("r.VelocityOutputPass"));
	// Writing velocity in base pass is disabled for desktop forward because it may use MSAA (runtime-settable setting) and Velocity isn't a multisample texture.
	// TSR or vr.AllowMotionBlurInVR=1 case aren't recommended for Desktop Forward renderer, and if enabled, cause a separate Velocity pass.
	if (IsMobilePlatform(Platform) || IsForwardShadingEnabled(Platform))
	{
		return false;
	}

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PrimitiveSceneProxy.cpp:203

Scope (from outer to inner):

file
function     static bool VertexDeformationOutputsVelocity

Source code excerpt:

static bool VertexDeformationOutputsVelocity()
{
	static const auto CVarVelocityOutputPass = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VelocityOutputPass"));
	const bool bVertexDeformationOutputsVelocityDefault = CVarVelocityOutputPass && CVarVelocityOutputPass->GetInt() != 2;
	const int32 VertexDeformationOutputsVelocity = CVarVelocityEnableVertexDeformation.GetValueOnAnyThread();
	return VertexDeformationOutputsVelocity == 1 || (VertexDeformationOutputsVelocity == 2 && bVertexDeformationOutputsVelocityDefault);
}

static FBoxSphereBounds PadBounds(const FBoxSphereBounds& InBounds, float PadAmount)
{

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VelocityRendering.cpp:27

Scope: file

Source code excerpt:


// Changing this causes a full shader recompile
static TAutoConsoleVariable<int32> CVarVelocityOutputPass(
	TEXT("r.VelocityOutputPass"),
	0,
	TEXT("When to write velocity buffer.\n") \
	TEXT(" 0: Renders during the depth pass. This splits the depth pass into 2 phases: with and without velocity.\n") \
	TEXT(" 1: Renders during the regular base pass. This adds an extra GBuffer target during base pass rendering.") \
	TEXT(" 2: Renders after the regular base pass.\n"), \

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VelocityRendering.cpp:409

Scope (from outer to inner):

file
function     bool FVelocityRendering::DepthPassCanOutputVelocity

Source code excerpt:

bool FVelocityRendering::DepthPassCanOutputVelocity(ERHIFeatureLevel::Type FeatureLevel)
{
	static bool bRequestedDepthPassVelocity = CVarVelocityOutputPass.GetValueOnAnyThread() == 0;
	const bool bMSAAEnabled = GetDefaultMSAACount(FeatureLevel) > 1;
	return !bMSAAEnabled && bRequestedDepthPassVelocity;
}

bool FVelocityRendering::BasePassCanOutputVelocity(EShaderPlatform ShaderPlatform)
{