r.PathTracing.ApproximateCaustics

r.PathTracing.ApproximateCaustics

#Overview

name: r.PathTracing.ApproximateCaustics

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.ApproximateCaustics is to control the approximation of caustic paths in the path tracing rendering system of Unreal Engine 5. This setting is designed to reduce noise in the rendered image, specifically targeting speckles and noise from low-roughness glass and metal surfaces.

This setting variable is primarily used in the Renderer module of Unreal Engine 5, specifically within the path tracing subsystem. Based on the callsites, we can see that it’s utilized in the PathTracing.cpp file, which is part of the core rendering functionality.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1 (enabled) and can be changed at runtime. The associated C++ variable is CVarPathTracingApproximateCaustics.

The variable interacts with the PathTracingData structure, specifically setting the ApproximateCaustics field. This suggests that it directly influences the path tracing algorithm’s behavior during rendering.

Developers should be aware that enabling this feature (which is the default state) will result in a trade-off between noise reduction and accuracy. While it reduces speckles and noise, it may also slightly affect the physical accuracy of caustics rendering.

Best practices when using this variable include:

  1. Keeping it enabled (value of 1) for most scenarios to benefit from noise reduction.
  2. Disabling it (setting to 0) when absolute physical accuracy of caustics is required, accepting the potential increase in noise.
  3. Experimenting with both settings in different lighting conditions and with various materials to find the optimal balance for specific scenes.

Regarding the associated variable CVarPathTracingApproximateCaustics:

This is the actual console variable that controls the r.PathTracing.ApproximateCaustics setting. It’s defined as an integer variable, suggesting it might support multiple levels of approximation in the future, although currently it’s used as a boolean (0 for disabled, non-zero for enabled).

The variable is accessed in the PreparePathTracingData function, where its value is retrieved using GetValueOnRenderThread(). This suggests that the setting can be changed dynamically and will take effect on the next render frame.

Developers should note that this variable is marked as ECVF_RenderThreadSafe, meaning it’s safe to modify from the render thread. However, best practice would be to change this setting either through console commands or through engine configuration files, rather than directly manipulating the C++ variable in code.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarPathTracingApproximateCaustics(
	TEXT("r.PathTracing.ApproximateCaustics"),
	1,
	TEXT("When non-zero, the path tracer will approximate caustic paths to reduce noise. This reduces speckles and noise from low-roughness glass and metals. (default = 1 (enabled))"),
	ECVF_RenderThreadSafe
);

TAutoConsoleVariable<int32> CVarPathTracingEnableEmissive(

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

);

TAutoConsoleVariable<int32> CVarPathTracingApproximateCaustics(
	TEXT("r.PathTracing.ApproximateCaustics"),
	1,
	TEXT("When non-zero, the path tracer will approximate caustic paths to reduce noise. This reduces speckles and noise from low-roughness glass and metals. (default = 1 (enabled))"),
	ECVF_RenderThreadSafe
);

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

Scope (from outer to inner):

file
function     static void PreparePathTracingData

Source code excerpt:

		PathTracingData.MaxPathIntensity = FMath::Pow(2.0f, PPV.PathTracingMaxPathExposure);
	}
	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;