UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PackedNormal.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3
4#pragma once
5
6#include "CoreMinimal.h"
8
9// LWC_TODO: Packed normals need proper double vector support.
10
13{
14 union
15 {
16 struct
17 {
18 int8 X, Y, Z, W;
19
20 };
23
24 // Constructors.
25
26 FPackedNormal() { Vector.Packed = 0; }
27 FPackedNormal(const FVector3f& InVector) { *this = InVector; }
28 FPackedNormal(const FVector3d& InVector) { *this = InVector; }
29 FPackedNormal(const FVector4f& InVector) { *this = InVector; }
30 FPackedNormal(const FVector4d& InVector) { *this = InVector; }
31
32 // Conversion operators.
33
34 void operator=(const FVector3f& InVector);
35 void operator=(const FVector3d& InVector);
36 void operator=(const FVector4f& InVector);
37 void operator=(const FVector4d& InVector);
39
40 FVector ToFVector() const;
41 FVector3f ToFVector3f() const;
42 FVector4 ToFVector4() const;
43 FVector4f ToFVector4f() const;
44
45 // Set functions.
46 void Set(const FVector& InVector) { *this = InVector; }
47
48 // Equality operator.
49
50 bool operator==(const FPackedNormal& B) const;
51 bool operator!=(const FPackedNormal& B) const;
52
53 // Serializer.
54
55 FString ToString() const
56 {
57 return FString::Printf(TEXT("X=%d Y=%d Z=%d W=%d"), Vector.X, Vector.Y, Vector.Z, Vector.W);
58 }
59
61};
62
64
66{
67 union
68 {
69 struct
70 {
71 uint8 X, Y, Z, W;
72 };
74 } Vector;
75
76public:
77 operator FVector3f() const
78 {
79 // Rescale [0..255] range to [-1..1]
82
85
86 return UnpackedVector;
87 }
88
89 operator FVector3d() const
90 {
91 FVector3f AsFloat = *this;
92 return FVector3d(AsFloat);
93 }
94
95 operator FVector4f() const
96 {
97 // Rescale [0..255] range to [-1..1]
100
103
104 return UnpackedVector;
105 }
106
107 operator FVector4d() const
108 {
109 FVector4f AsFloat = *this;
110 return FVector4d(AsFloat);
111 }
112
114};
115
116inline void FPackedNormal::operator=(const FVector3f& InVector)
117{
118 const float Scale = MAX_int8;
119 Vector.X = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.X * Scale), MIN_int8, MAX_int8);
120 Vector.Y = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Y * Scale), MIN_int8, MAX_int8);
121 Vector.Z = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Z * Scale), MIN_int8, MAX_int8);
122 Vector.W = MAX_int8;
123}
124
125inline void FPackedNormal::operator=(const FVector3d& InVector)
126{
127 const float Scale = MAX_int8;
128 Vector.X = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.X * Scale), MIN_int8, MAX_int8);
129 Vector.Y = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Y * Scale), MIN_int8, MAX_int8);
130 Vector.Z = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Z * Scale), MIN_int8, MAX_int8);
131 Vector.W = MAX_int8;
132}
133
134inline void FPackedNormal::operator=(const FVector4f& InVector)
135{
136 const float Scale = MAX_int8;
137 Vector.X = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.X * Scale), MIN_int8, MAX_int8);
138 Vector.Y = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Y * Scale), MIN_int8, MAX_int8);
139 Vector.Z = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Z * Scale), MIN_int8, MAX_int8);
140 Vector.W = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.W * Scale), MIN_int8, MAX_int8);
141}
142
143inline void FPackedNormal::operator=(const FVector4d& InVector)
144{
145 const float Scale = MAX_int8;
146 Vector.X = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.X * Scale), MIN_int8, MAX_int8);
147 Vector.Y = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Y * Scale), MIN_int8, MAX_int8);
148 Vector.Z = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Z * Scale), MIN_int8, MAX_int8);
149 Vector.W = (int8)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.W * Scale), MIN_int8, MAX_int8);
150}
151
153{
154 return Vector.Packed == B.Vector.Packed;
155}
156
158{
159 return !(*this == B);
160}
161
163{
164 // LWC_TODO: Support FVector3d
165 return FVector(ToFVector3f());
166}
167
176
178{
179 // LWC_TODO: Support FVector4d
180 return FVector4(ToFVector4f());
181}
182
184{
186 // Write to FVector4f and return it.
189 return UnpackedVector;
190}
191
193{
194 // Rescale [0..255] range to [-1..1]
197 // Return unpacked vector register.
198 return VectorToUnpack;
199}
200
203{
204 union
205 {
206 struct
207 {
208#if PLATFORM_LITTLE_ENDIAN
209 uint32 X : 10;
210 uint32 Y : 10;
211 uint32 Z : 10;
212 uint32 W : 2;
213#else
215 uint32 Z : 10;
216 uint32 Y : 10;
217 uint32 X : 10;
218#endif
219 };
220
221 struct
222 {
224 };
226
227 // Constructors.
228
229 FPackedRGB10A2N() { Vector.Packed = 0; }
230 FPackedRGB10A2N(const FVector3f& InVector) { *this = InVector; }
231 FPackedRGB10A2N(const FVector3d& InVector) { *this = InVector; }
232 FPackedRGB10A2N(const FVector4f& InVector) { *this = InVector; }
233
234 // Conversion operators.
235
236 void operator=(const FVector3f& InVector);
237 void operator=(const FVector3d& InVector);
238 void operator=(const FVector4f& InVector);
239
241
242 // Set functions.
243 void Set(const FVector3f& InVector) { *this = InVector; }
244 void Set(const FVector3d& InVector) { *this = InVector; }
245 void Set(const FVector4f& InVector) { *this = InVector; }
246
247 // Equality operator.
248
249 bool operator==(const FPackedRGB10A2N& B) const;
250 bool operator!=(const FPackedRGB10A2N& B) const;
251
252 // Serializer.
253
255
256 FString ToString() const
257 {
258 return FString::Printf(TEXT("X=%d Y=%d Z=%d W=%d"), Vector.X, Vector.Y, Vector.Z, Vector.W);
259 }
260
262};
263
264inline void FPackedRGB10A2N::operator=(const FVector3f& InVector)
265{
266 Vector.X = FMath::Clamp(FMath::TruncToInt32(InVector.X * 511.5f + 511.5f), 0, 1023);
267 Vector.Y = FMath::Clamp(FMath::TruncToInt32(InVector.Y * 511.5f + 511.5f), 0, 1023);
268 Vector.Z = FMath::Clamp(FMath::TruncToInt32(InVector.Z * 511.5f + 511.5f), 0, 1023);
269 Vector.W = 3;
270}
271
272inline void FPackedRGB10A2N::operator=(const FVector3d& InVector)
273{
274 Vector.X = FMath::Clamp(FMath::TruncToInt32(InVector.X * 511.5f + 511.5f), 0, 1023);
275 Vector.Y = FMath::Clamp(FMath::TruncToInt32(InVector.Y * 511.5f + 511.5f), 0, 1023);
276 Vector.Z = FMath::Clamp(FMath::TruncToInt32(InVector.Z * 511.5f + 511.5f), 0, 1023);
277 Vector.W = 3;
278}
279
280inline void FPackedRGB10A2N::operator=(const FVector4f& InVector)
281{
282 Vector.X = FMath::Clamp(FMath::TruncToInt32(InVector.X * 511.5f + 511.5f), 0, 1023);
283 Vector.Y = FMath::Clamp(FMath::TruncToInt32(InVector.Y * 511.5f + 511.5f), 0, 1023);
284 Vector.Z = FMath::Clamp(FMath::TruncToInt32(InVector.Z * 511.5f + 511.5f), 0, 1023);
285 Vector.W = FMath::Clamp(FMath::TruncToInt32(InVector.W * 1.5f + 1.5f), 0, 3);
286}
287
289{
290 return Vector.Packed == B.Vector.Packed;
291}
292
294{
295 return !(*this == B);
296}
297
299{
301 VectorToUnpack = VectorMultiplyAdd(VectorToUnpack, MakeVectorRegister(2.0f, 2.0f, 2.0f, 2.0f), MakeVectorRegister(-1.0f, -1.0f, -1.0f, -1.0f));
303 // Return unpacked vector register.
304 return VectorToUnpack;
305}
306
309{
310 struct
311 {
316 };
317
318 // Constructors.
319
320 FPackedRGBA16N() { X = 0; Y = 0; Z = 0; W = 0; }
321 FPackedRGBA16N(const FVector3d& InVector) { *this = InVector; }
322 FPackedRGBA16N(const FVector3f& InVector) { *this = InVector; }
323 FPackedRGBA16N(const FVector4f& InVector) { *this = InVector; }
324 //FPackedRGBA16N(uint16 InX, uint16 InY, uint16 InZ, uint16 InW) { X = InX; Y = InY; Z = InZ; W = InW; }
325
326 // Conversion operators.
327
328 void operator=(const FVector3d& InVector);
329 void operator=(const FVector3f& InVector);
330 void operator=(const FVector4f& InVector);
331 void operator=(const FVector4d& InVector);
332
333 FVector ToFVector() const;
334 FVector3f ToFVector3f() const;
335 FVector4 ToFVector4() const;
336 FVector4f ToFVector4f() const;
337
339
340 // Set functions.
341 void Set(const FVector3d& InVector) { *this = InVector; }
342 void Set(const FVector3f& InVector) { *this = InVector; }
343 void Set(const FVector4f& InVector) { *this = InVector; }
344
345 // Equality operator.
346
347 bool operator==(const FPackedRGBA16N& B) const;
348 bool operator!=(const FPackedRGBA16N& B) const;
349
350 FString ToString() const
351 {
352 return FString::Printf(TEXT("X=%d Y=%d Z=%d W=%d"), X, Y, Z, W);
353 }
354
356};
357
359
360inline void FPackedRGBA16N::operator=(const FVector3f& InVector)
361{
362 const float Scale = MAX_int16;
363 X = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.X * Scale), MIN_int16, MAX_int16);
364 Y = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Y * Scale), MIN_int16, MAX_int16);
365 Z = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Z * Scale), MIN_int16, MAX_int16);
366 W = MAX_int16;
367}
368
369inline void FPackedRGBA16N::operator=(const FVector3d& InVector)
370{
371 const float Scale = MAX_int16;
372 X = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.X * Scale), MIN_int16, MAX_int16);
373 Y = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Y * Scale), MIN_int16, MAX_int16);
374 Z = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Z * Scale), MIN_int16, MAX_int16);
375 W = MAX_int16;
376}
377
378inline void FPackedRGBA16N::operator=(const FVector4f& InVector)
379{
380 const float Scale = MAX_int16;
381 X = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.X * Scale), MIN_int16, MAX_int16);
382 Y = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Y * Scale), MIN_int16, MAX_int16);
383 Z = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Z * Scale), MIN_int16, MAX_int16);
384 W = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.W * Scale), MIN_int16, MAX_int16);
385}
386
387inline void FPackedRGBA16N::operator=(const FVector4d& InVector)
388{
389 const float Scale = MAX_int16;
390 X = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.X * Scale), MIN_int16, MAX_int16);
391 Y = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Y * Scale), MIN_int16, MAX_int16);
392 Z = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.Z * Scale), MIN_int16, MAX_int16);
393 W = (int16)FMath::Clamp<int32>(FMath::RoundToInt32(InVector.W * Scale), MIN_int16, MAX_int16);
394}
395
397{
398 return (X == B.X) && (Y == B.Y) && (Z == B.Z) && (W == B.W);
399}
400
402{
403 return !(*this == B);
404}
405
407{
408 // LWC_TODO: Support FVector3d
409 return FVector(ToFVector3f());
410}
411
420
422{
423 // LWC_TODO: Support FVector4d
424 return FVector4(ToFVector4f());
425}
426
435
437{
440 // Return unpacked vector register.
441 return VectorToUnpack;
442}
FPlatformTypes::int16 int16
A 16-bit signed integer.
Definition Platform.h:1123
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
#define TEXT(x)
Definition Platform.h:1272
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define FVector
Definition IOSSystemIncludes.h:8
UE::Math::TVector4< double > FVector4d
Definition MathFwd.h:62
UE::Math::TVector< float > FVector3f
Definition MathFwd.h:73
UE::Math::TVector4< double > FVector4
Definition MathFwd.h:49
UE::Math::TVector< double > FVector3d
Definition MathFwd.h:60
UE::Math::TVector4< float > FVector4f
Definition MathFwd.h:75
#define DECLARE_INTRINSIC_TYPE_LAYOUT(T)
Definition MemoryLayout.h:760
#define MIN_int16
Definition NumericLimits.h:15
#define MIN_int8
Definition NumericLimits.h:14
#define MAX_int16
Definition NumericLimits.h:24
#define MAX_int8
Definition NumericLimits.h:23
FORCEINLINE VectorRegister4Float VectorLoadSRGBA16N(void *Ptr)
Definition UnrealMathFPU.h:2268
FORCEINLINE VectorRegister4Float MakeVectorRegister(uint32 X, uint32 Y, uint32 Z, uint32 W)
Definition UnrealMathFPU.h:195
FORCEINLINE VectorRegister4Float VectorLoadURGB10A2N(void *Ptr)
Definition UnrealMathFPU.h:1875
FORCEINLINE VectorRegister4Float VectorSetFloat1(float F)
Definition UnrealMathFPU.h:518
FORCEINLINE VectorRegister4Float VectorMultiply(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:758
FORCEINLINE VectorRegister4Float VectorMultiplyAdd(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2, const VectorRegister4Float &Vec3)
Definition UnrealMathFPU.h:786
FORCEINLINE void VectorStore(const VectorRegister4Float &Vec, float *Dst)
Definition UnrealMathFPU.h:566
#define VectorResetFloatRegisters()
Definition UnrealMathFPU.h:1933
#define VectorLoadSignedByte4(Ptr)
Definition UnrealMathFPU.h:1823
#define VectorLoadByte4(Ptr)
Definition UnrealMathFPU.h:1814
FORCEINLINE void VectorStoreFloat3(const VectorRegister4Float &Vec, float *Dst)
Definition UnrealMathFPU.h:594
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition PackedNormal.h:66
uint8 W
Definition PackedNormal.h:71
friend RENDERCORE_API FArchive & operator<<(FArchive &Ar, FDeprecatedSerializedPackedNormal &N)
Definition RenderUtils.cpp:82
uint8 Y
Definition PackedNormal.h:71
uint8 X
Definition PackedNormal.h:71
uint8 Z
Definition PackedNormal.h:71
uint32 Packed
Definition PackedNormal.h:73
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592
Definition PackedNormal.h:13
void operator=(const FVector3f &InVector)
Definition PackedNormal.h:116
FString ToString() const
Definition PackedNormal.h:55
bool operator!=(const FPackedNormal &B) const
Definition PackedNormal.h:157
FVector ToFVector() const
Definition PackedNormal.h:162
FPackedNormal(const FVector3d &InVector)
Definition PackedNormal.h:28
bool operator==(const FPackedNormal &B) const
Definition PackedNormal.h:152
union FPackedNormal::@1687 Vector
int8 Y
Definition PackedNormal.h:18
void Set(const FVector &InVector)
Definition PackedNormal.h:46
FVector4 ToFVector4() const
Definition PackedNormal.h:177
uint32 Packed
Definition PackedNormal.h:21
VectorRegister4Float GetVectorRegister() const
Definition PackedNormal.h:192
int8 W
Definition PackedNormal.h:18
FPackedNormal()
Definition PackedNormal.h:26
int8 Z
Definition PackedNormal.h:18
FVector3f ToFVector3f() const
Definition PackedNormal.h:168
friend RENDERCORE_API FArchive & operator<<(FArchive &Ar, FPackedNormal &N)
Definition RenderUtils.cpp:88
FPackedNormal(const FVector4f &InVector)
Definition PackedNormal.h:29
int8 X
Definition PackedNormal.h:18
FPackedNormal(const FVector3f &InVector)
Definition PackedNormal.h:27
FVector4f ToFVector4f() const
Definition PackedNormal.h:183
FPackedNormal(const FVector4d &InVector)
Definition PackedNormal.h:30
Definition PackedNormal.h:203
FPackedRGB10A2N(const FVector4f &InVector)
Definition PackedNormal.h:232
FString ToString() const
Definition PackedNormal.h:256
void Set(const FVector3f &InVector)
Definition PackedNormal.h:243
void Set(const FVector3d &InVector)
Definition PackedNormal.h:244
uint32 Y
Definition PackedNormal.h:216
void operator=(const FVector3f &InVector)
Definition PackedNormal.h:264
uint32 W
Definition PackedNormal.h:214
bool operator!=(const FPackedRGB10A2N &B) const
Definition PackedNormal.h:293
VectorRegister4Float GetVectorRegister() const
Definition PackedNormal.h:298
static RENDERCORE_API FPackedRGB10A2N ZeroVector
Definition PackedNormal.h:261
union FPackedRGB10A2N::@1693 Vector
uint32 X
Definition PackedNormal.h:217
void Set(const FVector4f &InVector)
Definition PackedNormal.h:245
friend RENDERCORE_API FArchive & operator<<(FArchive &Ar, FPackedRGB10A2N &N)
uint32 Packed
Definition PackedNormal.h:223
uint32 Z
Definition PackedNormal.h:215
bool operator==(const FPackedRGB10A2N &B) const
Definition PackedNormal.h:288
FPackedRGB10A2N()
Definition PackedNormal.h:229
FPackedRGB10A2N(const FVector3f &InVector)
Definition PackedNormal.h:230
FPackedRGB10A2N(const FVector3d &InVector)
Definition PackedNormal.h:231
Definition PackedNormal.h:309
bool operator==(const FPackedRGBA16N &B) const
Definition PackedNormal.h:396
FPackedRGBA16N(const FVector4f &InVector)
Definition PackedNormal.h:323
bool operator!=(const FPackedRGBA16N &B) const
Definition PackedNormal.h:401
int16 W
Definition PackedNormal.h:315
FVector4 ToFVector4() const
Definition PackedNormal.h:421
void operator=(const FVector3d &InVector)
Definition PackedNormal.h:369
friend RENDERCORE_API FArchive & operator<<(FArchive &Ar, FPackedRGBA16N &N)
Definition RenderUtils.cpp:94
int16 Z
Definition PackedNormal.h:314
FVector4f ToFVector4f() const
Definition PackedNormal.h:427
FPackedRGBA16N()
Definition PackedNormal.h:320
FPackedRGBA16N(const FVector3f &InVector)
Definition PackedNormal.h:322
FVector ToFVector() const
Definition PackedNormal.h:406
FString ToString() const
Definition PackedNormal.h:350
int16 Y
Definition PackedNormal.h:313
void Set(const FVector4f &InVector)
Definition PackedNormal.h:343
int16 X
Definition PackedNormal.h:312
FPackedRGBA16N(const FVector3d &InVector)
Definition PackedNormal.h:321
FVector3f ToFVector3f() const
Definition PackedNormal.h:412
void Set(const FVector3f &InVector)
Definition PackedNormal.h:342
void Set(const FVector3d &InVector)
Definition PackedNormal.h:341
VectorRegister4Float GetVectorRegister() const
Definition PackedNormal.h:436
T Y
Definition Vector4.h:46
T Z
Definition Vector4.h:49
T W
Definition Vector4.h:52
T X
Definition Vector4.h:43
T Z
Definition Vector.h:68
T Y
Definition Vector.h:65
T X
Definition Vector.h:62
Definition UnrealMathFPU.h:20