r.RayTracing.Culling

r.RayTracing.Culling

#Overview

name: r.RayTracing.Culling

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.RayTracing.Culling is to control the culling behavior in ray tracing for objects relative to the camera position. This setting variable is part of Unreal Engine 5’s ray tracing system, which is a key component of the rendering pipeline.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically within the ray tracing subsystem. Based on the callsites, it’s implemented in the RayTracingInstanceCulling.cpp file, which suggests it’s responsible for culling instances during ray tracing calculations.

The value of this variable is set through the console variable system, with a default value of 3. It can be changed at runtime using console commands or through engine configuration files.

The variable interacts closely with an enumeration called ECullingMode, which defines the different culling modes available. There’s also an associated variable named CVarRayTracingCulling, which is the actual console variable that stores the value.

Developers must be aware that this variable significantly impacts performance and visual quality in ray-traced scenes. Different culling modes can affect which objects are rendered, potentially leading to visual artifacts if set incorrectly.

Best practices when using this variable include:

  1. Understanding the performance implications of each culling mode.
  2. Testing thoroughly with different settings to find the optimal balance between performance and visual quality for your specific use case.
  3. Considering the nature of your scene when choosing a culling mode (e.g., scenes with many objects behind the camera might benefit from more aggressive culling).

Regarding the associated variable CVarRayTracingCulling:

The purpose of CVarRayTracingCulling is to provide a console-accessible way to control the ray tracing culling behavior at runtime. It’s directly linked to the r.RayTracing.Culling setting.

This variable is part of the Renderer module and is used to interface with the engine’s console variable system. It allows developers and users to change the culling mode without recompiling the engine.

The value of CVarRayTracingCulling is set when the engine initializes and can be changed at runtime through console commands.

It interacts directly with the ECullingMode enumeration, translating the integer value to the corresponding culling mode.

Developers should be aware that changes to this variable take effect immediately on the render thread, which could cause visual changes in real-time.

Best practices for using CVarRayTracingCulling include:

  1. Using it for debugging and performance testing.
  2. Providing a user-friendly way to adjust ray tracing performance in shipping games, if appropriate.
  3. Ensuring that any code reading this value does so on the correct thread (render thread in this case).

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingInstanceCulling.cpp:8

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarRayTracingCulling(
	TEXT("r.RayTracing.Culling"),
	3,
	TEXT("Enable culling in ray tracing for objects that are behind the camera\n")
	TEXT(" 0: Culling disabled (default)\n")
	TEXT(" 1: Culling by distance and solid angle enabled. Only cull objects behind camera.\n")
	TEXT(" 2: Culling by distance and solid angle enabled. Cull objects in front and behind camera.\n")
	TEXT(" 3: Culling by distance OR solid angle enabled. Cull objects in front and behind camera."),

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RaytracingOptions.h:58

Scope (from outer to inner):

file
namespace    RayTracing

Source code excerpt:

namespace RayTracing
{
	// Keep in sync with r.RayTracing.Culling
	enum class ECullingMode : uint8
	{
		Disabled,
		BehindCameraByDistanceAndSolidAngle,
		DistanceAndSolidAngle,
		DistanceOrSolidAngle,

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingInstanceCulling.cpp:7

Scope: file

Source code excerpt:

#include "ScenePrivate.h"

static TAutoConsoleVariable<int32> CVarRayTracingCulling(
	TEXT("r.RayTracing.Culling"),
	3,
	TEXT("Enable culling in ray tracing for objects that are behind the camera\n")
	TEXT(" 0: Culling disabled (default)\n")
	TEXT(" 1: Culling by distance and solid angle enabled. Only cull objects behind camera.\n")
	TEXT(" 2: Culling by distance and solid angle enabled. Cull objects in front and behind camera.\n")

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingInstanceCulling.cpp:55

Scope (from outer to inner):

file
function     RayTracing::ECullingMode RayTracing::GetCullingMode

Source code excerpt:

	}
	
	return (ECullingMode) FMath::Clamp(CVarRayTracingCulling.GetValueOnRenderThread(), 0, int32(ECullingMode::MAX) - 1);
}

float GetRayTracingCullingRadius()
{
	return CVarRayTracingCullingRadius.GetValueOnRenderThread();
}