r.Water.BuildConservativeRasterizationMesh

r.Water.BuildConservativeRasterizationMesh

#Overview

name: r.Water.BuildConservativeRasterizationMesh

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Water.BuildConservativeRasterizationMesh is to enable additional data in the UV channels of the water mesh, which is used for software conservative rasterization when creating the GPU water quadtree.

This setting variable is primarily used in the Water plugin of Unreal Engine 5, specifically within the WaterBodyComponent subsystem. It affects the rendering and mesh generation of water bodies in the game.

The value of this variable is set as a console variable using TAutoConsoleVariable, with a default value of 1 (enabled). It is defined in the WaterBodyComponent.cpp file.

The associated variable CVarWaterBodyBuildConservativeRasterizationMesh interacts directly with r.Water.BuildConservativeRasterizationMesh, as they share the same value and purpose.

Developers must be aware that this variable affects the generation of water meshes and can impact performance and visual quality of water rendering. It’s important to note that the variable is marked as ECVF_ReadOnly, which means its value should not be changed during runtime.

Best practices when using this variable include:

  1. Consider the performance implications of enabling this feature, especially on lower-end hardware.
  2. Test water rendering with both enabled and disabled states to determine the optimal setting for your project.
  3. If you need to change this setting, it should be done before water bodies are initialized or updated.

Regarding the associated variable CVarWaterBodyBuildConservativeRasterizationMesh:

The purpose of CVarWaterBodyBuildConservativeRasterizationMesh is the same as r.Water.BuildConservativeRasterizationMesh - to control the generation of additional UV data for conservative rasterization in water meshes.

This variable is used within the Water plugin, specifically in the UWaterBodyComponent class. It’s used to determine whether the water info mesh should be updated with conservative rasterization data.

The value of this variable is set through the console variable r.Water.BuildConservativeRasterizationMesh, and it’s accessed using the GetValueOnGameThread() method.

CVarWaterBodyBuildConservativeRasterizationMesh interacts directly with the water mesh generation process. It’s checked in the OnPostRegisterAllComponents and UpdateWaterInfoMeshComponents functions to determine if the water body render data needs to be updated.

Developers should be aware that changes to this variable will trigger updates to the water body render data, which could impact performance during runtime if changed frequently.

Best practices for using this variable include:

  1. Avoid changing its value during performance-critical sections of your game.
  2. If you need to change it, consider doing so during level load or other appropriate times when performance impact is minimal.
  3. Be consistent in its usage across your project to ensure uniform water rendering behavior.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarWaterBodyBuildConservativeRasterizationMesh(
	TEXT("r.Water.BuildConservativeRasterizationMesh"), 1,
	TEXT("Enables additional data in the UV channels of the water mesh, which is used for software conservative rasterization when creating the GPU water quadtree."),
	ECVF_ReadOnly);

const FName UWaterBodyComponent::WaterBodyIndexParamName(TEXT("WaterBodyIndex"));
const FName UWaterBodyComponent::WaterZoneIndexParamName(TEXT("WaterZoneIndex"));
const FName UWaterBodyComponent::WaterBodyZOffsetParamName(TEXT("WaterBodyZOffset"));

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_Default);

TAutoConsoleVariable<int32> CVarWaterBodyBuildConservativeRasterizationMesh(
	TEXT("r.Water.BuildConservativeRasterizationMesh"), 1,
	TEXT("Enables additional data in the UV channels of the water mesh, which is used for software conservative rasterization when creating the GPU water quadtree."),
	ECVF_ReadOnly);

const FName UWaterBodyComponent::WaterBodyIndexParamName(TEXT("WaterBodyIndex"));
const FName UWaterBodyComponent::WaterZoneIndexParamName(TEXT("WaterZoneIndex"));

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

Scope (from outer to inner):

file
function     void UWaterBodyComponent::OnPostRegisterAllComponents

Source code excerpt:

	UWaterBodyInfoMeshComponent* WaterInfoMeshComponent = GetWaterInfoMeshComponent();
	const bool bHasConservativeRasterMesh = IsValid(WaterInfoMeshComponent) && WaterInfoMeshComponent->bIsConservativeRasterCompatible;
	const bool bShouldHaveConservativeRastermesh = CVarWaterBodyBuildConservativeRasterizationMesh.GetValueOnGameThread() != 0;
	if ((bHasConservativeRasterMesh != bShouldHaveConservativeRastermesh) || GetLinkerCustomVersion(FFortniteMainBranchObjectVersion::GUID) < FFortniteMainBranchObjectVersion::WaterBodyStaticMeshFixup)
	{
		UpdateWaterBodyRenderData();
	}

	// Ensure that the sprite component is updated once the water body is fully setup after PostRegister.

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

Scope (from outer to inner):

file
function     void UWaterBodyComponent::UpdateWaterInfoMeshComponents

Source code excerpt:

	}

	const bool bShouldBuildConservativeRasterMesh = CVarWaterBodyBuildConservativeRasterizationMesh.GetValueOnGameThread() != 0;
	FWaterBodyMeshBuilder MeshBuilder;
	MeshBuilder.BuildWaterInfoMeshes( this, GetWaterInfoMeshComponent(), GetDilatedWaterInfoMeshComponent(), bShouldBuildConservativeRasterMesh);
}

void UWaterBodyComponent::UpdateWaterBodyStaticMeshComponents()
{