r.PathTracing.Denoiser

r.PathTracing.Denoiser

#Overview

name: r.PathTracing.Denoiser

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.PathTracing.Denoiser is to control the denoising of path-traced output in Unreal Engine’s rendering system. This setting variable is primarily used in the path tracing and denoising subsystems of the engine’s rendering module.

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

  1. The Renderer module, specifically the path tracing and denoising components.
  2. The OpenImageDenoise plugin, which is an experimental denoising solution.

The value of this variable is set through the console variable system. It can be set programmatically or through the console, and it’s also accessible via PostProcessVolume settings in the engine.

This variable interacts with the associated variable CVarPathTracingDenoiser, which is the actual TAutoConsoleVariable instance that stores and manages the value.

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

  1. The default value is -1, which means the setting is inherited from the PostProcessVolume.
  2. A value of 0 disables the denoiser, while 1 enables it (if a denoiser plugin is active).
  3. The setting is render thread safe, meaning it can be changed at runtime without causing threading issues.

Best practices when using this variable include:

  1. Use PostProcessVolume to control this setting in most cases, allowing for more fine-grained control in different areas of your game.
  2. Only override this setting globally if you have a specific reason to enable or disable denoising for the entire project.
  3. Be aware of the performance implications of enabling or disabling the denoiser, especially on lower-end hardware.

Regarding the associated variable CVarPathTracingDenoiser:

The purpose of CVarPathTracingDenoiser is to provide a programmatic interface for the r.PathTracing.Denoiser setting. It’s an instance of TAutoConsoleVariable, which is Unreal Engine’s way of exposing settings to both the code and the console system.

This variable is used directly in the Renderer module to determine the denoising mode. It’s accessed in the GetPathTracingDenoiserMode function, which is likely called by various parts of the rendering pipeline that need to know whether denoising should be applied.

The value of CVarPathTracingDenoiser is set when the console variable is registered, but it can be changed at runtime through console commands or programmatically.

Developers should be aware that changes to CVarPathTracingDenoiser will immediately affect the rendering pipeline’s behavior. They should also note that this variable is accessed on the render thread, so any modifications should be done with consideration for potential threading issues.

Best practices for using CVarPathTracingDenoiser include:

  1. Use the provided GetPathTracingDenoiserMode function to access the value, as it handles the fallback to PostProcessVolume settings.
  2. If you need to change the value programmatically, use the appropriate thread-safe methods provided by the console variable system.
  3. Consider exposing this setting in your game’s graphics options menu to allow users to control denoising based on their hardware capabilities.

#References in C++ code

#Callsites

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

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

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:


	TAutoConsoleVariable<int32> CVarPathTracingDenoiser(
		TEXT("r.PathTracing.Denoiser"),
		-1,
		TEXT("Enable denoising of the path traced output (if a denoiser plugin is active) (default = -1 (driven by postprocesing volume))\n")
		TEXT("-1: inherit from PostProcessVolume\n")
		TEXT("0: disable denoiser\n")
		TEXT("1: enable denoiser (if a denoiser plugin is active)\n"),
		ECVF_RenderThreadSafe

#Loc: <Workspace>/Engine/Plugins/Experimental/OpenImageDenoise/Source/OpenImageDenoise/Private/Plugin.cpp:167

Scope (from outer to inner):

file
function     static void Denoise

Source code excerpt:

static void Denoise(FRHICommandListImmediate& RHICmdList, FRHITexture* ColorTex, FRHITexture* AlbedoTex, FRHITexture* NormalTex, FRHITexture* OutputTex, FRHIGPUMask GPUMask)
{
	static IConsoleVariable* DenoiseModeCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.PathTracing.Denoiser"));

	const int DenoiseModeCVarValue = DenoiseModeCVar ? DenoiseModeCVar->GetInt() : -1;
	const EDenoiseMode DenoiseMode = DenoiseModeCVarValue >= 0 ? EDenoiseMode(DenoiseModeCVarValue) : EDenoiseMode::DEFAULT;

#if WITH_EDITOR
	// NOTE: the time will include the transfer from GPU to CPU which will include waiting for the GPU pipeline to complete

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracingSpatialTemporalDenoising.cpp:26

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:

namespace {

	TAutoConsoleVariable<int32> CVarPathTracingDenoiser(
		TEXT("r.PathTracing.Denoiser"),
		-1,
		TEXT("Enable denoising of the path traced output (if a denoiser plugin is active) (default = -1 (driven by postprocesing volume))\n")
		TEXT("-1: inherit from PostProcessVolume\n")
		TEXT("0: disable denoiser\n")
		TEXT("1: enable denoiser (if a denoiser plugin is active)\n"),

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracingSpatialTemporalDenoising.cpp:246

Scope (from outer to inner):

file
function     int GetPathTracingDenoiserMode

Source code excerpt:

int GetPathTracingDenoiserMode(const FViewInfo& View)
{
	int DenoiserMode = CVarPathTracingDenoiser.GetValueOnRenderThread();
	if (DenoiserMode < 0)
	{
		DenoiserMode = View.FinalPostProcessSettings.PathTracingEnableDenoiser;
	}
	return DenoiserMode;
}