r.DisableDistortion

r.DisableDistortion

#Overview

name: r.DisableDistortion

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.DisableDistortion is to control whether distortion effects are rendered in the Unreal Engine. This setting variable is primarily used in the rendering system to manage visual distortion effects.

The Unreal Engine’s renderer subsystem relies on this setting variable, specifically within the distortion rendering module. This can be seen from the file locations where it’s referenced: DistortionRendering.cpp and MobileDistortionPass.cpp.

The value of this variable is set through the console variable system. It’s defined as a TAutoConsoleVariable with a default value of 0, meaning distortion is enabled by default. Users can change this value at runtime using console commands.

This variable interacts with other rendering-related variables, particularly those related to refraction quality. For example, in the ShouldRenderDistortion function, it’s used in conjunction with the refraction quality check.

Developers must be aware that disabling distortion (by setting r.DisableDistortion to 1) can save memory by avoiding the allocation of a full-screen framebuffer. However, this will prevent all distortion effects from rendering, which could significantly impact the visual quality of certain scenes or effects.

Best practices when using this variable include:

  1. Only disable distortion if memory constraints are a serious concern or if distortion effects are not needed in the project.
  2. Consider the visual impact of disabling distortion before doing so, especially in scenes that rely heavily on these effects.
  3. If disabling distortion, ensure that no other parts of the rendering pipeline or game logic assume distortion effects are present.
  4. For mobile development, be aware that distortion requires SceneDepth information in the SceneColor.A channel, so disabling it might have additional implications for mobile rendering.
  5. Use in conjunction with other rendering settings to fine-tune performance and visual quality as needed.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistortionRendering.cpp:23

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarDisableDistortion(
	TEXT("r.DisableDistortion"),
	0,
	TEXT("Prevents distortion effects from rendering.  Saves a full-screen framebuffer's worth of memory."),
	ECVF_Default);

static TAutoConsoleVariable<int32> CVarRefractionBlur(
	TEXT("r.Refraction.Blur"),

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistortionRendering.cpp:258

Scope (from outer to inner):

file
function     bool FDeferredShadingSceneRenderer::ShouldRenderDistortion

Source code excerpt:

bool FDeferredShadingSceneRenderer::ShouldRenderDistortion() const
{
	static const auto DisableDistortionCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.DisableDistortion"));
	const bool bAllowDistortion = DisableDistortionCVar->GetValueOnAnyThread() != 1;

	if (GetRefractionQuality(ViewFamily) <= 0 || !bAllowDistortion)
	{
		return false;
	}

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MobileDistortionPass.cpp:23

Scope (from outer to inner):

file
function     bool IsMobileDistortionActive

Source code excerpt:

bool IsMobileDistortionActive(const FViewInfo& View)
{
	static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.DisableDistortion"));
	int32 DisableDistortion = CVar->GetInt();

	// Distortion on mobile requires SceneDepth information in SceneColor.A channel
	const EMobileHDRMode HDRMode = GetMobileHDRMode();
	const bool bVisiblePrims = View.ParallelMeshDrawCommandPasses[EMeshPass::Distortion].HasAnyDraw();