r.PathTracing.Override.Depth

r.PathTracing.Override.Depth

#Overview

name: r.PathTracing.Override.Depth

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.PathTracing.Override.Depth is to control whether the path tracing depth z should override the scene depth z in Unreal Engine’s rendering system. This setting is specifically related to the path tracing feature, which is a part of the engine’s advanced rendering capabilities.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically within the path tracing subsystem. Based on the callsites, it’s clear that this variable is utilized in the PathTracing.cpp file, which is responsible for implementing path tracing functionality.

The value of this variable is set through a console variable (CVar) system, which allows for runtime configuration. It’s initialized with a default value of 1, meaning the override is enabled by default.

The associated variable CVarpathTracingOverrideDepth directly interacts with r.PathTracing.Override.Depth. They share the same value and purpose, with CVarpathTracingOverrideDepth being the actual C++ variable used in the code to access the setting.

Developers must be aware that this variable affects the depth buffer used in rendering. When enabled (set to 1), it replaces the scene depth with the path tracing depth, which can impact how depth-dependent effects like Depth of Field (DOF) are rendered, especially for translucent materials.

Best practices when using this variable include:

  1. Understanding its impact on rendering, particularly for scenes with translucent materials.
  2. Testing scenes with both settings (0 and 1) to determine which produces better visual results for specific use cases.
  3. Being cautious when changing this setting, as it can affect the overall look of the rendered scene, especially in relation to depth-based post-processing effects.

Regarding the associated variable CVarpathTracingOverrideDepth:

The purpose of CVarpathTracingOverrideDepth is to provide a programmatic way to access and modify the r.PathTracing.Override.Depth setting within the C++ code of the engine.

This variable is used directly in the Renderer module, specifically in the path tracing implementation. It’s defined and used in the PathTracing.cpp file.

The value of CVarpathTracingOverrideDepth is set when the r.PathTracing.Override.Depth console variable is modified, either through code or via console commands.

CVarpathTracingOverrideDepth interacts directly with the depth stencil state in the rendering pipeline. When its value is non-zero, it causes the depth stencil state to be set to always write depth (CF_Always), otherwise, depth writing is disabled.

Developers should be aware that changes to this variable will immediately affect the rendering pipeline’s behavior regarding depth writing during path tracing.

Best practices for using CVarpathTracingOverrideDepth include:

  1. Accessing its value using the GetValueOnRenderThread() method to ensure thread-safe operations.
  2. Considering the performance implications of enabling or disabling depth override in different scenarios.
  3. Coordinating its use with other depth-related rendering settings for consistent results.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracing.cpp:374

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarpathTracingOverrideDepth(
	TEXT("r.PathTracing.Override.Depth"),
	1,
	TEXT("Override the scene depth z by the path tracing depth z")
	TEXT("0: off\n")
	TEXT("1: On (Default, translucent materials have better DOF with the post-process DOF.)\n"),
	ECVF_RenderThreadSafe
);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracing.cpp:373

Scope: file

Source code excerpt:

);

TAutoConsoleVariable<int32> CVarpathTracingOverrideDepth(
	TEXT("r.PathTracing.Override.Depth"),
	1,
	TEXT("Override the scene depth z by the path tracing depth z")
	TEXT("0: off\n")
	TEXT("1: On (Default, translucent materials have better DOF with the post-process DOF.)\n"),
	ECVF_RenderThreadSafe

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracing.cpp:3355

Scope: file

Source code excerpt:

	FRHIDepthStencilState* DepthStencilState = nullptr;

	if (CVarpathTracingOverrideDepth.GetValueOnRenderThread() != 0)
	{
		DepthStencilState = TStaticDepthStencilState<true, CF_Always>::GetRHI();
	}
	else
	{
		DepthStencilState = TStaticDepthStencilState<false, CF_Always>::GetRHI();