r.PathTracing.SamplerType

r.PathTracing.SamplerType

#Overview

name: r.PathTracing.SamplerType

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.SamplerType is to control the random number generation method used by the path tracer in Unreal Engine’s rendering system.

This setting variable is primarily used by the path tracing subsystem within Unreal Engine’s renderer module. It specifically affects how random numbers are generated for path tracing calculations.

The value of this variable is set through a console variable (CVarPathTracingSamplerType) in the Engine/Source/Runtime/Renderer/Private/PathTracing.cpp file. It’s defined as an integer with a default value of PATHTRACER_SAMPLER_DEFAULT.

The associated variable CVarPathTracingSamplerType directly interacts with r.PathTracing.SamplerType. They share the same value and purpose.

Developers must be aware that this variable has two possible settings: 0: Uses a different high-quality random sequence per pixel (default) 1: Optimizes the random sequence across pixels to reduce visible error at the target sample count

When using this variable, best practices include:

  1. Understanding the trade-offs between the two options. Option 0 provides high-quality results for each pixel independently, while option 1 may reduce overall visible error but could introduce patterns across pixels.
  2. Testing both options in your specific use case to determine which provides better visual results.
  3. Considering performance implications, as option 1 may require additional computation to optimize across pixels.
  4. Being aware that changing this setting may affect the consistency of rendered results, which could be important for applications requiring deterministic output.

Regarding the associated variable CVarPathTracingSamplerType:

The purpose of CVarPathTracingSamplerType is to provide a programmatic interface to control the r.PathTracing.SamplerType setting within the engine’s C++ code.

This variable is used in the renderer module, specifically in the path tracing system. It’s defined as a TAutoConsoleVariable, which allows it to be changed at runtime through console commands.

The value of CVarPathTracingSamplerType is set when it’s defined, using the same options as r.PathTracing.SamplerType. It can be accessed in the code using the GetValueOnRenderThread() method.

CVarPathTracingSamplerType directly interacts with r.PathTracing.SamplerType, effectively serving as its C++ representation.

Developers should be aware that this variable is marked as ECVF_RenderThreadSafe, meaning it’s safe to access from the render thread.

Best practices for using CVarPathTracingSamplerType include:

  1. Accessing its value using GetValueOnRenderThread() when in render thread code.
  2. Being cautious about changing its value during runtime, as it could affect rendering consistency.
  3. Using it to programmatically control the path tracing sampler type based on other engine states or user inputs.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

// See PATHTRACER_SAMPLER_* defines
TAutoConsoleVariable<int32> CVarPathTracingSamplerType(
	TEXT("r.PathTracing.SamplerType"),
	PATHTRACER_SAMPLER_DEFAULT,
	TEXT("Controls the way the path tracer generates its random numbers\n")
	TEXT("0: use a different high quality random sequence per pixel (default)\n")
	TEXT("1: optimize the random sequence across pixels to reduce visible error at the target sample count\n"),
	ECVF_RenderThreadSafe
);

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:


// See PATHTRACER_SAMPLER_* defines
TAutoConsoleVariable<int32> CVarPathTracingSamplerType(
	TEXT("r.PathTracing.SamplerType"),
	PATHTRACER_SAMPLER_DEFAULT,
	TEXT("Controls the way the path tracer generates its random numbers\n")
	TEXT("0: use a different high quality random sequence per pixel (default)\n")
	TEXT("1: optimize the random sequence across pixels to reduce visible error at the target sample count\n"),
	ECVF_RenderThreadSafe

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

Scope (from outer to inner):

file
function     static void PreparePathTracingData

Source code excerpt:

	PathTracingData.ApproximateCaustics = CVarPathTracingApproximateCaustics.GetValueOnRenderThread();
	PathTracingData.EnableCameraBackfaceCulling = CVarPathTracingEnableCameraBackfaceCulling.GetValueOnRenderThread();
	PathTracingData.SamplerType = CVarPathTracingSamplerType.GetValueOnRenderThread();
	PathTracingData.VisualizeLightGrid = CVarPathTracingLightGridVisualize.GetValueOnRenderThread();
	PathTracingData.VisualizeDecalGrid = CVarPathTracingDecalGridVisualize.GetValueOnRenderThread();
	PathTracingData.FilterWidth = CVarPathTracingFilterWidth.GetValueOnRenderThread();
	PathTracingData.CameraFocusDistance = 0;
	PathTracingData.CameraLensRadius = FVector2f::ZeroVector;
	if (ShowFlags.DepthOfField &&