UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LandscapeGrassWeightExporter.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
7
8class ALandscapeProxy;
11class FRDGTexture;
15
16namespace UE::Landscape
17{
18 LANDSCAPE_API bool CanRenderGrassMap(ULandscapeComponent* Component);
20}
21
22// Hacky base class to avoid 8 bytes of padding after the vtable
28
29// data also accessible by render thread
31{
34
35private:
37
38public:
40
41 const FIntPoint& GetTargetSize() const { return TargetSize; }
42
45
46private:
47 struct FComponentInfo
48 {
50 TArray<TObjectPtr<ULandscapeGrassType>> RequestedGrassTypes;
52 int32 PixelOffsetX = 0;
53 FLandscapeComponentSceneProxy* SceneProxy = nullptr;
54 int32 NumPasses = 0;
55 int32 FirstHeightMipsPassIndex = MAX_int32;
56
57 FComponentInfo(ULandscapeComponent* InComponent, bool bInNeedsGrassmap, bool bInNeedsHeightmap, const TArray<int32>& InHeightMips)
59 , SceneProxy((FLandscapeComponentSceneProxy*)InComponent->SceneProxy)
60 {
62 {
63 RequestedGrassTypes = InComponent->GetGrassTypes();
64 }
65 int32 NumGrassMaps = RequestedGrassTypes.Num();
67 {
68 // 2 channels for the heightmap, and one channel for each grass map, packed into 4 channel render targets
69 NumPasses += FMath::DivideAndRoundUp(2 /* heightmap */ + NumGrassMaps, 4);
70 }
71
72#if WITH_EDITORONLY_DATA
73 // since we don't read HeightMips unless we are in editor, there's no reason to add passes for it unless we are in editor
74 if (InHeightMips.Num() > 0)
75 {
76 FirstHeightMipsPassIndex = NumPasses;
77 NumPasses += InHeightMips.Num();
78 }
79#endif // WITH_EDITORONLY_DATA
80 }
81 };
82
83 FSceneInterface* SceneInterface = nullptr;
85 FIntPoint TargetSize;
86 TArray<int32> HeightMips;
87 float PassOffsetX;
88 FVector ViewOrigin;
89
90 // game thread synchronous, do not access directly from render thread
91 FLandscapeAsyncTextureReadback* GameThreadAsyncReadbackPtr = nullptr;
92
93 FMatrix ViewRotationMatrix;
94 FMatrix ProjectionMatrix;
95
98};
99
101{
103
104private:
105 TObjectPtr<ALandscapeProxy> LandscapeProxy;
106 int32 ComponentSizeVerts;
107 int32 SubsectionSizeQuads;
108 int32 NumSubsections;
110
111public:
113
114 // If using the async readback path, check its status and update if needed. Return true when the AsyncReadbackResults are available.
115 // You must call this periodically, or the async readback may not complete.
116 // bInForceFinish will force the RenderThread to wait until GPU completes the readback, ensuring the readback is completed after the render thread executes the command.
117 // NOTE: you may still see false returned, this just means the render thread hasn't executed the command yet.
119
120 // return true if the async readback is complete. (Does not update the readback state)
122
123 // Fetches the results from the GPU texture and translates them into FLandscapeComponentGrassDatas.
124 // If using async readback, requires AsyncReadback to be complete before calling this.
125 // bFreeAsyncReadback if true will call FreeAsyncReadback() to free the readback resource (otherwise you must do it manually)
127
128private:
129 void FreeAsyncReadback();
130
131 // Applies the results using pre-fetched data.
132 static void ApplyResults(TMap<ULandscapeComponent*, TUniquePtr<FLandscapeComponentGrassData>, TInlineSetAllocator<1>>& Results);
133
134 // Fetches the results and applies them to the landscape components
135 // If using async readback, requires AsyncReadback to be complete before calling this.
136 void ApplyResults();
137
138 void CancelAndSelfDestruct();
139};
140
142{
143 void AddGrassWeightShaderTypes(FMaterialShaderTypes& InOutShaderTypes);
144}
145
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 MAX_int32
Definition NumericLimits.h:25
Definition LandscapeAsyncTextureReadback.h:13
Definition LandscapeRender.h:702
Definition LandscapeGrassMapsBuilder.h:44
Definition LandscapeGrassWeightExporter.h:24
Definition LandscapeGrassWeightExporter.h:31
friend class FLandscapeGrassWeightExporter
Definition LandscapeGrassWeightExporter.h:32
virtual ~FLandscapeGrassWeightExporter_RenderThread()
Definition LandscapeGrassWeightExporter.cpp:409
const FIntPoint & GetTargetSize() const
Definition LandscapeGrassWeightExporter.h:41
LANDSCAPE_API void RenderLandscapeComponentToTexture_RenderThread(FRDGBuilder &GraphBuilder, FRDGTextureRef OutputTexture)
Definition LandscapeGrassWeightExporter.cpp:443
Definition LandscapeGrassWeightExporter.h:101
TMap< ULandscapeComponent *, TUniquePtr< FLandscapeComponentGrassData >, TInlineSetAllocator< 1 > > FetchResults(bool bFreeAsyncReadback)
Definition LandscapeGrassWeightExporter.cpp:706
bool IsAsyncReadbackComplete()
Definition LandscapeGrassWeightExporter.cpp:577
bool CheckAndUpdateAsyncReadback(bool &bOutRenderCommandsQueued, const bool bInForceFinish=false)
Definition LandscapeGrassWeightExporter.cpp:571
Definition RenderGraphBuilder.h:49
Definition RenderGraphResources.h:571
Definition RHICommandList.h:4626
Definition SceneInterface.h:106
Definition TextureResource.h:433
Definition ArrayView.h:139
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
Definition ContainerAllocationPolicies.h:1664
Definition UnrealString.h.inl:34
Definition UniquePtr.h:107
Definition TextureRenderTarget2D.h:104
Definition LandscapeGrassWeightExporter.h:142
Definition Landscape.h:55
LANDSCAPE_API bool CanRenderGrassMap(ULandscapeComponent *Component)
Definition LandscapeGrassMapsBuilder.cpp:214
LANDSCAPE_API bool IsRuntimeGrassMapGenerationSupported()
Definition LandscapeGrassMapsBuilder.cpp:265
Definition MaterialShaderType.h:198
static constexpr UE_FORCEINLINE_HINT T DivideAndRoundUp(T Dividend, T Divisor)
Definition UnrealMathUtility.h:694
Definition ObjectPtr.h:488
Definition IntPoint.h:25
static CORE_API const TVector2< double > ZeroVector
Definition Vector2D.h:63