UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
HLSLMaterialDerivativeAutogen.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "MaterialShared.h"
7
8#include "HLSLMaterialDerivativeAutogen.generated.h"
9
10class FHLSLMaterialTranslator;
11
19UENUM()
21{
24 Zero,
25 Valid,
26};
27
28#if WITH_EDITORONLY_DATA
29
30inline bool IsDerivativeValid(EDerivativeStatus Status)
31{
32 return Status == EDerivativeStatus::Valid || Status == EDerivativeStatus::Zero;
33}
34
35enum class EDerivativeType
36{
37 None = -1,
38 Float1 = 0,
39 Float2,
40 Float3,
41 Float4,
46 Num,
47};
48static const int32 NumDerivativeTypes = (int32)EDerivativeType::Num;
49
50inline bool IsLWCType(EDerivativeType Type)
51{
52 return (int32)Type >= (int32)EDerivativeType::LWCScalar;
53}
54
56{
57 switch (Type)
58 {
59 case EDerivativeType::LWCScalar: return EDerivativeType::Float1;
60 case EDerivativeType::LWCVector2: return EDerivativeType::Float2;
61 case EDerivativeType::LWCVector3: return EDerivativeType::Float3;
62 case EDerivativeType::LWCVector4: return EDerivativeType::Float4;
63 default: return Type;
64 }
65}
66
68{
69 switch (Type)
70 {
71 case EDerivativeType::Float1: return EDerivativeType::LWCScalar;
72 case EDerivativeType::Float2: return EDerivativeType::LWCVector2;
73 case EDerivativeType::Float3: return EDerivativeType::LWCVector3;
74 case EDerivativeType::Float4: return EDerivativeType::LWCVector4;
75 default: return Type;
76 }
77}
78
80
81
82struct FDerivInfo
83{
87};
88
90{
91public:
92 // Unary functions
93 enum class EFunc1
94 {
95 Abs,
96 Log,
97 Log2,
98 Log10,
99 Exp,
100 Exp2,
101 Sin,
102 Cos,
103 Tan,
104 Asin,
105 AsinFast,
106 Acos,
107 AcosFast,
108 Atan,
109 AtanFast,
110 Sqrt,
111 Rcp,
112 Rsqrt,
113 Saturate,
114 Frac,
115 Length,
116 InvLength,
117 Normalize,
118 Num
119 };
120
121 // Binary functions
122 enum class EFunc2
123 {
124 Add,
125 Sub,
126 Mul,
127 Div,
128 Fmod,
129 Modulo,
130 Max,
131 Min,
132 Dot, // Depends on Add/Mul, so it must come after them
133 Pow,
135 Cross,
136 Atan2,
137 Atan2Fast,
138 Num
139 };
140
141 int32 GenerateExpressionFunc1(FHLSLMaterialTranslator& Translator, EFunc1 Op, int32 SrcCode);
142 int32 GenerateExpressionFunc2(FHLSLMaterialTranslator& Translator, EFunc2 Op, int32 LhsCode, int32 RhsCode);
143
144 int32 GenerateLerpFunc(FHLSLMaterialTranslator& Translator, int32 A, int32 B, int32 S);
145 int32 GenerateRotateScaleOffsetTexCoordsFunc(FHLSLMaterialTranslator& Translator, int32 TexCoord, int32 RotationScale, int32 Offset);
146 int32 GenerateIfFunc(FHLSLMaterialTranslator& Translator, int32 A, int32 B, int32 Greater, int32 Equal, int32 Less, int32 Threshold);
147
148 FString GenerateUsedFunctions(FHLSLMaterialTranslator& Translator);
149
150 FString ApplyUnMirror(FString Value, bool bUnMirrorU, bool bUnMirrorV);
151
152 FString ConstructDeriv(const FString& Value, const FString& Ddx, const FString& Ddy, EDerivativeType DstType);
153 FString ConstructDerivFinite(const FString& Value, EDerivativeType DstType);
154
155 FString ConvertDeriv(const FString& Value, EDerivativeType DstType, EDerivativeType SrcType);
156
157private:
158 struct FOperationType1
159 {
162
163 EDerivativeType ReturnType; // type of the result
164 EDerivativeType IntermediateType; // type of the inputs (may need to implicitly convert to this type before the operation)
165 };
166
167 struct FOperationType2
168 {
172
173 EDerivativeType ReturnType; // type of the result
174 EDerivativeType LhsIntermediateType; // type of the inputs (may need to implicitly convert to this type before the operation)
175 EDerivativeType RhsIntermediateType; // type of the inputs (may need to implicitly convert to this type before the operation)
176 };
177
180
181 FString CoerceValueRaw(FHLSLMaterialTranslator& Translator, const FString& Token, const FDerivInfo& SrcInfo, EDerivativeType DstType);
182 FString CoerceValueDeriv(const FString& Token, const FDerivInfo& SrcInfo, EDerivativeType DstType);
183
185
186 // State to keep track of which derivative functions have been used and need to be generated.
187 bool bFunc1OpIsEnabled[(int32)EFunc1::Num][NumDerivativeTypes] = {};
189
193
195
197
201 bool bRotateScaleOffsetTexCoords = false;
202 bool bUnMirrorEnabled[2][2] = {};
203
204};
205
206#endif // WITH_EDITORONLY_DATA
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
EDerivativeStatus
Definition HLSLMaterialDerivativeAutogen.h:21
EMaterialValueType MakeNonLWCType(EMaterialValueType Type)
Definition MaterialShared.h:267
bool IsLWCType(EMaterialValueType InType)
Definition MaterialShared.h:240
EMaterialValueType MakeLWCType(EMaterialValueType Type)
Definition MaterialShared.h:279
EMaterialValueType
Definition MaterialValueType.h:15
@ Num
Definition MetalRHIPrivate.h:234
#define UENUM(...)
Definition ObjectMacros.h:749
uint32 Offset
Definition VulkanMemory.cpp:4033
uint8_t uint8
Definition binka_ue_file_header.h:8
Type
Definition PawnAction_Move.h:11
T Normalize(UE::Math::TVector2< T > &Vector, const T Epsilon=0)
Definition VectorTypes.h:46
FValue Atan2(const FValue &Lhs, const FValue &Rhs)
Definition ShaderValue.cpp:1564
FValue Asin(const FValue &Value)
Definition ShaderValue.cpp:1489
FValue Mul(const FValue &Lhs, const FValue &Rhs)
Definition ShaderValue.cpp:1514
FValue Exp2(const FValue &Value)
Definition ShaderValue.cpp:1454
FValue Rcp(const FValue &Value)
Definition ShaderValue.cpp:1444
FValue Div(const FValue &Lhs, const FValue &Rhs)
Definition ShaderValue.cpp:1519
FValue Atan(const FValue &Value)
Definition ShaderValue.cpp:1499
FValue Log10(const FValue &Value)
Definition ShaderValue.cpp:1469
FValue Acos(const FValue &Value)
Definition ShaderValue.cpp:1494
FValue Exp(const FValue &Value)
Definition ShaderValue.cpp:1449
FValue Log2(const FValue &Value)
Definition ShaderValue.cpp:1464