r.Fog

r.Fog

#Overview

name: r.Fog

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.Fog is to control the rendering of fog effects in the Unreal Engine 5 environment. It is a setting variable used by the rendering system to enable or disable fog rendering.

The Unreal Engine rendering subsystem relies on this setting variable, specifically within the fog rendering module. This can be seen from the file location “Engine/Source/Runtime/Renderer/Private/FogRendering.cpp” where the variable is defined and used.

The value of this variable is set using a console variable (CVarFog) with a default value of 1 (enabled). It can be changed at runtime through console commands or programmatically.

The r.Fog variable interacts directly with its associated variable CVarFog. They share the same value and purpose.

Developers must be aware that this variable affects the entire fog rendering system. Setting it to 0 will disable all fog effects, while setting it to 1 (default) will enable fog rendering. This can have significant visual impacts on the game or application.

Best practices when using this variable include:

  1. Only disable fog (set to 0) when absolutely necessary, as it can significantly affect the visual quality and atmosphere of the scene.
  2. Consider performance implications when enabling fog, especially on lower-end hardware.
  3. Use this variable in conjunction with other fog-related settings for fine-tuned control over fog effects.

Regarding the associated variable CVarFog:

The purpose of CVarFog is to provide a programmatic interface to control the r.Fog setting. It is an instance of TAutoConsoleVariable, which allows for runtime modification of the fog rendering state.

CVarFog is used within the rendering subsystem to determine whether fog should be rendered. This can be seen in the ShouldRenderFog function, where CVarFog.GetValueOnRenderThread() is checked.

The value of CVarFog is set when it’s initialized, with a default value of 1. It can be modified through console commands or programmatically at runtime.

CVarFog interacts directly with the r.Fog setting, essentially serving as its backend implementation.

Developers should be aware that CVarFog is thread-safe for the render thread (ECVF_RenderThreadSafe) and is considered a scalability option (ECVF_Scalability). This means it can be safely adjusted in real-time and may be automatically adjusted based on the system’s performance capabilities.

Best practices for using CVarFog include:

  1. Use GetValueOnRenderThread() when accessing the value from render thread code.
  2. Consider exposing the fog toggle in graphics settings for users to adjust based on their preference or performance needs.
  3. Be cautious when frequently changing this value, as it can impact performance and visual consistency.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarFog(
	TEXT("r.Fog"),
	1,
	TEXT(" 0: disabled\n")
	TEXT(" 1: enabled (default)"),
	ECVF_RenderThreadSafe | ECVF_Scalability);

static TAutoConsoleVariable<bool> CVarFogUseDepthBounds(

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

DECLARE_GPU_DRAWCALL_STAT(Fog);

static TAutoConsoleVariable<int32> CVarFog(
	TEXT("r.Fog"),
	1,
	TEXT(" 0: disabled\n")
	TEXT(" 1: enabled (default)"),
	ECVF_RenderThreadSafe | ECVF_Scalability);

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

Scope (from outer to inner):

file
function     bool ShouldRenderFog

Source code excerpt:

		&& EngineShowFlags.Materials 
		&& !Family.UseDebugViewPS()
		&& CVarFog.GetValueOnRenderThread() == 1
		&& !EngineShowFlags.StationaryLightOverlap 
		&& !EngineShowFlags.LightMapDensity;
}
float GetFogDefaultStartDistance()
{
	return 30.0f;