r.MeshMerge.StoreImposterInfoInUVs

r.MeshMerge.StoreImposterInfoInUVs

#Overview

name: r.MeshMerge.StoreImposterInfoInUVs

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.MeshMerge.StoreImposterInfoInUVs is to control whether imposter information is stored in the UV channels of merged meshes. This setting variable is related to the mesh merging system in Unreal Engine 5.

This setting variable is primarily used by the MeshMergeUtilities module, which is responsible for combining multiple meshes into a single mesh. It specifically affects how imposter information is handled during the mesh merging process.

The value of this variable is set through a console variable (CVar) system. It’s defined as a TAutoConsoleVariable with an initial value of 0, meaning by default, imposter info is not stored in UVs.

The associated variable CVarMeshMergeStoreImposterInfoInUVs directly interacts with r.MeshMerge.StoreImposterInfoInUVs. They share the same value and purpose.

Developers must be aware that this variable affects the UV channel usage in merged meshes. When enabled (set to 1), it stores imposter information (position and scale) in UV2 and UV3 channels. This could potentially conflict with other systems or shaders that expect to use these UV channels for different purposes.

Best practices when using this variable include:

  1. Be cautious when enabling it, as it may affect rendering and materials that rely on UV2 and UV3.
  2. If enabled, ensure that your shaders and materials are aware of and compatible with this UV channel usage.
  3. Consider the performance implications of storing additional data in UV channels.
  4. Use the default value (0) unless you specifically need the imposter information in UVs for legacy reasons.

Regarding the associated variable CVarMeshMergeStoreImposterInfoInUVs:

This is the actual console variable that controls the behavior. It’s used in the code to check whether imposter info should be stored in UVs. The variable is checked using GetValueOnAnyThread() in the MergeImpostersToMesh function, where it determines whether to perform the imposter information storage in UV channels.

When using this variable, developers should:

  1. Access its value using GetValueOnAnyThread() when needed in code.
  2. Be aware that changing this value at runtime will affect subsequent mesh merges.
  3. Document the usage of this variable in project-specific guidelines if it’s being used in a non-default way.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Developer/MeshMergeUtilities/Private/MeshMergeHelpers.cpp:50

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMeshMergeStoreImposterInfoInUVs(
	TEXT("r.MeshMerge.StoreImposterInfoInUVs"),
	0,
	TEXT("Determines whether or not to store imposter info (position.xy in UV2, position.z + scale in UV3) in the merged mesh UV channels\n")
	TEXT("0: Do not store imposters info in UVs (default)\n")
	TEXT("1: Store imposter info in UVs (legacy)\n"),
	ECVF_Default);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Developer/MeshMergeUtilities/Private/MeshMergeHelpers.cpp:49

Scope: file

Source code excerpt:

//DECLARE_LOG_CATEGORY_CLASS(LogMeshMerging, Verbose, All);

static TAutoConsoleVariable<int32> CVarMeshMergeStoreImposterInfoInUVs(
	TEXT("r.MeshMerge.StoreImposterInfoInUVs"),
	0,
	TEXT("Determines whether or not to store imposter info (position.xy in UV2, position.z + scale in UV3) in the merged mesh UV channels\n")
	TEXT("0: Do not store imposters info in UVs (default)\n")
	TEXT("1: Store imposter info in UVs (legacy)\n"),
	ECVF_Default);

#Loc: <Workspace>/Engine/Source/Developer/MeshMergeUtilities/Private/MeshMergeHelpers.cpp:1154

Scope (from outer to inner):

file
function     void FMeshMergeHelpers::MergeImpostersToMesh

Source code excerpt:

		}

		if (CVarMeshMergeStoreImposterInfoInUVs.GetValueOnAnyThread())
		{
			// Imposter magic, we're storing the actor world position and X scale spread across two UV channels
			const int32 UVOneIndex = 2;
			const int32 UVTwoIndex = UVOneIndex + 1;
			TVertexInstanceAttributesRef<FVector2f> VertexInstanceUVs = ImposterMeshAttributes.GetVertexInstanceUVs();
			VertexInstanceUVs.SetNumChannels(UVTwoIndex + 1);