r.RayTracing.Culling.Angle

r.RayTracing.Culling.Angle

#Overview

name: r.RayTracing.Culling.Angle

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.RayTracing.Culling.Angle is to control camera culling for objects behind the camera in ray tracing effects. Specifically, it sets a threshold angle for culling objects that have a projected angle smaller than this value.

This setting variable is primarily used in the ray tracing subsystem of Unreal Engine’s rendering module. Based on the callsites, it’s clear that this variable is used in the RayTracingInstanceCulling.cpp file, which is part of the ray tracing culling system.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1.0 degrees, but can be changed at runtime through console commands or project settings.

The variable interacts closely with other ray tracing culling parameters, particularly within the FRayTracingCullingParameters structure. It’s used to calculate the AngleThresholdRatio and AngleThresholdRatioSq, which are likely used in the actual culling calculations.

Developers should be aware that this variable directly affects performance and visual quality in ray tracing effects. A smaller angle will result in more aggressive culling, potentially improving performance but risking the culling of objects that might be visible at the edges of the view. A larger angle will be more conservative, ensuring fewer missed objects but potentially reducing performance gains from culling.

Best practices when using this variable include:

  1. Carefully balancing performance and visual quality.
  2. Testing with different values to find the optimal setting for your specific scene and performance requirements.
  3. Considering the nature of your scene - scenes with many small, detailed objects might benefit from a slightly larger angle to prevent popping or missing details.

Regarding the associated variable CVarRayTracingCullingAngle:

This is the actual console variable that stores and provides access to the r.RayTracing.Culling.Angle value. It’s defined using the TAutoConsoleVariable template, which is part of Unreal Engine’s configuration system.

The purpose of CVarRayTracingCullingAngle is to provide a way to access and modify the r.RayTracing.Culling.Angle value at runtime. It’s used within the engine code to retrieve the current value of the culling angle when needed, such as in the FRayTracingCullingParameters::Init function.

This variable is part of the rendering subsystem and is specifically used in ray tracing instance culling. It’s typically set at engine initialization but can be modified during runtime.

The value of CVarRayTracingCullingAngle is accessed using the GetValueOnRenderThread() method, ensuring thread-safe access in the render thread.

Developers should be aware that changes to this variable will take effect immediately in the render thread. It’s marked as ECVF_RenderThreadSafe, meaning it’s safe to modify from any thread, but the changes will be applied in the render thread.

Best practices for using CVarRayTracingCullingAngle include:

  1. Using the appropriate methods to access and modify its value, especially considering thread safety.
  2. Being cautious about frequent changes, as they could impact performance.
  3. Considering exposing this variable in debug or development builds for easier tuning and testing.

#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:30

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarRayTracingCullingAngle(
	TEXT("r.RayTracing.Culling.Angle"),
	1.0f,
	TEXT("Do camera culling for objects behind the camera with a projected angle smaller than this threshold in ray tracing effects (default = 1 degrees)"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarRayTracingCullingUseMinDrawDistance(
	TEXT("r.RayTracing.Culling.UseMinDrawDistance"),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarRayTracingCullingAngle(
	TEXT("r.RayTracing.Culling.Angle"),
	1.0f,
	TEXT("Do camera culling for objects behind the camera with a projected angle smaller than this threshold in ray tracing effects (default = 1 degrees)"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarRayTracingCullingUseMinDrawDistance(

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

Scope (from outer to inner):

file
function     void FRayTracingCullingParameters::Init

Source code excerpt:

	CullingRadius = CVarRayTracingCullingRadius.GetValueOnRenderThread();
	FarFieldCullingRadius = Lumen::GetFarFieldMaxTraceDistance();
	CullAngleThreshold = CVarRayTracingCullingAngle.GetValueOnRenderThread();
	AngleThresholdRatio = FMath::Tan(FMath::Min(89.99f, CullAngleThreshold) * PI / 180.0f);
	AngleThresholdRatioSq = FMath::Square(AngleThresholdRatio);
	ViewOrigin = View.ViewMatrices.GetViewOrigin();
	TranslatedViewOrigin = FVector3f(ViewOrigin + View.ViewMatrices.GetPreViewTranslation());
	ViewDirection = View.GetViewDirection();
	bCullAllObjects = CullingMode == RayTracing::ECullingMode::DistanceAndSolidAngle || CullingMode == RayTracing::ECullingMode::DistanceOrSolidAngle;