UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ColorConstants.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "HAL/Platform.h"
6#include "Math/Color.h"
7#include "MathUtil.h"
8
9namespace UE
10{
11namespace Geometry
12{
13
14
20namespace LinearColors
21{
23 template <typename VectorType>
24 void SRGBToLinear(VectorType& Color)
25 {
26 // Sourced from MPCDIUtils.ush
27 auto SRGBToLinearFloat = [](const float Color) -> float
28 {
29 return (Color <= 0.04045f) ? Color / 12.92f : FMathf::Pow((Color + 0.055f) / 1.055f, 2.4f);
30 };
31
32 Color.X = SRGBToLinearFloat(Color.X);
33 Color.Y = SRGBToLinearFloat(Color.Y);
34 Color.Z = SRGBToLinearFloat(Color.Z);
35 }
36
38 template <typename VectorType>
39 void LinearToSRGB(VectorType& Color)
40 {
41 // Sourced from MPCDIUtils.ush
42 auto LinearToSRGBFloat = [](const float Color) -> float
43 {
44 return (Color <= 0.0031308f) ? Color * 12.92f : 1.055f * FMathf::Pow(Color, 1.0f / 2.4f) - 0.055f;
45 };
46
47 Color.X = LinearToSRGBFloat(Color.X);
48 Color.Y = LinearToSRGBFloat(Color.Y);
49 Color.Z = LinearToSRGBFloat(Color.Z);
50 }
51
52 template <typename VectorType>
53 VectorType MakeColor3f(float R, float G, float B)
54 {
55 return VectorType(R, G, B);
56 }
57
58 template <typename VectorType>
59 VectorType MakeColor4f(float R, float G, float B, float A)
60 {
61 return VectorType(R, G, B, A);
62 }
63
64#define ColorConstant(ColorName, R, G, B) \
65 inline FLinearColor ColorName##3f() { return MakeColor3f<FLinearColor>(R, G, B); } \
66 inline FColor ColorName##3b() { return MakeColor3f<FLinearColor>(R, G, B).ToFColor(false); }
67
68 ColorConstant(Black, 0.0f, 0.0f, 0.0f);
69 ColorConstant(White, 1.0f, 1.0f, 1.0f);
70 ColorConstant(Gray, 0.5f, 0.5f, 0.5f);
71
72 ColorConstant(Red, 1.0f, 0.0f, 0.0f);
73 ColorConstant(Green, 0.0f, 1.0f, 0.0f);
74 ColorConstant(Blue, 0.0f, 0.0f, 1.0f);
75 ColorConstant(Yellow, 1.0f, 1.0f, 0.0f);
76 ColorConstant(Cyan, 0.0f, 1.0f, 1.0f);
77 ColorConstant(Magenta, 1.0f, 0.0f, 1.0f);
78
79 ColorConstant(VideoBlack, 0.062745f, 0.062745f, 0.062745f);
80 ColorConstant(VideoWhite, 0.9215686f, 0.9215686f, 0.9215686f);
81 ColorConstant(VideoRed, 0.9215686f, 0.062745f, 0.062745f);
82 ColorConstant(VideoGreen, 0.062745f, 0.9215686f, 0.062745f);
83 ColorConstant(VideoBlue, 0.062745f, 0.062745f, 0.9215686f);
84
85 // X11 Colors - https://www.w3.org/TR/css-color-3/#html4
86 // python code to parse text file:
87 //
88 //f1 = f.readlines()
89 // for x in f1 :
90 //tokens = x.split()
91 // colors = tokens[2].split(',')
92 // r = float(colors[0]) / 255.0;
93 //g = float(colors[1]) / 255.0;
94 //b = float(colors[2]) / 255.0;
95 //print "ColorConstant(" + tokens[0].capitalize() + ", " + str(r) + "f, " + str(g) + "f, " + str(b) + "f);"
96
97
98 ColorConstant(AliceBlue, 0.941176470588f, 0.972549019608f, 1.0f);
99 ColorConstant(AntiqueWhite, 0.980392156863f, 0.921568627451f, 0.843137254902f);
100 ColorConstant(Aqua, 0.0f, 1.0f, 1.0f);
101 ColorConstant(Aquamarine, 0.498039215686f, 1.0f, 0.83137254902f);
102 ColorConstant(Azure, 0.941176470588f, 1.0f, 1.0f);
103 ColorConstant(Beige, 0.960784313725f, 0.960784313725f, 0.862745098039f);
104 ColorConstant(Bisque, 1.0f, 0.894117647059f, 0.76862745098f);
105 ColorConstant(BlanchedAlmond, 1.0f, 0.921568627451f, 0.803921568627f);
106 ColorConstant(BlueViolet, 0.541176470588f, 0.16862745098f, 0.886274509804f);
107 ColorConstant(Brown, 0.647058823529f, 0.164705882353f, 0.164705882353f);
108 ColorConstant(Burlywood, 0.870588235294f, 0.721568627451f, 0.529411764706f);
109 ColorConstant(CadetBlue, 0.372549019608f, 0.619607843137f, 0.627450980392f);
110 ColorConstant(Chartreuse, 0.498039215686f, 1.0f, 0.0f);
111 ColorConstant(Chocolate, 0.823529411765f, 0.411764705882f, 0.117647058824f);
112 ColorConstant(Coral, 1.0f, 0.498039215686f, 0.313725490196f);
113 ColorConstant(CornflowerBlue, 0.392156862745f, 0.58431372549f, 0.929411764706f);
114 ColorConstant(Cornsilk, 1.0f, 0.972549019608f, 0.862745098039f);
115 ColorConstant(Crimson, 0.862745098039f, 0.078431372549f, 0.235294117647f);
116 ColorConstant(DarkBlue, 0.0f, 0.0f, 0.545098039216f);
117 ColorConstant(DarkCyan, 0.0f, 0.545098039216f, 0.545098039216f);
118 ColorConstant(DarkGoldenrod, 0.721568627451f, 0.525490196078f, 0.043137254902f);
119 ColorConstant(DarkGray, 0.662745098039f, 0.662745098039f, 0.662745098039f);
120 ColorConstant(DarkGreen, 0.0f, 0.392156862745f, 0.0f);
121 ColorConstant(DarkKhaki, 0.741176470588f, 0.717647058824f, 0.419607843137f);
122 ColorConstant(DarkMagenta, 0.545098039216f, 0.0f, 0.545098039216f);
123 ColorConstant(DarkOliveGreen, 0.333333333333f, 0.419607843137f, 0.18431372549f);
124 ColorConstant(DarkOrange, 1.0f, 0.549019607843f, 0.0f);
125 ColorConstant(DarkOrchid, 0.6f, 0.196078431373f, 0.8f);
126 ColorConstant(DarkRed, 0.545098039216f, 0.0f, 0.0f);
127 ColorConstant(DarkSalmon, 0.913725490196f, 0.588235294118f, 0.478431372549f);
128 ColorConstant(DarkSeagreen, 0.560784313725f, 0.737254901961f, 0.560784313725f);
129 ColorConstant(DarkSlateBlue, 0.282352941176f, 0.239215686275f, 0.545098039216f);
130 ColorConstant(DarkSlateGray, 0.18431372549f, 0.309803921569f, 0.309803921569f);
131 ColorConstant(DarkTurquoise, 0.0f, 0.807843137255f, 0.819607843137f);
132 ColorConstant(DarkViolet, 0.580392156863f, 0.0f, 0.827450980392f);
133 ColorConstant(DeepPink, 1.0f, 0.078431372549f, 0.576470588235f);
134 ColorConstant(DeepSkyBlue, 0.0f, 0.749019607843f, 1.0f);
135 ColorConstant(DimGray, 0.411764705882f, 0.411764705882f, 0.411764705882f);
136 ColorConstant(DodgerBlue, 0.117647058824f, 0.564705882353f, 1.0f);
137 ColorConstant(Firebrick, 0.698039215686f, 0.133333333333f, 0.133333333333f);
138 ColorConstant(FloralWhite, 1.0f, 0.980392156863f, 0.941176470588f);
139 ColorConstant(ForestGreen, 0.133333333333f, 0.545098039216f, 0.133333333333f);
140 ColorConstant(Fuchsia, 1.0f, 0.0f, 1.0f);
141 ColorConstant(Gainsboro, 0.862745098039f, 0.862745098039f, 0.862745098039f);
142 ColorConstant(GhostWhite, 0.972549019608f, 0.972549019608f, 1.0f);
143 ColorConstant(Gold, 1.0f, 0.843137254902f, 0.0f);
144 ColorConstant(Goldenrod, 0.854901960784f, 0.647058823529f, 0.125490196078f);
145 ColorConstant(GreenYellow, 0.678431372549f, 1.0f, 0.18431372549f);
146 ColorConstant(HoneyDew, 0.941176470588f, 1.0f, 0.941176470588f);
147 ColorConstant(HotPink, 1.0f, 0.411764705882f, 0.705882352941f);
148 ColorConstant(IndianRed, 0.803921568627f, 0.360784313725f, 0.360784313725f);
149 ColorConstant(Indigo, 0.294117647059f, 0.0f, 0.509803921569f);
150 ColorConstant(Ivory, 1.0f, 1.0f, 0.941176470588f);
151 ColorConstant(Khaki, 0.941176470588f, 0.901960784314f, 0.549019607843f);
152 ColorConstant(Lavender, 0.901960784314f, 0.901960784314f, 0.980392156863f);
153 ColorConstant(LavenderBlush, 1.0f, 0.941176470588f, 0.960784313725f);
154 ColorConstant(LawnGreen, 0.486274509804f, 0.988235294118f, 0.0f);
155 ColorConstant(LemonChiffon, 1.0f, 0.980392156863f, 0.803921568627f);
156 ColorConstant(LightBlue, 0.678431372549f, 0.847058823529f, 0.901960784314f);
157 ColorConstant(LightCoral, 0.941176470588f, 0.501960784314f, 0.501960784314f);
158 ColorConstant(LightCyan, 0.878431372549f, 1.0f, 1.0f);
159 ColorConstant(LightGoldenrod, 0.980392156863f, 0.980392156863f, 0.823529411765f);
160 ColorConstant(LightGray, 0.827450980392f, 0.827450980392f, 0.827450980392f);
161 ColorConstant(LightGreen, 0.564705882353f, 0.933333333333f, 0.564705882353f);
162 ColorConstant(LightPink, 1.0f, 0.713725490196f, 0.756862745098f);
163 ColorConstant(LightSalmon, 1.0f, 0.627450980392f, 0.478431372549f);
164 ColorConstant(LightSeaGreen, 0.125490196078f, 0.698039215686f, 0.666666666667f);
165 ColorConstant(LightSkyBlue, 0.529411764706f, 0.807843137255f, 0.980392156863f);
166 ColorConstant(LightSlateGray, 0.466666666667f, 0.533333333333f, 0.6f);
167 ColorConstant(LightSteelBlue, 0.690196078431f, 0.76862745098f, 0.870588235294f);
168 ColorConstant(LightYellow, 1.0f, 1.0f, 0.878431372549f);
169 ColorConstant(Lime, 0.0f, 1.0f, 0.0f);
170 ColorConstant(LimeGreen, 0.196078431373f, 0.803921568627f, 0.196078431373f);
171 ColorConstant(Linen, 0.980392156863f, 0.941176470588f, 0.901960784314f);
172 ColorConstant(Maroon, 0.501960784314f, 0.0f, 0.0f);
173 ColorConstant(MediumAquamarine, 0.4f, 0.803921568627f, 0.666666666667f);
174 ColorConstant(MediumBlue, 0.0f, 0.0f, 0.803921568627f);
175 ColorConstant(MediumOrchid, 0.729411764706f, 0.333333333333f, 0.827450980392f);
176 ColorConstant(MediumPurple, 0.576470588235f, 0.439215686275f, 0.858823529412f);
177 ColorConstant(MediumSeaGreen, 0.235294117647f, 0.701960784314f, 0.443137254902f);
178 ColorConstant(MediumSlateBlue, 0.482352941176f, 0.407843137255f, 0.933333333333f);
179 ColorConstant(MediumSpringGreen, 0.0f, 0.980392156863f, 0.603921568627f);
180 ColorConstant(MediumTurquoise, 0.282352941176f, 0.819607843137f, 0.8f);
181 ColorConstant(MediumVioletRed, 0.780392156863f, 0.0823529411765f, 0.521568627451f);
182 ColorConstant(MidnightBlue, 0.0980392156863f, 0.0980392156863f, 0.439215686275f);
183 ColorConstant(MintCream, 0.960784313725f, 1.0f, 0.980392156863f);
184 ColorConstant(MistyRose, 1.0f, 0.894117647059f, 0.882352941176f);
185 ColorConstant(Moccasin, 1.0f, 0.894117647059f, 0.709803921569f);
186 ColorConstant(NavajoWhite, 1.0f, 0.870588235294f, 0.678431372549f);
187 ColorConstant(Navy, 0.0f, 0.0f, 0.501960784314f);
188 ColorConstant(OldLace, 0.992156862745f, 0.960784313725f, 0.901960784314f);
189 ColorConstant(Olive, 0.501960784314f, 0.501960784314f, 0.0f);
190 ColorConstant(OliveDrab, 0.419607843137f, 0.556862745098f, 0.137254901961f);
191 ColorConstant(Orange, 1.0f, 0.647058823529f, 0.0f);
192 ColorConstant(OrangeRed, 1.0f, 0.270588235294f, 0.0f);
193 ColorConstant(Orchid, 0.854901960784f, 0.439215686275f, 0.839215686275f);
194 ColorConstant(PaleGoldenrod, 0.933333333333f, 0.909803921569f, 0.666666666667f);
195 ColorConstant(PaleGreen, 0.596078431373f, 0.98431372549f, 0.596078431373f);
196 ColorConstant(PaleTurquoise, 0.686274509804f, 0.933333333333f, 0.933333333333f);
197 ColorConstant(PaleVioletRed, 0.858823529412f, 0.439215686275f, 0.576470588235f);
198 ColorConstant(PapayaWhip, 1.0f, 0.937254901961f, 0.835294117647f);
199 ColorConstant(PeachPuff, 1.0f, 0.854901960784f, 0.725490196078f);
200 ColorConstant(Peru, 0.803921568627f, 0.521568627451f, 0.247058823529f);
201 ColorConstant(Pink, 1.0f, 0.752941176471f, 0.796078431373f);
202 ColorConstant(Plum, 0.866666666667f, 0.627450980392f, 0.866666666667f);
203 ColorConstant(PowderBlue, 0.690196078431f, 0.878431372549f, 0.901960784314f);
204 ColorConstant(Purple, 0.501960784314f, 0.0f, 0.501960784314f);
205 ColorConstant(RosyBrown, 0.737254901961f, 0.560784313725f, 0.560784313725f);
206 ColorConstant(RoyalBlue, 0.254901960784f, 0.411764705882f, 0.882352941176f);
207 ColorConstant(SaddleBrown, 0.545098039216f, 0.270588235294f, 0.0745098039216f);
208 ColorConstant(Salmon, 0.980392156863f, 0.501960784314f, 0.447058823529f);
209 ColorConstant(SandyBrown, 0.956862745098f, 0.643137254902f, 0.376470588235f);
210 ColorConstant(SeaGreen, 0.180392156863f, 0.545098039216f, 0.341176470588f);
211 ColorConstant(Seashell, 1.0f, 0.960784313725f, 0.933333333333f);
212 ColorConstant(Sienna, 0.627450980392f, 0.321568627451f, 0.176470588235f);
213 ColorConstant(Silver, 0.752941176471f, 0.752941176471f, 0.752941176471f);
214 ColorConstant(SkyBlue, 0.529411764706f, 0.807843137255f, 0.921568627451f);
215 ColorConstant(SlateBlue, 0.41568627451f, 0.352941176471f, 0.803921568627f);
216 ColorConstant(SlateGray, 0.439215686275f, 0.501960784314f, 0.564705882353f);
217 ColorConstant(Snow, 1.0f, 0.980392156863f, 0.980392156863f);
218 ColorConstant(SpringGreen, 0.0f, 1.0f, 0.498039215686f);
219 ColorConstant(SteelBlue, 0.274509803922f, 0.509803921569f, 0.705882352941f);
220 ColorConstant(Tan, 0.823529411765f, 0.705882352941f, 0.549019607843f);
221 ColorConstant(Teal, 0.0f, 0.501960784314f, 0.501960784314f);
222 ColorConstant(Thistle, 0.847058823529f, 0.749019607843f, 0.847058823529f);
223 ColorConstant(Tomato, 1.0f, 0.388235294118f, 0.278431372549f);
224 ColorConstant(Turquoise, 0.250980392157f, 0.878431372549f, 0.81568627451f);
225 ColorConstant(Violet, 0.933333333333f, 0.509803921569f, 0.933333333333f);
226 ColorConstant(Wheat, 0.960784313725f, 0.870588235294f, 0.701960784314f);
227 ColorConstant(WhiteSmoke, 0.960784313725f, 0.960784313725f, 0.960784313725f);
228 ColorConstant(YellowGreen, 0.603921568627f, 0.803921568627f, 0.196078431373f);
229
230
231
232
233
234
240 template <typename VectorType>
242 {
243 static const FLinearColor ColorMap[] = {
251 };
252 return VectorType( (Index <= 0) ? White3f() : ColorMap[(Index-1) % (7*3)] );
253 }
254
255
262
263}
264
265
266} // end namespace UE::Geometry
267} // end namespace UE
#define ColorConstant(ColorName, R, G, B)
Definition ColorConstants.h:64
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
static RealType Pow(const RealType Value, const RealType Power)
Definition MathUtil.h:402
GEOMETRYCORE_API FColor SelectFColor(int32 Index)
Definition ColorConstants.cpp:5
VectorType SelectColor(int32 Index)
Definition ColorConstants.h:241
VectorType MakeColor4f(float R, float G, float B, float A)
Definition ColorConstants.h:59
void SRGBToLinear(VectorType &Color)
Definition ColorConstants.h:24
VectorType MakeColor3f(float R, float G, float B)
Definition ColorConstants.h:53
Definition AdvancedWidgetsModule.cpp:13
U16 Index
Definition radfft.cpp:71
Definition Color.h:486
Definition Color.h:48