r.Velocity.EnableVertexDeformation

r.Velocity.EnableVertexDeformation

#Overview

name: r.Velocity.EnableVertexDeformation

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.Velocity.EnableVertexDeformation is to control whether materials with World Position Offset and/or World Displacement output velocities during the velocity pass, even when the associated actor has not moved. This setting is primarily used in the rendering system, specifically for velocity rendering and primitive scene proxies.

This setting variable is relied upon by the Engine and Renderer modules of Unreal Engine. It’s particularly important for the velocity pass in rendering and for managing primitive scene proxies.

The value of this variable is set through a console variable, which can be adjusted at runtime. It has three possible values: 0 (Off), 1 (On), and 2 (Auto, which is the default).

The associated variable VertexDeformationOutputsVelocity interacts closely with r.Velocity.EnableVertexDeformation. It’s an enum property in the URendererSettings class that corresponds to the console variable.

Developers must be aware that enabling this feature can incur a performance cost, especially when the VelocityPass is set to ‘Write after base pass’. This performance impact is more significant if many objects are using World Position Offset, such as in a forest of trees.

Best practices when using this variable include:

  1. Use the Auto setting (2) unless you have specific performance or visual requirements.
  2. Be cautious when enabling this feature in scenes with many objects using World Position Offset.
  3. Consider the trade-off between visual fidelity and performance, especially on lower-end hardware.

Regarding the associated variable VertexDeformationOutputsVelocity:

The purpose of VertexDeformationOutputsVelocity is to provide a user-friendly way to control the same functionality as r.Velocity.EnableVertexDeformation through the Unreal Engine editor interface.

This variable is part of the URendererSettings class, which is used to configure various rendering options in the engine.

The value of this variable is set through the editor interface, typically in the project settings under the Rendering category.

It interacts directly with r.Velocity.EnableVertexDeformation, effectively sharing the same value and purpose.

Developers should be aware that changes to this setting in the editor will affect the corresponding console variable and vice versa.

Best practices for using VertexDeformationOutputsVelocity include:

  1. Use it in conjunction with other rendering settings to achieve the desired balance between visual quality and performance.
  2. Consider the impact on different hardware configurations when adjusting this setting.
  3. Test thoroughly after making changes, especially in scenes with complex vertex deformations or numerous objects using World Position Offset.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/RendererSettings.h:805

Scope (from outer to inner):

file
class        class URendererSettings : public UDeveloperSettings

Source code excerpt:

	UPROPERTY(config, EditAnywhere, Category=Optimizations, meta=(
		DisplayName="Output velocities due to vertex deformation",
		ConsoleVariable="r.Velocity.EnableVertexDeformation",
		ToolTip="Enables materials with World Position Offset and/or World Displacement to output velocities during the velocity pass even when the actor has not moved. \nIf the VelocityPass is set to 'Write after base pass' this can incur a performance cost due to additional draw calls. \nThat performance cost is higher if many objects are using World Position Offset. A forest of trees for example." ))
	TEnumAsByte<EVertexDeformationOutputsVelocity::Type> VertexDeformationOutputsVelocity;

	UPROPERTY(config, EditAnywhere, Category=Optimizations, meta=(
		ConsoleVariable="r.SelectiveBasePassOutputs", DisplayName="Selectively output to the GBuffer rendertargets",
		ToolTip="Enables not exporting to the GBuffer rendertargets that are not relevant. Changing this setting requires restarting the editor.",

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarVelocityEnableVertexDeformation(
	TEXT("r.Velocity.EnableVertexDeformation"),
	2,
	TEXT("Enables materials with World Position Offset and/or World Displacement to output velocities during velocity pass even when the actor has not moved. \n")
	TEXT("0=Off, 1=On, 2=Auto(Default). \n")
	TEXT("Auto setting is off if r.VelocityOutputPass=2, or else on. \n")
	TEXT("When r.VelocityOutputPass=2 this can incur a performance cost due to additional draw calls."),
	FConsoleVariableDelegate::CreateLambda([](IConsoleVariable* InVariable)

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/RendererSettings.h:807

Scope (from outer to inner):

file
class        class URendererSettings : public UDeveloperSettings

Source code excerpt:

		ConsoleVariable="r.Velocity.EnableVertexDeformation",
		ToolTip="Enables materials with World Position Offset and/or World Displacement to output velocities during the velocity pass even when the actor has not moved. \nIf the VelocityPass is set to 'Write after base pass' this can incur a performance cost due to additional draw calls. \nThat performance cost is higher if many objects are using World Position Offset. A forest of trees for example." ))
	TEnumAsByte<EVertexDeformationOutputsVelocity::Type> VertexDeformationOutputsVelocity;

	UPROPERTY(config, EditAnywhere, Category=Optimizations, meta=(
		ConsoleVariable="r.SelectiveBasePassOutputs", DisplayName="Selectively output to the GBuffer rendertargets",
		ToolTip="Enables not exporting to the GBuffer rendertargets that are not relevant. Changing this setting requires restarting the editor.",
		ConfigRestartRequired=true))
	uint32 bSelectiveBasePassOutputs:1;

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

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)
{
	FBoxSphereBounds Result = InBounds;
	Result.BoxExtent += FVector(PadAmount);

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

Scope: file

Source code excerpt:


	bAlwaysHasVelocity = CVarVelocityForceOutput.GetValueOnAnyThread();
	if (!bAlwaysHasVelocity && InProxyDesc.SupportsWorldPositionOffsetVelocity() && VertexDeformationOutputsVelocity() && bAnyMaterialHasWorldPositionOffset)
	{
		bHasWorldPositionOffsetVelocity = true;
	}
}

bool FPrimitiveSceneProxy::OnLevelAddedToWorld_RenderThread()

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

Scope (from outer to inner):

file
function     void FOpaqueVelocityMeshProcessor::CollectPSOInitializers

Source code excerpt:

	const EShaderPlatform ShaderPlatform = GetFeatureLevelShaderPlatform(FeatureLevel);
	bool bDrawsVelocity = (PreCacheParams.Mobility == EComponentMobility::Movable || PreCacheParams.Mobility == EComponentMobility::Stationary);
	bDrawsVelocity = bDrawsVelocity || (/*VertexDeformationOutputsVelocity() &&*/ (PreCacheParams.bAnyMaterialHasWorldPositionOffset || Material.MaterialUsesWorldPositionOffset_GameThread()));
	if (!PrimitiveCanHaveVelocity(ShaderPlatform, bDrawsVelocity, PreCacheParams.bStaticLighting))
	{
		return;
	}

	const FMaterial* EffectiveMaterial = &Material;

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

Scope: file

Source code excerpt:

	);

static TAutoConsoleVariable<int32> CVarVelocityEnableVertexDeformation(
	TEXT("r.Velocity.EnableVertexDeformation"),
	2,
	TEXT("Enables materials with World Position Offset and/or World Displacement to output velocities during velocity pass even when the actor has not moved. \n")
	TEXT("0=Off, 1=On, 2=Auto(Default). \n")
	TEXT("Auto setting is off if r.VelocityOutputPass=2, or else on. \n")
	TEXT("When r.VelocityOutputPass=2 this can incur a performance cost due to additional draw calls."),

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

Scope (from outer to inner):

file
function     static bool VertexDeformationOutputsVelocity

Source code excerpt:

	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)
{
	FBoxSphereBounds Result = InBounds;