r.Water.SingleLayer.UnderwaterFogWhenCameraIsAboveWater

r.Water.SingleLayer.UnderwaterFogWhenCameraIsAboveWater

#Overview

name: r.Water.SingleLayer.UnderwaterFogWhenCameraIsAboveWater

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.SingleLayer.UnderwaterFogWhenCameraIsAboveWater is to control the rendering of underwater fog in relation to the camera’s position in a single-layer water system. It specifically addresses the rendering of height fog behind the water surface when the camera is above water.

This setting variable is primarily used in the rendering system of Unreal Engine 5, specifically in the fog rendering subsystem. Based on the callsites, it’s implemented in the FogRendering.cpp file, which is part of the Renderer module.

The value of this variable is set through a console variable (CVarUnderwaterFogWhenCameraIsAboveWater) with a default value of false. It can be changed at runtime using console commands or through project settings.

The associated variable CVarUnderwaterFogWhenCameraIsAboveWater directly interacts with r.Water.SingleLayer.UnderwaterFogWhenCameraIsAboveWater. They share the same value and purpose.

Developers must be aware that enabling this variable can cause visual artifacts when looking at the water surface from a distance. However, it can help avoid artifacts when entering and exiting water in scenes with strong height fog.

Best practices when using this variable include:

  1. Testing the visual impact in various scenarios, especially when transitioning between above and underwater views.
  2. Considering the trade-offs between artifact reduction during water entry/exit and potential distant view artifacts.
  3. Using it in conjunction with other water and fog-related settings for optimal visual results.

Regarding the associated variable CVarUnderwaterFogWhenCameraIsAboveWater:

Its purpose is identical to r.Water.SingleLayer.UnderwaterFogWhenCameraIsAboveWater, serving as the internal representation of the console variable.

It’s used in the Renderer module, specifically in the FogRendering.cpp file.

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

It directly controls the behavior of underwater fog rendering in the RenderUnderWaterFog function of the FDeferredShadingSceneRenderer class.

Developers should be aware that this variable is render thread safe, meaning it’s designed to be safely accessed from the render thread.

Best practices include using the GetValueOnRenderThread() method to access its value in render thread contexts and considering its performance implications in the fog rendering pipeline.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/FogRendering.cpp:38

Scope: file

Source code excerpt:


static TAutoConsoleVariable<bool> CVarUnderwaterFogWhenCameraIsAboveWater(
	TEXT("r.Water.SingleLayer.UnderwaterFogWhenCameraIsAboveWater"), 
	false, 
	TEXT("Renders height fog behind the water surface even when the camera is above water. This avoids artifacts when entering and exiting the water with strong height fog in the scene but causes artifacts when looking at the water surface from a distance."),
	ECVF_RenderThreadSafe);

IMPLEMENT_GLOBAL_SHADER_PARAMETER_STRUCT(FFogUniformParameters, "FogStruct");

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/FogRendering.cpp:37

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe | ECVF_Scalability);

static TAutoConsoleVariable<bool> CVarUnderwaterFogWhenCameraIsAboveWater(
	TEXT("r.Water.SingleLayer.UnderwaterFogWhenCameraIsAboveWater"), 
	false, 
	TEXT("Renders height fog behind the water surface even when the camera is above water. This avoids artifacts when entering and exiting the water with strong height fog in the scene but causes artifacts when looking at the water surface from a distance."),
	ECVF_RenderThreadSafe);

IMPLEMENT_GLOBAL_SHADER_PARAMETER_STRUCT(FFogUniformParameters, "FogStruct");

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/FogRendering.cpp:521

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderUnderWaterFog

Source code excerpt:

		{
			const FViewInfo& View = Views[ViewIndex];
			if (View.IsPerspectiveProjection() && (View.IsUnderwater() || CVarUnderwaterFogWhenCameraIsAboveWater.GetValueOnRenderThread()))
			{
				RDG_EVENT_SCOPE_CONDITIONAL(GraphBuilder, Views.Num() > 1, "View%d", ViewIndex);
				RDG_GPU_MASK_SCOPE(GraphBuilder, View.GPUMask);

				const auto& SceneWithoutWaterView = SceneWithoutWaterTextures.Views[ViewIndex];