UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PrecomputedLightVolume.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 PrecomputedLightVolume.h: Declarations for precomputed light volumes.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "Misc/Guid.h"
11#include "Math/SHMath.h"
13#include "Math/GenericOctree.h"
14
15class FSceneInterface;
16
18template <int32 SHOrder>
20{
21public:
23 FVector3f Position; // LWC_TODO: Update to FVector once FVector4 supports doubles
25 float Radius;
26
34
37
40
42 Position(FVector(0, 0, 0)),
43 Radius(0),
44 PackedSkyBentNormal(FColor(127, 127, 255)),
46 {
47 }
48
51
53 {
54 PackedSkyBentNormal = FColor(FMath::TruncToInt((InSkyBentNormal.X * .5f + .5f) * 255.0f), FMath::TruncToInt((InSkyBentNormal.Y * .5f + .5f) * 255.0f), FMath::TruncToInt((InSkyBentNormal.Z * .5f + .5f) * 255.0f));
55 }
56
58 {
59 return FVector(PackedSkyBentNormal.R / 255.0f * 2.0f - 1.0f, PackedSkyBentNormal.G / 255.0f * 2.0f - 1.0f, PackedSkyBentNormal.B / 255.0f * 2.0f - 1.0f);
60 }
61
63};
64
68{
69 enum { MaxElementsPerLeaf = 4 };
70 enum { MaxNodeDepth = 12 };
71
74
75 // LWC_TODO: Update to return FVector::FReal once FVector4 supports doubles
76 inline static const float* GetBoundingBox(const FVolumeLightingSample& Sample)
77 {
79 // here we require that the position and radius are contiguous in memory
80 static_assert(STRUCT_OFFSET(FVolumeLightingSample, Position) + 3 * sizeof(float) == STRUCT_OFFSET(FVolumeLightingSample, Radius), "FVolumeLightingSample radius must follow position.");
81 return &Sample.Position.X;
82 }
83
85 {
86 }
87
88 inline static void ApplyOffset(FVolumeLightingSample& Element, FVector Offset)
89 {
90 Element.Position+= FVector3f(Offset); //LWC_TODO: Precision loss
91 }
92};
93
95
98{
99public:
100
103
106
108 ENGINE_API void Initialize(const FBox& NewBounds);
109
112
115
118
121
123
124 bool IsInitialized() const
125 {
126 return bInitialized;
127 }
128
130 {
131 return Bounds;
132 }
133
134private:
135
136 bool bInitialized;
137 FBox Bounds;
138
140 FLightVolumeOctree HighQualityLightmapOctree;
141
143 FLightVolumeOctree LowQualityLightmapOctree;
144
146};
147
148
151{
152public:
153
156
157 ENGINE_API void AddToScene(class FSceneInterface* Scene, class UMapBuildDataRegistry* Registry, FGuid LevelBuildDataId);
158
160
162
165 const FVector& Position,
166 float& AccumulatedWeight,
169 FVector& SkyBentNormal) const;
170
179
181
183
185
186 bool IsAddedToScene() const
187 {
188 return bAddedToScene;
189 }
190
191 double GetNodeLevelExtent(int32 Level) const
192 {
193 return OctreeForRendering->GetNodeLevelExtent(Level);
194 }
195
196 ENGINE_API void ApplyWorldOffset(const FVector& InOffset);
197
198 // temporary, for ES 3.1 preview verification.
199 inline bool IsUsingHighQualityLightMap() const
200 {
201 return OctreeForRendering == &Data->HighQualityLightmapOctree;
202 }
203
205
206private:
207
208 bool bAddedToScene;
209
211 const FLightVolumeOctree* OctreeForRendering;
212
214 FVector WorldOriginOffset;
215};
int Volume
Definition AndroidPlatformMisc.cpp:380
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define PLATFORM_CACHE_LINE_SIZE
Definition Platform.h:938
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define FVector
Definition IOSSystemIncludes.h:8
UE::Math::TVector< float > FVector3f
Definition MathFwd.h:73
TVolumeLightingSample< 3 > FVolumeLightingSample
Definition PrecomputedLightVolume.h:65
TVolumeLightingSample< 2 > FVolumeLightingSample2Band
Definition PrecomputedLightVolume.h:66
TOctree2< FVolumeLightingSample, FLightVolumeOctreeSemantics > FLightVolumeOctree
Definition PrecomputedLightVolume.h:94
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
#define STRUCT_OFFSET(struc, member)
Definition UnrealTemplate.h:218
uint32 Offset
Definition VulkanMemory.cpp:4033
Definition Archive.h:1208
Definition GenericOctree.h:42
Definition GenericOctreePublic.h:15
Definition PrecomputedLightVolume.h:98
ENGINE_API void AddHighQualityLightingSample(const FVolumeLightingSample &NewHighQualitySample)
Definition PrecomputedLightVolume.cpp:280
SIZE_T GetAllocatedBytes() const
Definition PrecomputedLightVolume.cpp:317
bool IsInitialized() const
Definition PrecomputedLightVolume.h:124
~FPrecomputedLightVolumeData()
Definition PrecomputedLightVolume.cpp:108
ENGINE_API void InvalidateLightingCache()
Definition PrecomputedLightVolume.cpp:304
friend FArchive & operator<<(FArchive &Ar, FPrecomputedLightVolumeData &Volume)
Definition PrecomputedLightVolume.cpp:147
ENGINE_API void FinalizeSamples()
Definition PrecomputedLightVolume.cpp:293
ENGINE_API void AddLowQualityLightingSample(const FVolumeLightingSample &NewLowQualitySample)
Definition PrecomputedLightVolume.cpp:286
FBox & GetBounds()
Definition PrecomputedLightVolume.h:129
ENGINE_API FPrecomputedLightVolumeData()
Definition PrecomputedLightVolume.cpp:102
Definition PrecomputedLightVolume.h:151
ENGINE_API void InterpolateIncidentRadianceBlock(const FBoxCenterAndExtent &BoundingBox, const FIntVector &QueryCellDimensions, const FIntVector &DestCellDimensions, const FIntVector &DestCellPosition, TArray< float > &AccumulatedWeights, TArray< FSHVectorRGB2 > &AccumulatedIncidentRadiance) const
Definition PrecomputedLightVolume.cpp:423
double GetNodeLevelExtent(int32 Level) const
Definition PrecomputedLightVolume.h:191
ENGINE_API void RemoveFromScene(FSceneInterface *Scene)
Definition PrecomputedLightVolume.cpp:363
bool IsAddedToScene() const
Definition PrecomputedLightVolume.h:186
ENGINE_API void AddToScene(class FSceneInterface *Scene, class UMapBuildDataRegistry *Registry, FGuid LevelBuildDataId)
Definition PrecomputedLightVolume.cpp:337
ENGINE_API void DebugDrawSamples(class FPrimitiveDrawInterface *PDI, bool bDrawDirectionalShadowing) const
Definition PrecomputedLightVolume.cpp:501
ENGINE_API bool IntersectBounds(const FBoxSphereBounds &InBounds) const
Definition PrecomputedLightVolume.cpp:514
~FPrecomputedLightVolume()
Definition PrecomputedLightVolume.cpp:333
const FPrecomputedLightVolumeData * Data
Definition PrecomputedLightVolume.h:204
bool IsUsingHighQualityLightMap() const
Definition PrecomputedLightVolume.h:199
ENGINE_API void SetData(const FPrecomputedLightVolumeData *NewData, FSceneInterface *Scene)
Definition PrecomputedLightVolume.cpp:378
SIZE_T GetAllocatedBytes() const
ENGINE_API FPrecomputedLightVolume()
Definition PrecomputedLightVolume.cpp:326
ENGINE_API void ApplyWorldOffset(const FVector &InOffset)
Definition PrecomputedLightVolume.cpp:525
ENGINE_API void InterpolateIncidentRadiancePoint(const FVector &Position, float &AccumulatedWeight, float &AccumulatedDirectionalLightShadowing, FSHVectorRGB3 &AccumulatedIncidentRadiance, FVector &SkyBentNormal) const
Definition PrecomputedLightVolume.cpp:384
Definition PrimitiveDrawInterface.h:19
Definition SceneInterface.h:106
Definition Array.h:670
Definition GenericOctree.h:378
FReal GetNodeLevelExtent(int32 Level) const
Definition GenericOctree.h:982
Definition SHMath.h:494
Definition ContainerAllocationPolicies.h:830
Definition PrecomputedLightVolume.h:20
FVector3f Position
Definition PrecomputedLightVolume.h:23
FVector GetSkyBentNormalUnpacked() const
Definition PrecomputedLightVolume.h:57
TSHVectorRGB< SHOrder > Lighting
Definition PrecomputedLightVolume.h:33
float DirectionalLightShadowing
Definition PrecomputedLightVolume.h:39
TVolumeLightingSample()
Definition PrecomputedLightVolume.h:41
TVolumeLightingSample(const TVolumeLightingSample< 2 > &Other)
friend FArchive & operator<<(FArchive &Ar, TVolumeLightingSample< SHOrder > &Sample)
TVolumeLightingSample(const TVolumeLightingSample< 3 > &Other)
FColor PackedSkyBentNormal
Definition PrecomputedLightVolume.h:36
void SetPackedSkyBentNormal(FVector InSkyBentNormal)
Definition PrecomputedLightVolume.h:52
float Radius
Definition PrecomputedLightVolume.h:25
Definition MapBuildDataRegistry.h:295
Definition Color.h:486
uint8 G
Definition Color.h:492
uint8 R
Definition Color.h:492
uint8 B
Definition Color.h:492
static FORCEINLINE void Prefetch(const void *Ptr)
Definition GenericPlatformMisc.h:1443
Definition Guid.h:109
Definition PrecomputedLightVolume.h:68
FDefaultAllocator ElementAllocator
Definition PrecomputedLightVolume.h:73
static void SetElementId(const FVolumeLightingSample &Element, FOctreeElementId2 Id)
Definition PrecomputedLightVolume.h:84
static void ApplyOffset(FVolumeLightingSample &Element, FVector Offset)
Definition PrecomputedLightVolume.h:88
@ MaxNodeDepth
Definition PrecomputedLightVolume.h:70
@ MaxElementsPerLeaf
Definition PrecomputedLightVolume.h:69
static const float * GetBoundingBox(const FVolumeLightingSample &Sample)
Definition PrecomputedLightVolume.h:76
Definition BoxSphereBounds.h:25