r.Water.WaterMesh.LocalTessellation.UpdateMargin

r.Water.WaterMesh.LocalTessellation.UpdateMargin

#Overview

name: r.Water.WaterMesh.LocalTessellation.UpdateMargin

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.Water.WaterMesh.LocalTessellation.UpdateMargin is to control the minimum distance between the view and the edge of the dynamic water mesh when local tessellation is enabled in Unreal Engine 5’s water rendering system.

This setting variable is primarily used in the Water plugin, specifically within the water rendering subsystem. Based on the callsites, it’s part of the WaterViewExtension module, which is responsible for managing the water mesh’s dynamic updates relative to the camera position.

The value of this variable is set as a console variable with a default value of 15000 units. It can be changed at runtime through the console or configuration files.

The associated variable CVarLocalTessellationUpdateMargin directly interacts with r.Water.WaterMesh.LocalTessellation.UpdateMargin. They share the same value and purpose.

Developers must be aware that this variable affects the performance and visual quality of water rendering. A larger value will cause the water mesh to update less frequently but may result in less detailed water at the edges of the view. A smaller value will provide more detailed water throughout the view but may increase performance overhead due to more frequent updates.

Best practices when using this variable include:

  1. Adjust the value based on the scale of your game world and the typical movement speed of the camera.
  2. Balance between performance and visual quality. Larger values are more performance-friendly but may reduce visual fidelity at the edges of the view.
  3. Consider the type of water bodies in your game. Large oceans might benefit from larger values, while smaller lakes or rivers might need smaller values for better detail.
  4. Test thoroughly with different camera movements and positions to ensure smooth transitions and consistent water quality.

Regarding the associated variable CVarLocalTessellationUpdateMargin:

The purpose of CVarLocalTessellationUpdateMargin is identical to r.Water.WaterMesh.LocalTessellation.UpdateMargin. It’s the C++ implementation of the console variable.

This variable is used within the Water plugin, specifically in the WaterViewExtension module. It’s used to determine when to update the water mesh based on the camera’s position relative to the current water mesh bounds.

The value is set when the console variable is initialized and can be accessed at runtime using the GetValueOnGameThread() method.

CVarLocalTessellationUpdateMargin directly interacts with the water mesh update logic. It’s used to calculate the UpdateExtents, which determines when the water mesh needs to be updated as the camera moves.

Developers should be aware that this variable is used in performance-critical code that runs every frame. Changes to this value can have immediate effects on both performance and visual quality.

Best practices for using CVarLocalTessellationUpdateMargin include:

  1. Use it in conjunction with other water rendering settings to achieve the desired balance between performance and visual quality.
  2. Monitor its impact on frame rates, especially in scenes with large water bodies.
  3. Consider exposing it as a user-adjustable setting for players with different hardware capabilities.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterViewExtension.cpp:19

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarLocalTessellationUpdateMargin(
	TEXT("r.Water.WaterMesh.LocalTessellation.UpdateMargin"),
	15000.,
	TEXT("Controls the minimum distance between the view and the edge of the dynamic water mesh when local tessellation is enabled.\n")
	TEXT("If the view is less than UpdateMargin units away from the edge, it moves the sliding window forward."),
	ECVF_Default);

extern void OnCVarWaterInfoSceneProxiesValueChanged(IConsoleVariable*);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterViewExtension.cpp:18

Scope: file

Source code excerpt:

	ECVF_Default);

static TAutoConsoleVariable<float> CVarLocalTessellationUpdateMargin(
	TEXT("r.Water.WaterMesh.LocalTessellation.UpdateMargin"),
	15000.,
	TEXT("Controls the minimum distance between the view and the edge of the dynamic water mesh when local tessellation is enabled.\n")
	TEXT("If the view is less than UpdateMargin units away from the edge, it moves the sliding window forward."),
	ECVF_Default);

#Loc: <Workspace>/Engine/Plugins/Experimental/Water/Source/Runtime/Private/WaterViewExtension.cpp:338

Scope (from outer to inner):

file
function     void FWaterViewExtension::SetupView

Source code excerpt:


			// Trigger the next update when the camera is <UpdateMargin> units away from the border of the current window.
			const FVector2D UpdateMargin(CVarLocalTessellationUpdateMargin.GetValueOnGameThread());

			// Keep a minimum of <1., 1.> bounds to avoid updating every frame if the update margin is larger than the zone.
			const FVector2D UpdateExtents = FVector2D::Max(FVector2D(1., 1.), WaterInfoHalfExtent - UpdateMargin);
			WaterZoneInfo->UpdateBounds.Emplace(FVector2D(WaterMeshCenter) - UpdateExtents, FVector2D(WaterMeshCenter) + UpdateExtents);

			const FVector2D WaterQuadTreeHalfExtent = WaterMesh->GetExtentInTiles() * TileSize;