forked from baldavenger/DCTLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArriLut_sat.dctl
64 lines (43 loc) · 1.83 KB
/
ArriLut_sat.dctl
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
// Arri Lut (LogC AWG to Lin to rec709 to logC to tonemap minus saturation)
__DEVICE__ float logclin(float p_Channel) // logC to linear
{
float lin = p_Channel > 0.1496582f ? (_powf(10.0f, (p_Channel - 0.385537f) / 0.2471896f) - 0.052272f) / 5.555556f : (p_Channel - 0.092809f) / 5.367655f;
return lin;
}
__DEVICE__ float linlogc(float p_Channel) // linear to logC
{
float log = p_Channel > 0.010591f ? 0.247190f * _log10f(5.555556f * p_Channel + 0.052272f) + 0.385537f : 5.367655f * p_Channel + 0.092809f;
return log;
}
__DEVICE__ float logistic(float p_Channel) // tonemaps logC
{
float x = 1.0f / (1.0f + _powf(2.718281828459045, -8.9f*(p_Channel - 0.435f)));
return x;
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B)
{
// logC to linear
float linR = logclin(p_R);
float linG = logclin(p_G);
float linB = logclin(p_B);
// alexawidegamut to rec709 primaries for linear signal
float matrix[9] = {1.617523f, -0.537287f, -0.080237f, -0.070573f, 1.334613f, -0.26404f, -0.021102f, -0.226954f, 1.248056f};
float matR = matrix[0]*linR + matrix[1]*linG + matrix[2]*linB;
float matG = matrix[3]*linR + matrix[4]*linG + matrix[5]*linB;
float matB = matrix[6]*linR + matrix[7]*linG + matrix[8]*linB;
// linear to logC
float logR = linlogc(matR);
float logG = linlogc(matG);
float logB = linlogc(matB);
// logC tonemapped
float R = logistic(logR);
float G = logistic(logG);
float B = logistic(logB);
// saturation roll-off in highlights
float luma = 0.2126f*R + 0.7152f*G + 0.0722f*B;
float sat = 0.7f;
float r = ((1.0f - sat) * luma + sat * R) * luma + R * (1.0f - luma);
float g = ((1.0f - sat) * luma + sat * G) * luma + G * (1.0f - luma);
float b = ((1.0f - sat) * luma + sat * B) * luma + B * (1.0f - luma);
return make_float3(r, g, b);
}