r.Water.WaterMesh.MIDDeduplication
r.Water.WaterMesh.MIDDeduplication
#Overview
name: r.Water.WaterMesh.MIDDeduplication
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Deduplicate per-water body MIDs
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Water.WaterMesh.MIDDeduplication is to control the deduplication of per-water body Material Instance Dynamic (MID) in the water rendering system of Unreal Engine 5.
This setting variable is primarily used in the Water plugin, specifically within the WaterMeshComponent. It’s part of the experimental Water module in Unreal Engine 5, which is responsible for rendering and simulating water bodies in the game environment.
The value of this variable is set through a console variable (CVar) system, which allows for runtime modification. It’s defined with a default value of 0, meaning the deduplication is disabled by default.
The associated variable CVarWaterMeshMIDDeduplication directly interacts with r.Water.WaterMesh.MIDDeduplication. They share the same value and purpose.
Developers must be aware that this variable is a boolean flag (0 for false, non-zero for true) that determines whether to deduplicate Material Instance Dynamics for each water body. When enabled, it can potentially optimize memory usage and rendering performance by reducing the number of unique material instances.
Best practices when using this variable include:
- Consider enabling it (set to 1) if your game has many water bodies with similar materials to potentially improve performance.
- Test thoroughly with both settings (0 and 1) to ensure it doesn’t negatively impact visual quality or cause unexpected behavior in your specific use case.
- Be aware that changing this setting might affect the ability to individually customize materials for each water body.
Regarding the associated variable CVarWaterMeshMIDDeduplication:
- It’s the actual CVar object that controls the r.Water.WaterMesh.MIDDeduplication setting.
- It’s defined with the ECVF_RenderThreadSafe flag, indicating it’s safe to modify from the render thread.
- Its value is retrieved in the UWaterMeshComponent::RebuildWaterMesh function to determine whether to deduplicate MIDs when rebuilding the water mesh.
Developers should use CVarWaterMeshMIDDeduplication.GetValueOnGameThread() to safely retrieve the current value of this setting in their code, as demonstrated in the provided source code excerpt.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterMeshComponent.cpp:64
Scope: file
Source code excerpt:
TAutoConsoleVariable<int32> CVarWaterMeshMIDDeduplication(
TEXT("r.Water.WaterMesh.MIDDeduplication"),
0,
TEXT("Deduplicate per-water body MIDs"),
ECVF_RenderThreadSafe
);
extern TAutoConsoleVariable<float> CVarWaterSplineResampleMaxDistance;
#Associated Variable and Callsites
This variable is associated with another variable named CVarWaterMeshMIDDeduplication
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterMeshComponent.cpp:63
Scope: file
Source code excerpt:
);
TAutoConsoleVariable<int32> CVarWaterMeshMIDDeduplication(
TEXT("r.Water.WaterMesh.MIDDeduplication"),
0,
TEXT("Deduplicate per-water body MIDs"),
ECVF_RenderThreadSafe
);
#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterMeshComponent.cpp:394
Scope (from outer to inner):
file
function void UWaterMeshComponent::RebuildWaterMesh
lambda-function
Source code excerpt:
}
const bool bDeduplicateMIDs = CVarWaterMeshMIDDeduplication.GetValueOnGameThread() != 0;
if (bDeduplicateMIDs)
{
// Assign material instance(s)
UMaterialInterface* WaterMaterial = WaterBodyComponent->GetWaterMaterial();
if (WaterMaterial)