r.Shadow.Preshadows
r.Shadow.Preshadows
#Overview
name: r.Shadow.Preshadows
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Whether to allow preshadows (static world casting on character)
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.Preshadows is to control whether preshadows are allowed in the rendering system. Preshadows are shadows cast by static world geometry onto dynamic objects, such as characters.
This setting variable is primarily used by the Renderer module of Unreal Engine, specifically in the shadow setup and rendering subsystem. It’s defined in the ShadowSetup.cpp file, which is part of the core rendering pipeline.
The value of this variable is set as a console variable using TAutoConsoleVariable. It’s initialized with a default value of 1 (enabled) but can be changed at runtime through console commands or programmatically.
The associated variable CVarAllowPreshadows directly interacts with r.Shadow.Preshadows. They share the same value and purpose, with CVarAllowPreshadows being the C++ representation of the console variable.
Developers must be aware that this variable affects the rendering performance and visual quality of the game. Enabling preshadows can enhance the visual fidelity by allowing static world objects to cast shadows on dynamic objects, but it may also impact performance.
Best practices when using this variable include:
- Consider the performance impact when enabling preshadows, especially on lower-end hardware.
- Use it in conjunction with other shadow settings to achieve the desired balance between visual quality and performance.
- Test the game thoroughly with different preshadow settings to ensure consistent performance across various scenarios.
Regarding the associated variable CVarAllowPreshadows:
- It’s a static TAutoConsoleVariable
that directly represents the r.Shadow.Preshadows console variable in C++ code. - It’s used in the CreatePerObjectProjectedShadow function to determine whether to render preshadows for specific objects.
- When working with shadow rendering code, developers should use CVarAllowPreshadows.GetValueOnRenderThread() to check if preshadows are enabled.
- This variable is thread-safe for render thread operations, as indicated by the ECVF_RenderThreadSafe flag.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:122
Scope: file
Source code excerpt:
/** Whether to allow preshadows (static world casting on character), can be disabled for debugging. */
static TAutoConsoleVariable<int32> CVarAllowPreshadows(
TEXT("r.Shadow.Preshadows"),
1,
TEXT("Whether to allow preshadows (static world casting on character)"),
ECVF_RenderThreadSafe
);
/** Whether to allow per object shadows (character casting on world), can be disabled for debugging. */
#Associated Variable and Callsites
This variable is associated with another variable named CVarAllowPreshadows
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:121
Scope: file
Source code excerpt:
/** Whether to allow preshadows (static world casting on character), can be disabled for debugging. */
static TAutoConsoleVariable<int32> CVarAllowPreshadows(
TEXT("r.Shadow.Preshadows"),
1,
TEXT("Whether to allow preshadows (static world casting on character)"),
ECVF_RenderThreadSafe
);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:3394
Scope (from outer to inner):
file
function void FSceneRenderer::CreatePerObjectProjectedShadow
Source code excerpt:
const bool bRenderPreShadow =
CVarAllowPreshadows.GetValueOnRenderThread()
&& LightSceneInfo->Proxy->HasStaticShadowing()
// Preshadow only affects the subject's pixels
&& bSubjectIsVisible
// Only objects with dynamic lighting should create a preshadow
// Unless we're in the editor and need to preview an object without built lighting
&& (!PrimitiveSceneInfo->Proxy->HasStaticLighting() || !Interaction->IsShadowMapped())