r.RayTracing.Culling.PerInstance

r.RayTracing.Culling.PerInstance

#Overview

name: r.RayTracing.Culling.PerInstance

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.PerInstance is to control per-instance culling in the ray tracing system of Unreal Engine 5. This setting variable is specifically related to the ray tracing culling mechanism, which is part of the rendering system.

The Unreal Engine subsystem that relies on this setting variable is the Renderer module, specifically the ray tracing component. This can be inferred from the file location where the variable is defined and used: “Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingInstanceCulling.cpp”.

The value of this variable is set as a console variable using TAutoConsoleVariable. It is initialized with a default value of 1, meaning per-instance culling is enabled by default.

This variable interacts with other culling-related variables in the same file, such as CVarRayTracingCullingRadius and CVarRayTracingCullingGroupIds. It is specifically associated with CVarRayTracingCullingPerInstance, which shares the same value.

Developers must be aware that this variable affects the performance and accuracy of ray tracing in the engine. Enabling per-instance culling (value set to 1) can potentially improve performance by reducing the number of ray-object intersection tests, but it may also introduce additional computational overhead for the culling process itself.

Best practices when using this variable include:

  1. Testing the performance impact with and without per-instance culling enabled for your specific scene and use case.
  2. Considering the trade-off between culling overhead and potential rendering performance gains.
  3. Using this in conjunction with other culling techniques for optimal results.

Regarding the associated variable CVarRayTracingCullingPerInstance:

The purpose of CVarRayTracingCullingPerInstance is to provide programmatic access to the r.RayTracing.Culling.PerInstance console variable within the C++ code.

This variable is used in the Renderer module, specifically in the ray tracing culling system.

The value of this variable is set through the console variable system and can be accessed in the code using GetValueOnRenderThread().

It interacts directly with the r.RayTracing.Culling.PerInstance console variable, effectively serving as its in-code representation.

Developers should be aware that changes to this variable will affect the ray tracing culling behavior at runtime.

Best practices for using this variable include:

  1. Accessing its value on the render thread using GetValueOnRenderThread() to ensure thread safety.
  2. Using it to conditionally enable or disable per-instance culling in ray tracing-related code.
  3. Considering performance implications when modifying its value dynamically during runtime.

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarRayTracingCullingPerInstance(
	TEXT("r.RayTracing.Culling.PerInstance"),
	1,
	TEXT(""),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarRayTracingCullingRadius(
	TEXT("r.RayTracing.Culling.Radius"),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarRayTracingCullingPerInstance(
	TEXT("r.RayTracing.Culling.PerInstance"),
	1,
	TEXT(""),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarRayTracingCullingRadius(

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

Scope (from outer to inner):

file
function     void FRayTracingCullingParameters::Init

Source code excerpt:

	bCullUsingGroupIds = CVarRayTracingCullingGroupIds.GetValueOnRenderThread() != 0;
	bCullMinDrawDistance = CVarRayTracingCullingUseMinDrawDistance.GetValueOnRenderThread() != 0;
	bUseInstanceCulling = CVarRayTracingCullingPerInstance.GetValueOnRenderThread() != 0 && bCullAllObjects;
}

namespace RayTracing
{
bool ShouldConsiderCulling(const FRayTracingCullingParameters& CullingParameters, const FBoxSphereBounds& ObjectBounds, float MinDrawDistance)
{