Skip to content

Commit 6fd0b8c

Browse files
committed
Resolved conflicts
2 parents df1f540 + e4ab38c commit 6fd0b8c

File tree

21 files changed

+1886
-243
lines changed

21 files changed

+1886
-243
lines changed

include/nbl/builtin/glsl/colorspace/decodeCIEXYZ.glsl

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,36 @@
55
#ifndef _NBL_BUILTIN_GLSL_COLOR_SPACE_DECODE_CIE_XYZ_INCLUDED_
66
#define _NBL_BUILTIN_GLSL_COLOR_SPACE_DECODE_CIE_XYZ_INCLUDED_
77

8-
const mat3 nbl_glsl_XYZtoscRGB = mat3( vec3( 3.2404542,-0.9692660, 0.0556434),
9-
vec3(-1.5371385, 1.8760108,-0.2040259),
10-
vec3(-0.4985314, 0.0415560, 1.0572252));
8+
const mat3 nbl_glsl_XYZtoscRGB = mat3(
9+
vec3( 3.240970f, -0.969244f, 0.055630f),
10+
vec3(-1.537383f, 1.875968f, -0.203977f),
11+
vec3(-0.498611f, 0.041555f, 1.056972f)
12+
);
1113

1214
const mat3 nbl_glsl_XYZtosRGB = nbl_glsl_XYZtoscRGB;
1315

1416
const mat3 nbl_glsl_XYZtoBT709 = nbl_glsl_XYZtoscRGB;
1517

1618

17-
const mat3 nbl_glsl_XYZtoDisplay_P3 = mat3( vec3( 2.4934969,-0.8294890, 0.0358458),
18-
vec3(-0.9313836, 1.7626641,-0.0761724),
19-
vec3(-0.4027108, 0.0236247, 0.9568845));
19+
const mat3 nbl_glsl_XYZtoDisplay_P3 = mat3(
20+
vec3( 2.4934969119f,-0.8294889696f, 0.0358458302f),
21+
vec3(-0.9313836179f, 1.7626640603f,-0.0761723893f),
22+
vec3(-0.4027107845f, 0.0236246858f, 0.9568845240f)
23+
);
2024

2125

22-
const mat3 nbl_glsl_XYZtoDCI_P3 = mat3(vec3(1.0,0.0,0.0),vec3(0.0,1.0,0.0),vec3(0.0,0.0,1.0));
26+
const mat3 nbl_glsl_XYZtoDCI_P3 = mat3(
27+
vec3(1.0f,0.0f,0.0f),
28+
vec3(0.0f,1.0f,0.0f),
29+
vec3(0.0f,0.0f,1.0f)
30+
);
2331

2432

25-
const mat3 nbl_glsl_XYZtoBT2020 = mat3( vec3( 1.7166512,-0.6666844, 0.0176399),
26-
vec3(-0.3556708, 1.6164812,-0.0427706),
27-
vec3(-0.2533663, 0.0157685, 0.9421031));
33+
const mat3 nbl_glsl_XYZtoBT2020 = mat3(
34+
vec3( 1.716651f,-0.666684f, 0.017640f),
35+
vec3(-0.355671f, 1.616481f,-0.042771f),
36+
vec3(-0.253366f, 0.015769f, 0.942103f)
37+
);
2838

2939
const mat3 nbl_glsl_XYZtoHDR10_ST2084 = nbl_glsl_XYZtoBT2020;
3040

@@ -33,19 +43,25 @@ const mat3 nbl_glsl_XYZtoDOLBYIVISION = nbl_glsl_XYZtoBT2020;
3343
const mat3 nbl_glsl_XYZtoHDR10_HLG = nbl_glsl_XYZtoBT2020;
3444

3545

36-
const mat3 nbl_glsl_XYZtoAdobeRGB = mat3( vec3( 2.04159,-0.96924, 0.01344),
37-
vec3(-0.56501, 1.87597,-0.11836),
38-
vec3(-0.34473, 0.04156, 1.01517));
46+
const mat3 nbl_glsl_XYZtoAdobeRGB = mat3(
47+
vec3( 2.0415879038f,-0.9692436363f, 0.0134442806f),
48+
vec3(-0.5650069743f, 1.8759675015f,-0.1183623922f),
49+
vec3(-0.3447313508f, 0.0415550574f, 1.0151749944f)
50+
);
3951

4052

