r.Paper2D.UsePrebuiltVertexBuffers

r.Paper2D.UsePrebuiltVertexBuffers

#Overview

name: r.Paper2D.UsePrebuiltVertexBuffers

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.Paper2D.UsePrebuiltVertexBuffers is to control whether sprites in the Paper2D module of Unreal Engine 5 are drawn using prebuilt vertex buffers.

This setting variable is primarily used in the Paper2D plugin, which is part of Unreal Engine’s 2D game development toolset. Specifically, it’s utilized in the rendering system for 2D sprites.

The value of this variable is set through a console variable (CVar) system in Unreal Engine. It’s initialized with a default value of 1 (true), meaning that by default, sprites will use prebuilt vertex buffers.

The associated variable CVarDrawSpritesUsingPrebuiltVertexBuffers directly interacts with r.Paper2D.UsePrebuiltVertexBuffers. They share the same value and purpose.

Developers should be aware that this variable affects the rendering performance of 2D sprites. Using prebuilt vertex buffers can potentially improve performance by reducing the need to construct vertex buffers at runtime.

Best practices when using this variable include:

  1. Leave it at its default value (1) unless you have specific reasons to change it.
  2. If you’re experiencing performance issues with 2D sprite rendering, you might experiment with toggling this value to see if it improves performance in your specific use case.
  3. Profile your game’s performance with this setting both on and off to determine which provides better results for your project.

Regarding the associated variable CVarDrawSpritesUsingPrebuiltVertexBuffers:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Plugins/2D/Paper2D/Source/Paper2D/Private/PaperRenderSceneProxy.cpp:13

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarDrawSpritesAsTwoSided(TEXT("r.Paper2D.DrawTwoSided"), 1, TEXT("Draw sprites as two sided."));
static TAutoConsoleVariable<int32> CVarDrawSpritesUsingPrebuiltVertexBuffers(TEXT("r.Paper2D.UsePrebuiltVertexBuffers"), 1, TEXT("Draw sprites using prebuilt vertex buffers."));

DECLARE_CYCLE_STAT(TEXT("Get New Batch Meshes"), STAT_PaperRender_GetNewBatchMeshes, STATGROUP_Paper2D);
DECLARE_CYCLE_STAT(TEXT("SpriteProxy GDME"), STAT_PaperRenderSceneProxy_GetDynamicMeshElements, STATGROUP_Paper2D);

FPackedNormal FPaperSpriteTangents::PackedNormalX(FVector(1.0f, 0.0f, 0.0f));
FPackedNormal FPaperSpriteTangents::PackedNormalZ(FVector(0.0f, -1.0f, 0.0f));

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Plugins/2D/Paper2D/Source/Paper2D/Private/PaperRenderSceneProxy.cpp:13

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarDrawSpritesAsTwoSided(TEXT("r.Paper2D.DrawTwoSided"), 1, TEXT("Draw sprites as two sided."));
static TAutoConsoleVariable<int32> CVarDrawSpritesUsingPrebuiltVertexBuffers(TEXT("r.Paper2D.UsePrebuiltVertexBuffers"), 1, TEXT("Draw sprites using prebuilt vertex buffers."));

DECLARE_CYCLE_STAT(TEXT("Get New Batch Meshes"), STAT_PaperRender_GetNewBatchMeshes, STATGROUP_Paper2D);
DECLARE_CYCLE_STAT(TEXT("SpriteProxy GDME"), STAT_PaperRenderSceneProxy_GetDynamicMeshElements, STATGROUP_Paper2D);

FPackedNormal FPaperSpriteTangents::PackedNormalX(FVector(1.0f, 0.0f, 0.0f));
FPackedNormal FPaperSpriteTangents::PackedNormalZ(FVector(0.0f, -1.0f, 0.0f));

#Loc: <Workspace>/Engine/Plugins/2D/Paper2D/Source/Paper2D/Private/PaperRenderSceneProxy.cpp:174

Scope (from outer to inner):

file
function     FPaperRenderSceneProxy::FPaperRenderSceneProxy

Source code excerpt:


	bDrawTwoSided = CVarDrawSpritesAsTwoSided.GetValueOnAnyThread() != 0;
	bSpritesUseVertexBufferPath = CVarDrawSpritesUsingPrebuiltVertexBuffers.GetValueOnAnyThread() != 0;
}

FPaperRenderSceneProxy::~FPaperRenderSceneProxy()
{
	for (FSpriteTextureOverrideRenderProxy* Proxy : MaterialTextureOverrideProxies)
	{