Slate.DrawToVRRenderTarget
Slate.DrawToVRRenderTarget
#Overview
name: Slate.DrawToVRRenderTarget
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If enabled while in VR. Slate UI will be drawn into the render target texture where the VR imagery for either eye was rendered, allow the viewer of the HMD to see the UI (for better or worse.) This render target will then be cropped/scaled into the back buffer, if mirroring is enabled. When disabled, Slate UI will be drawn on top of the backbuffer (not to the HMD) after the mirror texture has been cropped/scaled into the backbuffer.
It is referenced in 5
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of Slate.DrawToVRRenderTarget is to control how Slate UI is rendered in VR environments. It determines whether the UI should be drawn directly into the VR render target or on top of the backbuffer.
This setting variable is primarily used by the Slate RHI Renderer subsystem, which is part of Unreal Engine’s UI rendering pipeline. It specifically affects how UI elements are rendered when using a VR headset.
The value of this variable is set through a console variable (CVarDrawToVRRenderTarget) in the SlateRHIRenderer.cpp file. It is initialized with a default value of 1, meaning it’s enabled by default.
The associated variable CVarDrawToVRRenderTarget interacts directly with Slate.DrawToVRRenderTarget. They share the same value and purpose.
Developers must be aware that:
- When enabled (set to 1), Slate UI will be drawn into the VR render target, making it visible in the HMD.
- When disabled (set to 0), Slate UI will be drawn on top of the backbuffer, not visible in the HMD but visible on the mirrored display.
Best practices when using this variable include:
- Consider the user experience in VR when deciding whether to enable or disable this feature.
- Test UI visibility and readability in both enabled and disabled states to ensure a good experience for both VR users and spectators.
- Be mindful of performance implications, as rendering UI into the VR target may have different performance characteristics than rendering to the backbuffer.
Regarding the associated variable CVarDrawToVRRenderTarget:
- It’s a TAutoConsoleVariable of type float, used to control the Slate.DrawToVRRenderTarget setting.
- It’s defined in the same file (SlateRHIRenderer.cpp) and is used to get the current value of the setting in various parts of the code.
- The GetDrawToVRRenderTarget() function in FSlateRHIRenderer class uses this variable to retrieve the current setting value.
- It’s checked in rendering logic to determine how to handle UI rendering in VR scenarios.
Developers should use CVarDrawToVRRenderTarget->GetInt() to retrieve the current value of the setting in their code when needed, rather than accessing Slate.DrawToVRRenderTarget directly.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/SlateRHIRenderer/Private/SlateRHIRenderer.cpp:92
Scope: file
Source code excerpt:
static TAutoConsoleVariable<float> CVarDrawToVRRenderTarget(
TEXT("Slate.DrawToVRRenderTarget"),
1,
TEXT("If enabled while in VR. Slate UI will be drawn into the render target texture where the VR imagery for either eye was rendered, allow the viewer of the HMD to see the UI (for better or worse.) This render target will then be cropped/scaled into the back buffer, if mirroring is enabled. When disabled, Slate UI will be drawn on top of the backbuffer (not to the HMD) after the mirror texture has been cropped/scaled into the backbuffer."),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarMemorylessDepthStencil(
TEXT("Slate.MemorylessDepthStencil"),
#Associated Variable and Callsites
This variable is associated with another variable named CVarDrawToVRRenderTarget
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/SlateRHIRenderer/Private/SlateRHIRenderer.cpp:91
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<float> CVarDrawToVRRenderTarget(
TEXT("Slate.DrawToVRRenderTarget"),
1,
TEXT("If enabled while in VR. Slate UI will be drawn into the render target texture where the VR imagery for either eye was rendered, allow the viewer of the HMD to see the UI (for better or worse.) This render target will then be cropped/scaled into the back buffer, if mirroring is enabled. When disabled, Slate UI will be drawn on top of the backbuffer (not to the HMD) after the mirror texture has been cropped/scaled into the backbuffer."),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarMemorylessDepthStencil(
#Loc: <Workspace>/Engine/Source/Runtime/SlateRHIRenderer/Private/SlateRHIRenderer.cpp:282
Scope (from outer to inner):
file
function int32 FSlateRHIRenderer::GetDrawToVRRenderTarget
Source code excerpt:
int32 FSlateRHIRenderer::GetDrawToVRRenderTarget()
{
return CVarDrawToVRRenderTarget->GetInt();
}
int32 FSlateRHIRenderer::GetProcessSlatePostBuffers()
{
return CVarCopyBackbufferToSlatePostRenderTargets->GetInt();
}
#Loc: <Workspace>/Engine/Source/Runtime/SlateRHIRenderer/Private/SlateRHIRenderer.cpp:1110
Scope (from outer to inner):
file
function void FSlateRHIRenderer::DrawWindow_RenderThread
Source code excerpt:
bool bRenderedStereo = false;
if (CVarDrawToVRRenderTarget->GetInt() == 0 && GEngine && IsValidRef(ViewportInfo.GetRenderTargetTexture()) && GEngine->StereoRenderingDevice.IsValid())
{
const FVector2D WindowSize = WindowElementList.GetWindowSize();
GEngine->StereoRenderingDevice->RenderTexture_RenderThread(RHICmdList, RHIGetViewportBackBuffer(ViewportInfo.ViewportRHI), ViewportInfo.GetRenderTargetTexture(), WindowSize);
bRenderedStereo = true;
}
#Loc: <Workspace>/Engine/Source/Runtime/SlateRHIRenderer/Private/SlateRHIRenderer.cpp:1828
Scope (from outer to inner):
file
lambda-function
Source code excerpt:
{
bool bRenderedStereo = false;
if (CVarDrawToVRRenderTarget->GetInt() == 0 && GEngine && IsValidRef(ViewInfo->GetRenderTargetTexture()) && GEngine->StereoRenderingDevice.IsValid())
{
GEngine->StereoRenderingDevice->RenderTexture_RenderThread(RHICmdList, RHIGetViewportBackBuffer(ViewInfo->ViewportRHI), ViewInfo->GetRenderTargetTexture(), ElementWindowSize);
bRenderedStereo = true;
}
FTexture2DRHIRef ViewportRT = bRenderedStereo ? nullptr : ViewInfo->GetRenderTargetTexture();