r.VoxelLevel2

r.VoxelLevel2

#Overview

name: r.VoxelLevel2

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.VoxelLevel2 is to control a specific aspect of the Nanite rendering system in Unreal Engine 5, particularly related to voxel-based rendering at level 2 detail.

This setting variable is primarily used by the Nanite rendering subsystem, which is part of Unreal Engine 5’s advanced geometry system. Based on the callsites, it’s clear that this variable is utilized within the Renderer module, specifically in the Nanite namespace.

The value of this variable is set through a console variable (CVarVoxelLevel2) with a default value of 1. It’s defined as a render thread safe variable, meaning it can be safely accessed and modified from the render thread.

The associated variable CVarVoxelLevel2 directly interacts with r.VoxelLevel2. They share the same value and are essentially two ways to access the same setting.

Developers must be aware that this variable affects the rendering pipeline, specifically the voxel-based rendering at level 2 detail in Nanite. Changing this value could impact performance and visual quality of Nanite-rendered geometry.

Best practices when using this variable include:

  1. Only modify it if you fully understand its impact on the Nanite rendering system.
  2. Test thoroughly after changing the value to ensure it doesn’t negatively affect performance or visual quality.
  3. Consider exposing it as a configurable setting for advanced users or developers, but not for end-users.

Regarding the associated variable CVarVoxelLevel2:

The purpose of CVarVoxelLevel2 is to provide programmatic access to the r.VoxelLevel2 setting within the C++ code of the engine.

It’s used directly in the Nanite namespace, specifically in the DrawVisibleBricks function, to determine whether to perform certain rendering operations.

The value of CVarVoxelLevel2 is set when r.VoxelLevel2 is modified, as they are linked.

CVarVoxelLevel2 interacts directly with the r.VoxelLevel2 console variable.

Developers should be aware that accessing CVarVoxelLevel2 should be done using the GetValueOnRenderThread() method to ensure thread-safe access.

Best practices for CVarVoxelLevel2 include:

  1. Always access it using GetValueOnRenderThread() when in render thread code.
  2. Avoid frequently querying its value in performance-critical code paths.
  3. Consider caching its value if it’s accessed multiple times in the same frame or function.

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarVoxelLevel2(
	TEXT("r.VoxelLevel2"),
	1,
	TEXT(""),
	ECVF_RenderThreadSafe
	);

namespace Nanite

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	);

static TAutoConsoleVariable<int32> CVarVoxelLevel2(
	TEXT("r.VoxelLevel2"),
	1,
	TEXT(""),
	ECVF_RenderThreadSafe
	);

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

Scope (from outer to inner):

file
namespace    Nanite
function     void DrawVisibleBricks

Source code excerpt:

	FRDGBufferRef BlockBuffer = BlockBufferL1;

	if( CVarVoxelLevel2.GetValueOnRenderThread() )
	{
		{
			FBuildBricksParameters* PassParameters = GraphBuilder.AllocParameters< FBuildBricksParameters >();

			PassParameters->RWBrickBuffer	= GraphBuilder.CreateUAV( BrickBuffer );
			PassParameters->BlockBuffer		= GraphBuilder.CreateSRV( BlockBufferL1 );