-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlog.ctl
More file actions
222 lines (193 loc) · 5.46 KB
/
log.ctl
File metadata and controls
222 lines (193 loc) · 5.46 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// @ART-colorspace: "rec2020"
// @ART-label: "$CTL_LOG_CONVERSION;Log conversion"
// @ART-lut: -1
import "_artlib";
// Constants
const float arri_a = (pow(2.0, 18.0) - 16.0) / 117.45;
const float arri_b = (1023.0 - 95.0) / 1023.0;
const float arri_c = 95.0 / 1023.0;
const float arri_s = (7 * log(2) * pow(2.0, 7 - 14 * arri_c / arri_b)) / (arri_a * arri_b);
const float arri_t = (pow(2.0, 14.0 * (-arri_c / arri_b) + 6.0) - 64.0) / arri_a;
// LogC4 Curve Encoding Function
float relativeSceneLinearToNormalizedLogC4( float x)
{
if (x < arri_t) {
return (x - arri_t) / arri_s;
}
return (log2( arri_a * x + 64.0) - 6.0) / 14.0 * arri_b + arri_c;
}
// LogC4 Curve Decoding Function
float normalizedLogC4ToRelativeSceneLinear( float x)
{
if (x < 0.0) {
return x * arri_s + arri_t;
}
float p = 14.0 * (x - arri_c) / arri_b + 6.0;
return (pow(2.0, p) - 64.0) / arri_a;
}
const float red_a = 0.224282;
const float red_b = 155.975327;
const float red_c = 0.01;
const float red_g = 15.1927;
float log3G10Inverse(float x)
{
if (x < 0.0) {
return (x/red_g)-red_c;
}
const float out = (pow(10.0,x/red_a)-1.0) / red_b;
return out - red_c;
}
float log3G10(float xx)
{
float x = xx + red_c;
if (x < 0.0) {
return x*red_g;
}
const float out = red_a*log10((x*red_b)+1.0);
return out;
}
float slog3(float x)
{
if (x >= 0.01125000) {
return (420.0 + log10((x + 0.01) / (0.18 + 0.01)) * 261.5) / 1023.0;
} else {
return (x * (171.2102946929 - 95.0)/0.01125000 + 95.0) / 1023.0;
}
}
float slog3inv(float x)
{
if (x >= 171.2102946929 / 1023.0) {
return pow(10.0, ((x * 1023.0 - 420.0) / 261.5)) * (0.18 + 0.01) - 0.01;
} else {
return (x * 1023.0 - 95.0) * 0.01125000 / (171.2102946929 - 95.0);
}
}
const float fuji_a = 5.555556;
const float fuji_b = 0.064829;
const float fuji_c = 0.245281;
const float fuji_d = 0.384316;
const float fuji_e = 8.799461;
const float fuji_f = 0.092864;
const float fuji_cut1 = 0.000889;
const float fuji_cut2 = 0.100686685370811;
float flog2(float x)
{
if (x >= fuji_cut1) {
return fuji_c * log10(fuji_a * x + fuji_b) + fuji_d;
} else {
return fuji_e * x + fuji_f;
}
}
float flog2inv(float x)
{
if (x >= fuji_cut2) {
return pow(10.0, ((x - fuji_d) / fuji_c)) / fuji_a - fuji_b / fuji_a;
} else {
return (x - fuji_f) / fuji_e;
}
}
const float AgxMinEv = -12.47393;
const float AgxMaxEv = 4.026069;
float agx_log(float x)
{
float y = log2(x);
y = (y - AgxMinEv) / (AgxMaxEv - AgxMinEv);
return y;//clamp(y, 0, 1);
}
float agx_log_inv(float x)
{
//return pow(fmax(0.0, x), 2.2);
float y = x * (AgxMaxEv - AgxMinEv) + AgxMinEv;
return pow(2, y);
}
float ACEScct_to_lin(float x)
{
if (x <= 0.0078125) {
return 10.5402377416545 * x + 0.0729055341958355;
} else {
return (log2(x) + 9.72) / 17.52;
}
}
float lin_to_ACEScct(float x)
{
if (x <= 0.15525114155) {
return (x - 0.0729055341958355) / 10.5402377416545;
} else {
return pow(2, x * 17.52 - 9.72);
}
}
// @ART-param: ["direction", "$CTL_DIRECTION;Direction", ["$CTL_FORWARD_LIN_LOG;Forward (linear to log)", "$CTL_FORWARD_LOG_LIN;Inverse (log to linear)"], 0]
// @ART-param: ["mode", "$CTL_LOG_CURVE;Log curve", ["ACEScct", "ARRI LogC4", "RED Log3G10", "Sony Slog3", "Fujifilm F-Log2", "AgX log2"], 0]
void ART_main(varying float r, varying float g, varying float b,
output varying float rout,
output varying float gout,
output varying float bout,
int direction, int mode)
{
float rgb[3] = { r, g, b };
const bool invert = (direction == 1);
if (mode == 1) {
if (invert) {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = normalizedLogC4ToRelativeSceneLinear(rgb[i]);
}
} else {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = relativeSceneLinearToNormalizedLogC4(rgb[i]);
}
}
} else if (mode == 2) {
if (invert) {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = log3G10Inverse(rgb[i]);
}
} else {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = log3G10(rgb[i]);
}
}
} else if (mode == 3) {
if (invert) {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = slog3inv(rgb[i]);
}
} else {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = slog3(rgb[i]);
}
}
} else if (mode == 4) {
if (invert) {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = flog2inv(rgb[i]);
}
} else {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = flog2(rgb[i]);
}
}
} else if (mode == 5) {
if (invert) {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = agx_log_inv(rgb[i]);
}
} else {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = agx_log(rgb[i]);
}
}
} else {
if (invert) {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = lin_to_ACEScct(rgb[i]);
}
} else {
for (int i = 0; i < 3; i = i+1) {
rgb[i] = ACEScct_to_lin(rgb[i]);
}
}
}
rout = rgb[0];
gout = rgb[1];
bout = rgb[2];
}