r.RayTracing.Geometry.Water

r.RayTracing.Geometry.Water

#Overview

name: r.RayTracing.Geometry.Water

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.RayTracing.Geometry.Water is to control the inclusion of water geometry in ray tracing effects within Unreal Engine 5. This setting is specifically related to the rendering system, particularly the ray tracing subsystem.

The Water plugin in Unreal Engine 5’s experimental features relies on this setting variable. It is used within the WaterMeshSceneProxy.cpp file, which is part of the Water plugin’s runtime module.

The value of this variable is set through a console variable (CVar) system. It is initialized with a default value of 0, which means water is disabled in ray tracing by default.

The associated variable CVarRayTracingGeometryWater directly interacts with r.RayTracing.Geometry.Water. They share the same value and purpose.

Developers must be aware that:

  1. This feature is part of the experimental Water plugin.
  2. It’s only relevant when ray tracing is enabled (RHI_RAYTRACING is defined).
  3. The default setting (0) excludes water from ray tracing effects, which may impact performance and visual fidelity.

Best practices when using this variable include:

  1. Only enable it when specifically needed for water-related ray tracing effects.
  2. Consider the performance implications of including water in ray tracing, especially for large water bodies or scenes with multiple water surfaces.
  3. Test thoroughly with both enabled and disabled states to ensure desired visual results and performance.

Regarding the associated variable CVarRayTracingGeometryWater:

The purpose of CVarRayTracingGeometryWater is to provide programmatic access to the r.RayTracing.Geometry.Water setting within the C++ code.

It is used in the Water plugin’s runtime module, specifically in the WaterMeshSceneProxy class.

The value of this variable is set through the CVar system, mirroring the r.RayTracing.Geometry.Water setting.

It directly interacts with the FWaterMeshSceneProxy::GetDynamicRayTracingInstances function, determining whether water should be included in ray tracing instances.

Developers should be aware that:

  1. This variable is only defined when RHI_RAYTRACING is enabled.
  2. It controls whether the water mesh contributes to ray tracing effects.

Best practices include:

  1. Use CVarRayTracingGeometryWater.GetValueOnRenderThread() to access the current setting value in render thread code.
  2. Consider caching the value if used frequently to avoid repeated CVar lookups.
  3. Be mindful of the performance implications when enabling water in ray tracing, especially in complex scenes.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

#if RHI_RAYTRACING
static TAutoConsoleVariable<int32> CVarRayTracingGeometryWater(
	TEXT("r.RayTracing.Geometry.Water"),
	0,
	TEXT("Include water in ray tracing effects (default = 0 (water disabled in ray tracing))"));
#endif

static TAutoConsoleVariable<int32> CVarWaterMeshOcclusionCulling(
	TEXT("r.Water.WaterMesh.OcclusionCulling"),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:


#if RHI_RAYTRACING
static TAutoConsoleVariable<int32> CVarRayTracingGeometryWater(
	TEXT("r.RayTracing.Geometry.Water"),
	0,
	TEXT("Include water in ray tracing effects (default = 0 (water disabled in ray tracing))"));
#endif

static TAutoConsoleVariable<int32> CVarWaterMeshOcclusionCulling(

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

Scope (from outer to inner):

file
function     void FWaterMeshSceneProxy::GetDynamicRayTracingInstances

Source code excerpt:

void FWaterMeshSceneProxy::GetDynamicRayTracingInstances(FRayTracingMaterialGatheringContext& Context, TArray<FRayTracingInstance>& OutRayTracingInstances)
{
	if (!HasWaterData() || !FWaterUtils::IsWaterMeshRenderingEnabled(/*bIsRenderThread = */true) || !CVarRayTracingGeometryWater.GetValueOnRenderThread())
	{
		return;
	}

	const FSceneView& SceneView = *Context.ReferenceView;
	const FVector ObserverPosition = SceneView.ViewMatrices.GetViewOrigin();