41-
const mat3 nbl_glsl_XYZtoACES2065_1 = mat3( vec3( 1.0498110175, 0.0000000000,-0.0000974845),
42-
vec3(-0.4959030231, 1.3733130458, 0.0982400361),
43-
vec3( 0.0000000000, 0.0000000000, 0.9912520182));
53+
const mat3 nbl_glsl_XYZtoACES2065_1 = mat3(
54+
vec3( 1.0498110175f, -0.4959030231f, 0.0000000000f),
55+
vec3( 0.0000000000f, 1.3733130458f, 0.0000000000f),
56+
vec3(-0.0000974845f, 0.0982400361f, 0.9912520182f)
57+
);
4458

4559

46-
const mat3 nbl_glsl_XYZtoACEScc = mat3( vec3( 1.6410234,-0.6636629, 0.0117219),
47-
vec3(-0.3248033, 1.6153316,-0.0082844),
48-
vec3(-0.2364247, 0.0167563, 0.9883949));
60+
const mat3 nbl_glsl_XYZtoACEScc = mat3(
61+
vec3( 1.6410233797f,-0.6636628587f, 0.0117218943f),
62+
vec3(-0.3248032942f, 1.6153315917f,-0.0082844420f),
63+
vec3(-0.2364246952f, 0.0167563477f, 0.9883948585f)
64+
);
4965

5066
const mat3 nbl_glsl_XYZtoACEScct = nbl_glsl_XYZtoACEScc;
5167

include/nbl/builtin/glsl/colorspace/encodeCIEXYZ.glsl

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#define _NBL_BUILTIN_GLSL_COLOR_SPACE_ENCODE_CIE_XYZ_INCLUDED_
77

88
const mat3 nbl_glsl_scRGBtoXYZ = mat3(
9-
vec3(0.4124564, 0.2126729, 0.0193339),
10-
vec3(0.3575761, 0.7151522, 0.1191920),
11-
vec3(0.1804375, 0.0721750, 0.9503041)
9+
vec3(0.412391f, 0.212639f, 0.019331f),
10+
vec3(0.357584f, 0.715169f, 0.119195f),
11+
vec3(0.180481f, 0.072192f, 0.950532f)
1212
);
1313

1414
const mat3 nbl_glsl_sRGBtoXYZ = nbl_glsl_scRGBtoXYZ;
@@ -17,23 +17,23 @@ const mat3 nbl_glsl_BT709toXYZ = nbl_glsl_scRGBtoXYZ;
1717

1818

1919
const mat3 nbl_glsl_Display_P3toXYZ = mat3(
20-
vec3(0.4865709, 0.2289746, 0.0000000),
21-
vec3(0.2656677, 0.6917385, 0.0451134),
22-
vec3(0.1982173, 0.0792869, 1.0439444)
20+
vec3(0.4865709486f, 0.2289745641f, 0.0000000000f),
21+
vec3(0.2656676932f, 0.6917385218f, 0.0451133819f),
22+
vec3(0.1982172852f, 0.0792869141f, 1.0439443689f)
2323
);
2424

2525

2626
const mat3 nbl_glsl_DCI_P3toXYZ = mat3(
27-
vec3(1.0, 0.0, 0.0),
28-
vec3(0.0, 1.0, 0.0),
29-
vec3(0.0, 0.0, 1.0)
27+
vec3(1.0f, 0.0f, 0.0f),
28+
vec3(0.0f, 1.0f, 0.0f),
29+
vec3(0.0f, 0.0f, 1.0f)
3030
);
3131

3232

3333
const mat3 nbl_glsl_BT2020toXYZ = mat3(
34-
vec3(0.6369580, 0.2627002, 0.0000000),
35-
vec3(0.1446169, 0.6779981, 0.0280727),
36-
vec3(0.1688810, 0.0593017, 1.0609851)
34+
vec3(0.636958f, 0.262700f, 0.000000f),
35+
vec3(0.144617f, 0.677998f, 0.028073f),
36+
vec3(0.168881f, 0.059302f, 1.060985f)
3737
);
3838

3939
const mat3 nbl_glsl_HDR10_ST2084toXYZ = nbl_glsl_BT2020toXYZ;
@@ -44,23 +44,23 @@ const mat3 nbl_glsl_HDR10_HLGtoXYZ = nbl_glsl_BT2020toXYZ;
4444

4545

