UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LandscapeLight.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 LandscapeLight.h: Static lighting for LandscapeComponents
5 =============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "PixelFormat.h"
11#include "StaticLighting.h"
12#include "RenderUtils.h"
13
14class FLightmassExporter;
16class ULandscapeComponent;
17class ULevel;
18class ULightComponent;
20
23{
24public:
27
28 // FStaticLightingTextureMapping interface
29 LANDSCAPE_API virtual void Apply(FQuantizedLightmapData* QuantizedData, const TMap<ULightComponent*,FShadowMapData2D*>& ShadowMapData, const FStaticLightingBuildContext* LightingContext);
30
31#if WITH_EDITOR
36 UNREALED_API virtual void ExportMapping(FLightmassExporter* Exporter);
37 LANDSCAPE_API virtual void Serialize(FArchive& Ar);
38
39#endif //WITH_EDITOR
40
42
43 virtual FString GetDescription() const
44 {
45 return FString(TEXT("LandscapeMapping"));
46 }
47private:
48
50 ULandscapeComponent* LandscapeComponent;
51};
52
54{
55public:
57
58 virtual void Apply(struct FQuantizedLightmapData* QuantizedData, const TMap<ULightComponent*,class FShadowMapData2D*>& ShadowMapData, const FStaticLightingBuildContext* LightingContext) override
59 {
60 // Should never be processed
61 check(false);
62 }
63
64#if WITH_EDITOR
65 virtual bool DebugThisMapping() const override
66 {
67 return false;
68 }
69
74 UNREALED_API virtual void ExportMapping(class FLightmassExporter* Exporter) override;
75#endif //WITH_EDITOR
76
78 virtual bool IsValidMapping() const override {return true;}
79
80 virtual FString GetDescription() const override
81 {
82 return FString(TEXT("LandscapeVolumeMapping"));
83 }
84};
85
86
89{
90public:
91 // tors
94
95 // FStaticLightingMesh interface
97 virtual void GetTriangleIndices(int32 TriangleIndex,int32& OutI0,int32& OutI1,int32& OutI2) const;
99
100 virtual bool IsInstancedMesh() const override { return false; }
101
102#if WITH_EDITOR
107 UNREALED_API virtual void ExportMeshInstance(FLightmassExporter* Exporter) const;
108#endif //WITH_EDITOR
109
110protected:
112
115
116 ULandscapeComponent* LandscapeComponent;
117
118 // FLandscapeStaticLightingMeshData
124
126 // Cache
129 float UVFactor;
131
132 friend class FLightmassExporter;
133
134#if WITH_EDITOR
135public:
136 // Cache data for Landscape upscaling data
138 UE_DEPRECATED(5.7, "RetopologizeTool/XYOffset deprecated with the removal of non-edit layer landscapes")
140#endif
141};
142
143namespace
144{
145 // LightmapRes: Multiplier of lightmap size relative to landscape size
146 // X: (Output) PatchExpandCountX (at Lighting LOD)
147 // Y: (Output) PatchExpandCountY (at Lighting LOD)
148 // ComponentSize: Component size in patches (at LOD 0)
149 // LigtmapSize: Size desired for lightmap (texels)
150 // DesiredSize: (Output) Recommended lightmap size (texels)
151 // return: LightMapRatio
152 static float GetTerrainExpandPatchCount(float LightMapRes, int32& X, int32& Y, int32 ComponentSize, int32 LightmapSize, int32& DesiredSize, uint32 LightingLOD)
153 {
154 if (LightMapRes <= 0) return 0.f;
155
156 // Assuming DXT_1 compression at the moment...
161
162 X = FMath::Max<int32>(1, PatchExpandCountX >> LightingLOD);
163 Y = FMath::Max<int32>(1, PatchExpandCountY >> LightingLOD);
164
165 DesiredSize = (LightMapRes >= 1.f) ? FMath::Min<int32>((int32)((ComponentSize + 1) * LightMapRes), 4096) : FMath::Min<int32>((int32)((LightmapSize)* LightMapRes), 4096);
167
168 // Find proper Lightmap Size
169 if (CurrentSize > DesiredSize)
170 {
171 // Find maximum bit
172 int32 PriorSize = DesiredSize;
173 while (DesiredSize > 0)
174 {
175 PriorSize = DesiredSize;
176 DesiredSize = DesiredSize & ~(DesiredSize & ~(DesiredSize - 1));
177 }
178
179 DesiredSize = PriorSize << 1; // next bigger size
180 if (CurrentSize * CurrentSize <= ((PriorSize * PriorSize) << 1))
181 {
182 DesiredSize = PriorSize;
183 }
184 }
185
186 const float DestSize = FMath::Floor(static_cast<float>(DesiredSize) / CurrentSize * (ComponentSize*LightMapRes));
187 const float LightMapRatio = DestSize / (ComponentSize*LightMapRes) * CurrentSize / DesiredSize;
188 return LightMapRatio;
189 }
190}
#define check(expr)
Definition AssertionMacros.h:314
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define TEXT(x)
Definition Platform.h:1272
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
FPixelFormatInfo GPixelFormats[PF_MAX]
Definition PixelFormat.cpp:31
@ PF_DXT1
Definition PixelFormat.h:22
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition LandscapeLight.h:54
virtual void Apply(struct FQuantizedLightmapData *QuantizedData, const TMap< ULightComponent *, class FShadowMapData2D * > &ShadowMapData, const FStaticLightingBuildContext *LightingContext) override
Definition LandscapeLight.h:58
virtual bool IsValidMapping() const override
Definition LandscapeLight.h:78
virtual FString GetDescription() const override
Definition LandscapeLight.h:80
LANDSCAPE_API FLandscapeStaticLightingGlobalVolumeMapping(ULandscapeComponent *InPrimitive, FStaticLightingMesh *InMesh, int32 InLightMapWidth, int32 InLightMapHeight, bool bPerformFullQualityRebuild)
Definition LandscapeLight.h:89
virtual bool IsInstancedMesh() const override
Definition LandscapeLight.h:100
FLandscapeStaticLightingMesh(ULandscapeComponent *InComponent, const TArray< ULightComponent * > &InRelevantLights, int32 InExpandQuadsX, int32 InExpandQuadsY, float LightMapRatio, int32 InLOD)
int32 NumVertices
Definition LandscapeLight.h:127
int32 NumQuads
Definition LandscapeLight.h:128
void GetStaticLightingVertex(int32 VertexIndex, FStaticLightingVertex &OutVertex) const
float LightMapRatio
Definition LandscapeLight.h:121
virtual FLightRayIntersection IntersectLightRay(const FVector &Start, const FVector &End, bool bFindNearestIntersection) const
ULandscapeComponent * LandscapeComponent
Definition LandscapeLight.h:116
void GetHeightmapData(int32 InLOD, int32 GeometryLOD)
int32 ComponentSizeQuads
Definition LandscapeLight.h:120
virtual void GetTriangle(int32 TriangleIndex, FStaticLightingVertex &OutV0, FStaticLightingVertex &OutV1, FStaticLightingVertex &OutV2) const
bool bReverseWinding
Definition LandscapeLight.h:130
virtual void GetTriangleIndices(int32 TriangleIndex, int32 &OutI0, int32 &OutI1, int32 &OutI2) const
int32 ExpandQuadsY
Definition LandscapeLight.h:123
int32 ExpandQuadsX
Definition LandscapeLight.h:122
float UVFactor
Definition LandscapeLight.h:129
FTransform LocalToWorld
Definition LandscapeLight.h:119
TArray< FColor > HeightData
Definition LandscapeLight.h:125
friend class FLightmassExporter
Definition LandscapeLight.h:132
Definition LandscapeLight.h:23
FLandscapeStaticLightingTextureMapping(ULandscapeComponent *InPrimitive, FStaticLightingMesh *InMesh, int32 InLightMapWidth, int32 InLightMapHeight, bool bPerformFullQualityRebuild)
virtual LANDSCAPE_API void Apply(FQuantizedLightmapData *QuantizedData, const TMap< ULightComponent *, FShadowMapData2D * > &ShadowMapData, const FStaticLightingBuildContext *LightingContext)
virtual FString GetDescription() const
Definition LandscapeLight.h:43
LANDSCAPE_API FLandscapeStaticLightingTextureMapping(const FArchive &Ar)
Definition StaticLighting.h:93
Definition ShadowMap.h:100
Definition StaticLighting.h:114
Definition StaticLighting.h:406
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition Level.h:423
Definition Color.h:486
Definition UnrealMathUtility.h:270
static UE_FORCEINLINE_HINT float Floor(float F)
Definition UnrealMathUtility.h:525
int32 BlockSizeX
Definition PixelFormat.h:467
int32 BlockSizeY
Definition PixelFormat.h:468
Definition LightMap.h:500
Definition StaticLighting.h:23
Definition IntPoint.h:25