r.FilmGrain
r.FilmGrain
#Overview
name: r.FilmGrain
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Whether to enable film grain.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.FilmGrain is to control whether film grain effect is enabled in the rendering process. This setting variable is part of Unreal Engine’s post-processing system, specifically for adding a film grain effect to the rendered image.
The r.FilmGrain variable is used in the Renderer module of Unreal Engine, as evidenced by its location in the SceneRendering.cpp file. This module is responsible for rendering the game scene.
The value of this variable is set through a console variable (CVarFilmGrain) with a default value of 1, meaning it’s enabled by default. It can be changed at runtime through console commands or programmatically.
The r.FilmGrain variable interacts with several other factors to determine if film grain should be applied:
- The FilmGrainIntensity post-process setting must be greater than 0.
- The Grain engine show flag must be enabled.
- The current shader platform must support film grain (checked by SupportsFilmGrain function).
Developers should be aware that:
- This setting is render thread safe, meaning it can be changed without causing threading issues.
- It’s a boolean value (0 disables, non-zero enables).
- It’s used in conjunction with other settings and engine flags to determine the final film grain effect.
Best practices when using this variable include:
- Consider performance implications when enabling film grain, especially on lower-end devices.
- Use it in combination with FilmGrainIntensity for fine-tuned control over the effect.
- Be aware of how it interacts with other post-processing effects.
Regarding the associated variable CVarFilmGrain:
The purpose of CVarFilmGrain is to provide a console-accessible way to control the r.FilmGrain setting. It’s defined as a TAutoConsoleVariable, which allows it to be changed at runtime through console commands.
CVarFilmGrain is used in the same Renderer module and is directly tied to the r.FilmGrain setting. Its value is set to 1 by default, enabling film grain.
The value of CVarFilmGrain can be changed through console commands or programmatically using C++ code.
Developers should be aware that:
- Changes to CVarFilmGrain will immediately affect the r.FilmGrain setting.
- It’s checked on the game thread (GetValueOnGameThread), which means changes may not be immediately reflected in the renderer.
Best practices for using CVarFilmGrain include:
- Use it for debugging or testing different film grain settings during development.
- Consider exposing it as an in-game graphics option for players to toggle.
- Be cautious about changing it frequently, as it may impact performance due to the game thread check.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:377
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarFilmGrain(
TEXT("r.FilmGrain"), 1,
TEXT("Whether to enable film grain."),
ECVF_RenderThreadSafe);
#if !UE_BUILD_SHIPPING
static TAutoConsoleVariable<int32> CVarTestInternalViewRectOffset(
#Associated Variable and Callsites
This variable is associated with another variable named CVarFilmGrain
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:376
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<int32> CVarFilmGrain(
TEXT("r.FilmGrain"), 1,
TEXT("Whether to enable film grain."),
ECVF_RenderThreadSafe);
#if !UE_BUILD_SHIPPING
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:2706
Scope (from outer to inner):
file
function FSceneRenderer::FSceneRenderer
Source code excerpt:
if (ViewInfo->FinalPostProcessSettings.FilmGrainIntensity > 0.0f &&
ViewFamily.EngineShowFlags.Grain &&
CVarFilmGrain.GetValueOnGameThread() != 0 &&
SupportsFilmGrain(ViewFamily.GetShaderPlatform()))
{
UTexture2D* FilmGrainTexture = ViewInfo->FinalPostProcessSettings.FilmGrainTexture;
if (FilmGrainTexture == nullptr)
{
GEngine->LoadDefaultFilmGrainTexture();