4646
const mat3 nbl_glsl_AdobeRGBtoXYZ = mat3(
47-
vec3(0.57667, 0.29734, 0.02703),
48-
vec3(0.18556, 0.62736, 0.07069),
49-
vec3(0.18823, 0.07529, 0.99134)
47+
vec3(0.5766690429f, 0.2973449753f, 0.0270313614f),
48+
vec3(0.1855582379f, 0.6273635663f, 0.0706888525f),
49+
vec3(0.1882286462f, 0.0752914585f, 0.9913375368f)
5050
);
5151

5252

5353
const mat3 nbl_glsl_ACES2065_1toXYZ = mat3(
54-
vec3(0.9525523959, 0.3439664498, 0.0000000000),
55-
vec3(0.0000000000, 0.7281660966, 0.0000000000),
56-
vec3(0.0000936786, -0.0721325464, 1.0088251844)
54+
vec3(0.9525523959f, 0.3439664498f, 0.0000000000f),
55+
vec3(0.0000000000f, 0.7281660966f, 0.0000000000f),
56+
vec3(0.0000936786f, -0.0721325464f, 1.0088251844f)
5757
);
5858

5959

6060
const mat3 nbl_glsl_ACEScctoXYZ = mat3(
61-
vec3(0.6624542, 0.2722287, -0.0055746),
62-
vec3(0.1340042, 0.6740818, 0.6740818),
63-
vec3(0.1561877, 0.0536895, 1.0103391)
61+
vec3(0.6624541811f, 0.2722287168f, -0.0055746495f),
62+
vec3(0.1340042065f, 0.6740817658f, 0.0040607335f),
63+
vec3(0.1561876870f, 0.0536895174f, 1.0103391003f)
6464
);
6565

