r.DiffuseIndirect.RayPerPixel

r.DiffuseIndirect.RayPerPixel

#Overview

name: r.DiffuseIndirect.RayPerPixel

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.DiffuseIndirect.RayPerPixel is to control the number of rays used per pixel in the diffuse indirect lighting calculation within Unreal Engine’s rendering system. This setting is crucial for balancing rendering quality and performance in global illumination effects.

This setting variable is primarily used by the rendering subsystem of Unreal Engine, specifically in the indirect lighting rendering module. Based on the callsites, it’s clear that this variable is utilized in the IndirectLightRendering.cpp file, which is part of the Renderer module.

The value of this variable is set through a console variable (CVar) system, which allows for runtime adjustment. It’s initialized with a default value of 6, as seen in the source code:

static TAutoConsoleVariable<int32> CVarDiffuseIndirectRayPerPixel(
	TEXT("r.DiffuseIndirect.RayPerPixel"), 6,
	TEXT("TODO(Guillaume)"),
	ECVF_RenderThreadSafe);

This variable interacts with the rendering pipeline, specifically in the SetupCommonDiffuseIndirectParameters function, where it’s used to determine the number of rays to cast per pixel:

int32 RayCountPerPixel = FMath::Clamp(
	int32(CVarDiffuseIndirectRayPerPixel.GetValueOnRenderThread()),
	1, HybridIndirectLighting::kMaxRayPerPixel);

Developers must be aware that this variable directly impacts rendering performance and quality. Higher values will produce more accurate indirect lighting but at the cost of increased rendering time and computational load.

Best practices when using this variable include:

  1. Adjusting it based on the specific needs of your scene and target hardware.
  2. Testing different values to find the optimal balance between quality and performance.
  3. Considering dynamic adjustment based on scene complexity or distance from the camera.

Regarding the associated variable CVarDiffuseIndirectRayPerPixel, it’s the actual console variable object that stores and manages the r.DiffuseIndirect.RayPerPixel setting. It’s defined using the TAutoConsoleVariable template, which is part of Unreal’s console variable system. This object provides thread-safe access to the variable’s value and allows for runtime modification of the setting.

When working with CVarDiffuseIndirectRayPerPixel, developers should:

  1. Use GetValueOnRenderThread() when accessing the value in render thread code.
  2. Be aware that changes to this variable will affect rendering in real-time.
  3. Consider exposing this setting in a user interface for easier tuning during development or even in final builds for performance optimization on different hardware.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/IndirectLightRendering.cpp:58

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarDiffuseIndirectRayPerPixel(
	TEXT("r.DiffuseIndirect.RayPerPixel"), 6, // TODO(Guillaume): Matches old Lumen hard code sampling pattern.
	TEXT("TODO(Guillaume)"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarDiffuseIndirectDenoiser(
	TEXT("r.DiffuseIndirect.Denoiser"), 1,
	TEXT("Denoising options (default = 1)"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/IndirectLightRendering.cpp:57

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarDiffuseIndirectRayPerPixel(
	TEXT("r.DiffuseIndirect.RayPerPixel"), 6, // TODO(Guillaume): Matches old Lumen hard code sampling pattern.
	TEXT("TODO(Guillaume)"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarDiffuseIndirectDenoiser(
	TEXT("r.DiffuseIndirect.Denoiser"), 1,

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/IndirectLightRendering.cpp:790

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::SetupCommonDiffuseIndirectParameters

Source code excerpt:


	int32 RayCountPerPixel = FMath::Clamp(
		int32(CVarDiffuseIndirectRayPerPixel.GetValueOnRenderThread()),
		1, HybridIndirectLighting::kMaxRayPerPixel);

	if (ViewPipelineState.DiffuseIndirectMethod == EDiffuseIndirectMethod::SSGI)
	{
		// Standalone SSGI have the number of ray baked in the shader permutation.
		RayCountPerPixel = ScreenSpaceRayTracing::GetSSGIRayCountPerTracingPixel();