r.Water.WaterSplineResampleMaxDistance

r.Water.WaterSplineResampleMaxDistance

#Overview

name: r.Water.WaterSplineResampleMaxDistance

This variable is created as a Console Variable (cvar).

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Water.WaterSplineResampleMaxDistance is to control the precision of water spline conversion to polygons in Unreal Engine 5’s water system. This setting variable is primarily used for balancing the accuracy of water body representations against performance considerations.

This variable is mainly used in the Experimental Water plugin, specifically within the Runtime module. The subsystems that rely on this setting are related to water body rendering, collision, and mesh generation.

The value of this variable is set as a console variable with a default value of 50.0f. It can be adjusted at runtime through the console or programmatically.

The associated variable CVarWaterSplineResampleMaxDistance interacts directly with r.Water.WaterSplineResampleMaxDistance, as they share the same value. This variable is used in various components of the water system, such as LakeCollisionComponent, WaterBodyActor, and WaterMeshComponent.

Developers must be aware that this variable affects the trade-off between water body accuracy and performance. A lower value will result in more accurate water shapes and physics, but at the cost of increased computational overhead.

Best practices when using this variable include:

  1. Adjusting the value based on the specific needs of the project, considering both visual quality and performance requirements.
  2. Testing different values to find the optimal balance for your specific water bodies.
  3. Potentially using different values for different levels of detail or distances from the camera.

Regarding the associated variable CVarWaterSplineResampleMaxDistance:

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


TAutoConsoleVariable<float> CVarWaterSplineResampleMaxDistance(
	TEXT("r.Water.WaterSplineResampleMaxDistance"),
	50.0f,
	TEXT("Maximum distance between the sample segments and the spline when converting the water spline shapes to polygons (as distance discreases, the number of vertices will increase, \
		, the physics shapes will be more accurate, the water tiles will match more closely, but the computational cost will also increase)."),
	ECVF_Default);

// ----------------------------------------------------------------------------------

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

// ----------------------------------------------------------------------------------

extern TAutoConsoleVariable<float> CVarWaterSplineResampleMaxDistance;


// ----------------------------------------------------------------------------------

ULakeCollisionComponent::ULakeCollisionComponent(const FObjectInitializer& ObjectInitializer)
	: UPrimitiveComponent(ObjectInitializer)

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

Scope (from outer to inner):

file
function     void ULakeCollisionComponent::UpdateBodySetup

Source code excerpt:


			TArray<FVector> PolyLineVertices;
			SplineComp->ConvertSplineToPolyLine(ESplineCoordinateSpace::World, FMath::Square(CVarWaterSplineResampleMaxDistance.GetValueOnGameThread()), PolyLineVertices);
			// Transform to local space of this component :
			Algo::Transform(PolyLineVertices, SplineVerts, [this](const FVector& Vertex) { return FVector2D(GetComponentToWorld().InverseTransformPosition(Vertex)); });
		}

		TArray<FVector2D> CorrectedSplineVertices;
		FGeomTools2D::CorrectPolygonWinding(CorrectedSplineVertices, SplineVerts, false);

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

Scope: file

Source code excerpt:

#define LOCTEXT_NAMESPACE "Water"

TAutoConsoleVariable<float> CVarWaterSplineResampleMaxDistance(
	TEXT("r.Water.WaterSplineResampleMaxDistance"),
	50.0f,
	TEXT("Maximum distance between the sample segments and the spline when converting the water spline shapes to polygons (as distance discreases, the number of vertices will increase, \
		, the physics shapes will be more accurate, the water tiles will match more closely, but the computational cost will also increase)."),
	ECVF_Default);

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

Scope: file

Source code excerpt:

);

extern TAutoConsoleVariable<float> CVarWaterSplineResampleMaxDistance;


// ----------------------------------------------------------------------------------

UWaterMeshComponent::UWaterMeshComponent()
{

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

Scope (from outer to inner):

file
lambda-function

Source code excerpt:

				{
					TArray<FVector> PolyLineVertices;
					SplineComp->ConvertSplineToPolyLine(ESplineCoordinateSpace::World, FMath::Square(CVarWaterSplineResampleMaxDistance.GetValueOnGameThread()), PolyLineVertices);

					TArray<FVector2D>& Polygon = PolygonBatches.Emplace_GetRef();
					Polygon.Reserve(PolyLineVertices.Num());
					Algo::Transform(PolyLineVertices, Polygon, [](const FVector& Vertex) { return FVector2D(Vertex); });
				}

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

Scope (from outer to inner):

file
lambda-function

Source code excerpt:


					TArray<FVector> PolyLineVertices;
					SplineComp->ConvertSplineToPolyLine(ESplineCoordinateSpace::World, FMath::Square(CVarWaterSplineResampleMaxDistance.GetValueOnGameThread()), PolyLineVertices);

					Polygon.Reserve(PolyLineVertices.Num());
					Algo::Transform(PolyLineVertices, Polygon, [](const FVector& Vertex) { return FVector2D(Vertex); });

					FBox OceanBounds = WaterBodyComponent->Bounds.GetBox();
					OceanBounds.Max.Z += WaterBodyComponent->GetMaxWaveHeight();