UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
RenderingVisualizationUtils.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "SceneRendering.h"
6#include "ScreenPass.h"
7#include "UnrealEngine.h"
8
9template <typename EntryContainerType>
11{
12 AddDrawCanvasPass(GraphBuilder, RDG_EVENT_NAME("Labels"), View, OutputTarget,
13 [&](FCanvas& Canvas)
14 {
16
17 const float DPIScale = Canvas.GetDPIScale();
18 Canvas.SetBaseTransform(FMatrix(FScaleMatrix(DPIScale) * Canvas.CalcBaseTransform2D(Canvas.GetViewRect().Width(), Canvas.GetViewRect().Height())));
19
20 auto DrawColorTile = [&](float X, float Y, float Width, float Height, const FLinearColor& Color)
21 {
22 Canvas.DrawTile(X/DPIScale, Y/DPIScale, Width/DPIScale, Height/DPIScale, 0, 0, 0, 0, Color);
23 };
24
25 auto DrawShadowedString = [&](float X, float Y, FStringView Text, const FLinearColor& Color = FLinearColor::White)
26 {
27 Canvas.DrawShadowedString(X / DPIScale, Y / DPIScale, Text, StatsFont, Color);
28 };
29
30 const float YStride = 20.0f * DPIScale;
31
33 auto DrawLegendEntry = [&](const FString& Label, FLinearColor Color)
34 {
35 DrawColorTile(LegendPosition.X + 7.0f * DPIScale, LegendPosition.Y + 5.0f * DPIScale, 10.0f * DPIScale, 10.0f * DPIScale, Color);
36 DrawShadowedString(LegendPosition.X + YStride, LegendPosition.Y + 2.0f * DPIScale, Label);
37 LegendPosition.Y += YStride;
38 };
39
40 auto GetStringWidth = [&](FStringView StringView) -> float
41 {
42 int32 XL = 0;
43 int32 YL = 0;
44 StringSize(StatsFont, XL, YL, StringView);
45 return float(XL);
46 };
47
48 float AutoSizeY = FMath::Max(LegendMinSize.Y, float(LegendEntries.Num() + 1) * 20.0f + 10.0f) * DPIScale;
49 // using lower left positioning
50 LegendPosition.Y -= AutoSizeY;
51
52 float AutoSizeX = FMath::Max(LegendMinSize.X, GetStringWidth(HeaderLabel));
53 for (const auto& Entry : LegendEntries)
54 {
55 AutoSizeX = FMath::Max(AutoSizeX, GetStringWidth(Entry.Label.ToString()));
56 }
57 AutoSizeX += 35.0f;
58 AutoSizeX *= DPIScale;
59
60 DrawColorTile(LegendPosition.X, LegendPosition.Y, AutoSizeX, AutoSizeY, FLinearColor(0.1f, 0.1f, 0.1f, 0.8f));
61 DrawShadowedString(LegendPosition.X + 5.0f * DPIScale, LegendPosition.Y + 5.0f * DPIScale, HeaderLabel);
62 LegendPosition.Y += YStride;
63
64 for (const auto& Entry : LegendEntries)
65 {
66 DrawLegendEntry(Entry.Label.ToString(), Entry.Color);
67 }
68 });
69}
ENGINE_API void StringSize(const UFont *Font, int32 &XL, int32 &YL, FStringView Text)
Definition Canvas.cpp:1181
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define X(Name, Desc)
Definition FormatStringSan.h:47
UE::Math::TMatrix< double > FMatrix
Definition MathFwd.h:51
#define RDG_EVENT_NAME(...)
Definition RenderGraphEvent.h:529
void AddLegendCanvasPass(FRDGBuilder &GraphBuilder, const FViewInfo &View, FScreenPassRenderTarget OutputTarget, const FString &HeaderLabel, FVector2f LegendAnchorPositionLowerLeft, FVector2f LegendMinSize, const EntryContainerType &LegendEntries)
Definition RenderingVisualizationUtils.h:10
void AddDrawCanvasPass(FRDGBuilder &GraphBuilder, FRDGEventName &&PassName, const FSceneView &View, FScreenPassRenderTarget Output, TFunction Function)
Definition ScreenPass.h:726
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
UFont * GetStatsFont()
Definition UnrealEngine.cpp:13672
Definition CanvasTypes.h:211
float GetDPIScale() const
Definition CanvasTypes.h:605
static ENGINE_API FMatrix CalcBaseTransform2D(uint32 ViewSizeX, uint32 ViewSizeY)
Definition Canvas.cpp:391
const FIntRect & GetViewRect() const
Definition CanvasTypes.h:567
ENGINE_API int32 DrawShadowedString(double StartX, double StartY, FStringView Text, const UFont *Font, const FLinearColor &Color, const FLinearColor &ShadowColor=FLinearColor::Black)
Definition Canvas.cpp:1130
ENGINE_API void DrawTile(double X, double Y, double SizeX, double SizeY, float U, float V, float SizeU, float SizeV, const FLinearColor &Color, const FTexture *Texture=NULL, bool AlphaBlend=true)
Definition Canvas.cpp:1102
ENGINE_API void SetBaseTransform(const FMatrix &Transform)
Definition Canvas.cpp:378
Definition RenderGraphBuilder.h:49
Definition SceneRendering.h:1132
Definition Font.h:111
Definition Color.h:48
static CORE_API const FLinearColor White
Definition Color.h:456
Definition ScreenPass.h:83
IntType Width() const
Definition IntRect.h:469
IntType Height() const
Definition IntRect.h:372
T Y
Definition Vector2D.h:52
T X
Definition Vector2D.h:49