6666
const mat3 nbl_glsl_ACESccttoXYZ = nbl_glsl_ACEScctoXYZ;
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
2+
// Copyright (C) 2018-2022 - DevSH Graphics Programming Sp. z O.O.
3+
// This file is part of the "Nabla Engine".
4+
// For conditions of distribution and use, see copyright notice in nabla.h
5+
6+
#ifndef _NBL_BUILTIN_HLSL_COLOR_SPACE_EOTF_INCLUDED_
7+
#define _NBL_BUILTIN_HLSL_COLOR_SPACE_EOTF_INCLUDED_
8+
9+
//#include <nbl/builtin/hlsl/common.hlsl>
10+
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
11+
#include <nbl/builtin/hlsl/cpp_compat/promote.hlsl>
12+
#include <nbl/builtin/hlsl/cpp_compat/type_traits.hlsl>
13+
14+
namespace nbl
15+
{
16+
namespace hlsl
17+
{
18+
namespace colorspace
19+
{
20+
namespace eotf
21+
{
22+
23+
template<typename T>
24+
T identity(NBL_CONST_REF_ARG(T) nonlinear)
25+
{
26+
return nonlinear;
27+
}
28+
29+
template<typename T>
30+
T impl_shared_2_4(NBL_CONST_REF_ARG(T) nonlinear, typename scalar_type<T>::type vertex)
31+
{
32+
typedef typename scalar_type<T>::type Val_t;
33+
bool3 right = (nonlinear > promote<T, Val_t>(vertex));
34+
return lerp(nonlinear / Val_t(12.92), pow((nonlinear + promote<T, Val_t>(0.055)) / Val_t(1.055), promote<T, Val_t>(2.4)), right);
35+
}
36+
37+
// compatible with scRGB as well
38+
template<typename T>
39+
T sRGB(NBL_CONST_REF_ARG(T) nonlinear)
40+
{
41+
typedef typename scalar_type<T>::type Val_t;
42+
bool3 negatif = (nonlinear < promote<T, Val_t>(0.0));
43+
T absVal = impl_shared_2_4<T>(abs(nonlinear), 0.04045);
44+
return lerp(absVal, -absVal, negatif);
45+
}
46+
47+
// also known as P3-D65
48+
template<typename T>
49+
T Display_P3(NBL_CONST_REF_ARG(T) nonlinear)
50+
{
51+
typedef typename scalar_type<T>::type Val_t;
52+
return impl_shared_2_4<T>(nonlinear, 0.039000312);
53+
}
54+
55+
template<typename T>
56+
T DCI_P3_XYZ(NBL_CONST_REF_ARG(T) nonlinear)
57+
{
58+
typedef typename scalar_type<T>::type Val_t;
59+
return pow(nonlinear * Val_t(52.37), promote<T, Val_t>(2.6));
60+
}
61+
62+
template<typename T>
63+
T SMPTE_170M(NBL_CONST_REF_ARG(T) nonlinear)
64+
{
65+
typedef typename scalar_type<T>::type Val_t;
66+
// ITU specs (and the outlier BT.2020) give different constants for these, but they introduce discontinuities in the mapping
67+
// because HDR swapchains often employ the RGBA16_SFLOAT format, this would become apparent because its higher precision than 8,10,12 bits
68+
Val_t alpha = 1.099296826809443; // 1.099 for all ITU but the BT.2020 12 bit encoding, 1.0993 otherwise
69+
T delta = promote<T, Val_t>(0.081242858298635); // 0.0812 for all ITU but the BT.2020 12 bit encoding
70+
return lerp(nonlinear / Val_t(4.5), pow((nonlinear + promote<T, Val_t>(alpha - 1.0)) / alpha, promote<T, Val_t>(1.0 / 0.45)), (nonlinear >= delta));
71+
}
72+
73+
template<typename T>
74+
T SMPTE_ST2084(NBL_CONST_REF_ARG(T) nonlinear)
75+
{
76+
typedef typename scalar_type<T>::type Val_t;
77+
const T invm2 = promote<T, Val_t>(1.0 / 78.84375);
78+
T _common = pow(invm2, invm2);
79+
80+
const T c2 = promote<T, Val_t>(18.8515625);
81+
const Val_t c3 = 18.68875;
82+
const T c1 = promote<T, Val_t>(c3 + 1.0) - c2;
83+
84+
const T invm1 = promote<T, Val_t>(1.0 / 0.1593017578125);
85+
return pow(max(_common - c1, promote<T, Val_t>(0.0)) / (c2 - _common * c3), invm1);
86+
}
87+
88+
// did I do this right by applying the function for every color?
89+
template<typename T>
90+
T HDR10_HLG(NBL_CONST_REF_ARG(T) nonlinear)
91+
{
92+
typedef typename scalar_type<T>::type Val_t;
93+
// done with log2 so constants are different
94+
const Val_t a = 0.1239574303172;
95+
const T b = promote<T, Val_t>(0.02372241);
96+
const T c = promote<T, Val_t>(1.0042934693729);
97+
bool3 right = (nonlinear > promote<T, Val_t>(0.5));
98+
return lerp(nonlinear * nonlinear / Val_t(3.0), exp2((nonlinear - c) / a) + b, right);
99+
}
100+
101+
template<typename T>
102+
T AdobeRGB(NBL_CONST_REF_ARG(T) nonlinear)
103+
{
104+
typedef typename scalar_type<T>::type Val_t;
105+
return pow(nonlinear, promote<T, Val_t>(2.19921875));
106+
}
107+
108+
template<typename T>
109+
T Gamma_2_2(NBL_CONST_REF_ARG(T) nonlinear)
110+
{
111+
typedef typename scalar_type<T>::type Val_t;
112+
return pow(nonlinear, promote<T, Val_t>(2.2));
113+
}
114+
115+
template<typename T>
116+
T ACEScc(NBL_CONST_REF_ARG(T) nonlinear)
117+
{
118+
typedef typename scalar_type<T>::type Val_t;
119+
bool3 right = (nonlinear >= promote<T, Val_t>(-0.301369863));
120+
T _common = exp2(nonlinear * Val_t(17.52) - promote<T, Val_t>(9.72));
121+
return max(lerp(_common * Val_t(2.0) - promote<T, Val_t>(0.000030517578125), _common, right), promote<T, Val_t>(65504.0));
122+
}
123+
124+
template<typename T>
125+
T ACEScct(NBL_CONST_REF_ARG(T) nonlinear)
126+
{
127+
typedef typename scalar_type<T>::type Val_t;
128+
bool3 right = (nonlinear >= promote<T, Val_t>(0.155251141552511));
129+
return max(lerp((nonlinear - promote<T, Val_t>(0.0729055341958355)) / Val_t(10.5402377416545), exp2(nonlinear * Val_t(17.52) - promote<T, Val_t>(9.72)), right), promote<T, Val_t>(65504.0));
130+
}
131+
132+
}
133+
}
134+
}
135+
}
136+
137+
#endif
138+

0 commit comments

Comments
 (0)