-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathACES_DLog_DGamut.dctl
executable file
·66 lines (55 loc) · 1.44 KB
/
ACES_DLog_DGamut.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
62
63
64
65
66
// D-Log D-Gamut to ACES AP0 DCTL
typedef struct
{
float3 r0, r1, r2;
} mat3;
__DEVICE__ mat3 make_mat3( float3 A, float3 B, float3 C);
__DEVICE__ float3 mult_f3_f33 (float3 In, mat3 A);
__DEVICE__ float dlog_to_lin(float in);
__DEVICE__ float3 dlog_to_lin3(float3 in);
__DEVICE__ mat3 make_mat3( float3 A, float3 B, float3 C)
{
mat3 D;
D.r0 = A;
D.r1 = B;
D.r2 = C;
return D;
}
__DEVICE__ float3 mult_f3_f33 (float3 In, mat3 A)
{
float out[3];
float in[3] = {In.x, In.y, In.z};
float a[3][3] = {{A.r0.x, A.r0.y, A.r0.z},
{A.r1.x, A.r1.y, A.r1.z},
{A.r2.x, A.r2.y, A.r2.z}};
for( int i = 0; i < 3; ++i)
{
out[i] = 0.0f;
for( int j = 0; j < 3; ++j)
{
out[i] = out[i] + in[j] * a[i][j];
}
}
return make_float3(out[0], out[1], out[2]);
}
#define dgamut_to_AP0 make_mat3(make_float3(0.691279f, 0.214383f, 0.094338f), make_float3(0.066222f, 1.011616f, -0.077838f), make_float3(-0.017299f, -0.077379f, 1.094677f))
__DEVICE__ float dlog_to_lin( float in)
{
float out = in <= 0.14f ? (in - 0.0929f) / 6.025f : (_exp10f(3.89616 * in - 2.27752f) - 0.0108f) / 0.9892f;
return out;
}
__DEVICE__ float3 dlog_to_lin3( float3 in)
{
float3 out;
out.x = dlog_to_lin(in.x);
out.y = dlog_to_lin(in.y);
out.z = dlog_to_lin(in.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 rgb = make_float3(p_R, p_G, p_B);
rgb = dlog_to_lin3(rgb);
rgb = mult_f3_f33(rgb, dgamut_to_AP0);
return rgb;
}