r.Ortho.CalculateDepthThicknessScaling

r.Ortho.CalculateDepthThicknessScaling

#Overview

name: r.Ortho.CalculateDepthThicknessScaling

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.Ortho.CalculateDepthThicknessScaling is to control the automatic calculation of depth thickness scaling for orthographic projections in the rendering system. This setting is part of Unreal Engine’s view and projection management subsystem.

The Unreal Engine subsystem that relies on this setting variable is primarily the rendering system, specifically the part that handles view and projection matrices for orthographic views. This can be seen from its usage in the SceneView.cpp file, which is part of the Engine module.

The value of this variable is set through a console variable (CVar) system. It’s defined as a TAutoConsoleVariable with a default value of 1 (enabled).

This variable interacts with another variable named r.Ortho.DepthThicknessScale. When r.Ortho.CalculateDepthThicknessScaling is disabled (set to 0), the system uses the value specified by r.Ortho.DepthThicknessScale instead.

Developers must be aware that this variable affects the depth testing accuracy in orthographic projections. When enabled, it automatically derives the depth thickness test scale from the difference between the near and far planes. This can potentially improve depth precision in orthographic views.

Best practices when using this variable include:

  1. Leave it enabled (default value of 1) unless there’s a specific reason to manually control the depth thickness scale.
  2. If disabling it, ensure that r.Ortho.DepthThicknessScale is set to an appropriate value for your scene’s scale.
  3. Be aware of its impact on rendering performance and depth precision when modifying it.

Regarding the associated variable CVarOrthoCalculateDepthThicknessScaling:

The purpose of CVarOrthoCalculateDepthThicknessScaling is to serve as the internal representation of the r.Ortho.CalculateDepthThicknessScaling console variable within the engine’s C++ code.

This variable is used directly in the Engine module, specifically in the FViewMatrices::Init function, to determine whether to calculate the PerProjectionDepthThicknessScale automatically.

The value of this variable is set when the r.Ortho.CalculateDepthThicknessScaling console variable is modified.

It interacts directly with the InvProjectionMatrix and PerProjectionDepthThicknessScale variables in the view matrices calculation.

Developers should be aware that this variable is accessed using the GetValueOnAnyThread() method, which means its value can be read from any thread.

Best practices for using this variable include:

  1. Use it for runtime checks of the r.Ortho.CalculateDepthThicknessScaling setting.
  2. Be cautious when accessing it from multiple threads to avoid potential race conditions.
  3. Remember that changes to this variable will affect the next frame’s view matrix calculations.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SceneView.cpp:318

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarOrthoCalculateDepthThicknessScaling(
	TEXT("r.Ortho.CalculateDepthThicknessScaling"),
	1,
	TEXT("Whether to automatically derive the depth thickness test scale from the Near/FarPlane difference.\n")
	TEXT("0: Disabled (use scaling specified by r.Ortho.DepthThicknessScale)\n")
	TEXT("1: Enabled (default)"),
	ECVF_Scalability | ECVF_RenderThreadSafe);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SceneView.cpp:317

Scope: file

Source code excerpt:

	ECVF_Default);

static TAutoConsoleVariable<int32> CVarOrthoCalculateDepthThicknessScaling(
	TEXT("r.Ortho.CalculateDepthThicknessScaling"),
	1,
	TEXT("Whether to automatically derive the depth thickness test scale from the Near/FarPlane difference.\n")
	TEXT("0: Disabled (use scaling specified by r.Ortho.DepthThicknessScale)\n")
	TEXT("1: Enabled (default)"),
	ECVF_Scalability | ECVF_RenderThreadSafe);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SceneView.cpp:761

Scope (from outer to inner):

file
function     void FViewMatrices::Init

Source code excerpt:

		ProjectionScale = FVector2D(ScreenXScale, 1.0f);

		if (CVarOrthoCalculateDepthThicknessScaling.GetValueOnAnyThread())
		{
			int8 Exponent = -FMath::Clamp(FMath::LogX(10, FMath::Abs(InvProjectionMatrix.M[2][2])), 0, 9);
			PerProjectionDepthThicknessScale = FMath::Pow(10, (float)Exponent);
		}
		else
		{