r.Voxel

r.Voxel

#Overview

name: r.Voxel

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.Voxel is to control the voxel rendering feature in the Unreal Engine’s Nanite system. This setting variable is primarily used in the rendering system, specifically for the Nanite voxel-based rendering pipeline.

The Unreal Engine subsystem that relies on this setting variable is the Renderer module, particularly the Nanite subsystem within it. This can be seen from the file path “Engine/Source/Runtime/Renderer/Private/Nanite/Voxel.cpp”.

The value of this variable is set as a console variable using TAutoConsoleVariable. It is initialized with a default value of 0, which suggests that the voxel rendering feature is disabled by default.

The associated variable CVarVoxel directly interacts with r.Voxel. They share the same value and are used interchangeably in the code.

Developers must be aware that this variable is render thread safe (ECVF_RenderThreadSafe), meaning it can be safely accessed and modified from the render thread without causing race conditions or other threading issues.

Best practices when using this variable include:

  1. Only enabling it when necessary, as it may have performance implications.
  2. Modifying it through the console or config files rather than hard-coding changes.
  3. Being aware of its impact on the Nanite rendering pipeline and testing thoroughly when enabled.

Regarding the associated variable CVarVoxel:

The purpose of CVarVoxel is to provide a programmatic way to access and control the r.Voxel setting within the C++ code. It is used to check the current state of the voxel rendering feature and control the execution of voxel-related code.

CVarVoxel is used in the Nanite namespace, specifically in the DrawVisibleBricks function. This function appears to be responsible for rendering visible voxel bricks in the scene.

The value of CVarVoxel is set through the r.Voxel console variable, and its value is retrieved using the GetValueOnRenderThread() method, ensuring thread-safe access on the render thread.

Developers should be aware that CVarVoxel acts as a gate for voxel rendering code. When its value is 0, the voxel rendering code is skipped entirely.

Best practices for using CVarVoxel include:

  1. Always accessing its value using GetValueOnRenderThread() when in render thread code.
  2. Considering the performance implications of enabling/disabling voxel rendering in different scenarios.
  3. Using it as a quick way to toggle voxel rendering for debugging or performance testing purposes.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/Voxel.cpp:12

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarVoxel(
	TEXT("r.Voxel"),
	0,
	TEXT(""),
	ECVF_RenderThreadSafe
	);

static TAutoConsoleVariable<int32> CVarVoxelMethod(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/Voxel.cpp:11

Scope: file

Source code excerpt:

#include "DataDrivenShaderPlatformInfo.h"

static TAutoConsoleVariable<int32> CVarVoxel(
	TEXT("r.Voxel"),
	0,
	TEXT(""),
	ECVF_RenderThreadSafe
	);

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

Scope (from outer to inner):

file
namespace    Nanite
function     void DrawVisibleBricks

Source code excerpt:

{
#if !UE_BUILD_SHIPPING
	if( CVarVoxel.GetValueOnRenderThread() == 0 )
		return;

	RDG_EVENT_SCOPE( GraphBuilder, "Voxel" );

	uint32 HashTableSize = View.ViewRect.Area();
	//uint32 HashTableSize = FMath::RoundUpToPowerOfTwo( View.ViewRect.Area() );