-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLMT_Academy_Analytic_4a.dctl
More file actions
168 lines (131 loc) · 3.71 KB
/
LMT_Academy_Analytic_4a.dctl
File metadata and controls
168 lines (131 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// LMT_Academy_Analytic_4 by Scott Dyer (converted to DCTL from original CTL by Baldavenger)
//
// Input is linear ACES2065-1
// Output is linear ACES2065-1
__CONSTANT__ float X_BRK = 0.0078125f;
__CONSTANT__ float Y_BRK = 0.155251141552511f;
__CONSTANT__ float A = 10.5402377416545f;
__CONSTANT__ float B = 0.0729055341958355f;
__DEVICE__ float3 mult_f_f3(float f, float3 x)
{
x.x *= f;
x.y *= f;
x.z *= f;
return x;
}
__DEVICE__ float3 mult_f3_f33(float3 In, float3 A[3])
{
float3 out;
out.x = In.x * A[0].x + In.y * A[0].y + In.z * A[0].z;
out.y = In.x * A[1].x + In.y * A[1].y + In.z * A[1].z;
out.z = In.x * A[2].x + In.y * A[2].y + In.z * A[2].z;
return out;
}
__DEVICE__ float lin_to_ACEScct(float in)
{
float out;
if (in <= X_BRK){
out = A * in + B;
} else {
out = (_log2f(in) + 9.72f) / 17.52f;
}
return out;
}
__DEVICE__ float ACEScct_to_lin(float in)
{
float out;
if (in > Y_BRK){
out = _powf(2.0f, in * 17.52f - 9.72f);
} else {
out = (in - B) / A;
}
return out;
}
__DEVICE__ float3 ACES_to_ACEScct(float3 in)
{
float3 out;
//AP0 to AP1
out.x = 1.4514393161f * in.x + -0.2365107469f * in.y + -0.2149285693f * in.z;
out.y = -0.0765537734f * in.x + 1.1762296998f * in.y + -0.0996759264f * in.z;
out.z = 0.0083161484f * in.x + -0.0060324498f * in.y + 0.9977163014f * in.z;
// Linear to ACEScct
out.x = lin_to_ACEScct(out.x);
out.y = lin_to_ACEScct(out.y);
out.z = lin_to_ACEScct(out.z);
return out;
}
__DEVICE__ float3 ACEScct_to_ACES(float3 in)
{
float3 lin, out;
// ACEScct to linear
lin.x = ACEScct_to_lin(in.x);
lin.y = ACEScct_to_lin(in.y);
lin.z = ACEScct_to_lin(in.z);
// AP1 to AP0
out.x = 0.6954522414f * lin.x + 0.1406786965f * lin.y + 0.1638690622f * lin.z;
out.y = 0.0447945634f * lin.x + 0.8596711185f * lin.y + 0.0955343182f * lin.z;
out.z = -0.0055258826f * lin.x + 0.0040252103f * lin.y + 1.0015006723f * lin.z;
return out;
}
__DEVICE__ float3 gamma_adjust_linear(float3 rgbIn, float GAMMA, float PIVOT)
{
const float SCALAR = PIVOT / _powf(PIVOT, GAMMA);
if (rgbIn.x > 0.0f){ rgbIn.x = _powf(rgbIn.x, GAMMA) * SCALAR;}
if (rgbIn.y > 0.0f){ rgbIn.y = _powf(rgbIn.y, GAMMA) * SCALAR;}
if (rgbIn.z > 0.0f){ rgbIn.z = _powf(rgbIn.z, GAMMA) * SCALAR;}
return rgbIn;
}
__DEVICE__ float3* calc_sat_adjust_matrix(float sat, float3 rgb2Y)
{
float3 M[3];
M[0].x = (1.0f - sat) * rgb2Y.x + sat;
M[1].x = (1.0f - sat) * rgb2Y.x;
M[2].x = (1.0f - sat) * rgb2Y.x;
M[0].y = (1.0f - sat) * rgb2Y.y;
M[1].y = (1.0f - sat) * rgb2Y.y + sat;
M[2].y = (1.0f - sat) * rgb2Y.y;
M[0].z = (1.0f - sat) * rgb2Y.z;
M[1].z = (1.0f - sat) * rgb2Y.z;
M[2].z = (1.0f - sat) * rgb2Y.z + sat;
return M;
}
__DEVICE__ float3 sat_adjust(float3 rgbIn, float SAT_FACTOR)
{
float3 RGB2Y = make_float3(0.2126f, 0.7152f, 0.0722f);
float3* SAT_MAT;
SAT_MAT = calc_sat_adjust_matrix(SAT_FACTOR, RGB2Y);
return mult_f3_f33(rgbIn, SAT_MAT);
}
__DEVICE__ float3 overlay_f3(float3 a, float3 b)
{
float LUMA_CUT = lin_to_ACEScct(0.5f);
float luma = 0.2126f * a.x + 0.7152f * a.y + 0.0722f * a.z;
float3 out;
if (luma < LUMA_CUT) {
out.x = 2.0f * a.x * b.x;
out.y = 2.0f * a.y * b.y;
out.z = 2.0f * a.z * b.z;
} else {
out.x = 1.0f - (2.0f * (1.0f - a.x) * (1.0f - b.x));
out.y = 1.0f - (2.0f * (1.0f - a.y) * (1.0f - b.y));
out.z = 1.0f - (2.0f * (1.0f - a.z) * (1.0f - b.z));
}
return out;
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B)
{
float3 aces;
aces.x = p_R;
aces.y = p_G;
aces.z = p_B;
float3 a, b, out, blend;
a = sat_adjust(aces, 0.9f);
a = mult_f_f3(2.0f, a);
b = sat_adjust(aces, 0.0f);
b = gamma_adjust_linear(b, 1.2f, 0.18f);
a = ACES_to_ACEScct(a);
b = ACES_to_ACEScct(b);
blend = overlay_f3(a, b);
out = ACEScct_to_ACES(blend);
return out;
}