forked from sobotka/SB2383-Configuration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAgx-SB2383.dctl
172 lines (122 loc) · 5.97 KB
/
Agx-SB2383.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
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
//Based on Troy Sobotka's work
//Agx log is a pure log2 trasfer function with 10 stops under 0.18 and 6.5 stops over middle grey
__DEVICE__ float Lintolog(float in,float mn, float mx)
{
float minimum = _powf(2,-15)*0.18;
in = _fmaxf(minimum,in);
in = _logf(in/0.18)/_logf(2);
in = (in-mn)/(mx-mn);
return in;
}
//SB2383 ored=4.5,og=-0.5,ob= -2.0
DEFINE_UI_PARAMS(rc, R Compress, DCTLUI_SLIDER_FLOAT, 0.15, 0, 1, 0.01)
DEFINE_UI_PARAMS(gc, G Compress, DCTLUI_SLIDER_FLOAT, 0.1, 0, 1, 0.01)
DEFINE_UI_PARAMS(bc,B Compress, DCTLUI_SLIDER_FLOAT, 0.1, 0, 1, 0.01)
DEFINE_UI_PARAMS(ored, Rotate R, DCTLUI_SLIDER_FLOAT, 4.5, -10.0, 10, 1)
DEFINE_UI_PARAMS(og, Rotate G, DCTLUI_SLIDER_FLOAT, -0.5, -10.0, 10, 1)
DEFINE_UI_PARAMS(ob, Rotate B, DCTLUI_SLIDER_FLOAT, -2.0, -10.0, 10, 1)
DEFINE_UI_PARAMS(sp, Shoulder Power, DCTLUI_SLIDER_FLOAT, 1.5, 0, 3, 0.1)
DEFINE_UI_PARAMS(tp, Toe Power, DCTLUI_SLIDER_FLOAT, 1.5, 0, 3, 0.1)
DEFINE_UI_PARAMS(slope, Fulcrum Slope, DCTLUI_SLIDER_FLOAT, 2.4, 1, 3, 0.1)
DEFINE_UI_PARAMS(in_gamut, input gamut, DCTLUI_COMBO_BOX, 13, {ap0, ap1, p3d65,p3d60, rec2020, rec709, awg3, awg4,rwg, sgamut3,sgamut3cine, blackmagicwg, canoncinema, davinciwg,egamut}, {ACES, ACEScg, P3D65,P3D60, Rec.2020, Rec.709, Alexa Wide Gamut 3,Alexa Wide Gamut 4, Red Wide Gamut RGB, Sony SGamut3,Sony SGamut3Cine, Blackmagic Wide Gamut, Canon Cinema - Gamut, DaVinci Wide Gamut,Filmlight E - Gamut})
DEFINE_UI_PARAMS(in_curve, input curve, DCTLUI_COMBO_BOX, 8, {linear, acescct, arri_logc,arri_logc4, red_log3g10, sony_slog3, blackmagic_film_gen5, canonlog3, davinci_intermediate,filmlight_tlog}, {Linear, ACEScct, Arri V3LogC,Arri LogCV4, Red Log3G10, Sony SLog3, Blackmagic Film Gen5, Canon Log3, DaVinci Intermediate,Filmlight TLog})
DEFINE_UI_PARAMS(Loginput, AGXlog Input, DCTLUI_CHECK_BOX, 0)
DEFINE_UI_PARAMS(Output, Output, DCTLUI_COMBO_BOX, 0, {BaseRec709, AgxLog}, {BaseRec709, AgxLog})
#include "SB2383lib.h"
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B)
{
float3x3 in_to_xyz;
if (in_gamut == ap0) in_to_xyz = matrix_ap0_to_xyz;
else if (in_gamut == ap1) in_to_xyz = matrix_ap1_to_xyz;
else if (in_gamut == p3d65) in_to_xyz = matrix_p3d65_to_xyz;
else if (in_gamut == p3d60) in_to_xyz = RGBtoXYZ(P3D60_PRI);
else if (in_gamut == rec2020) in_to_xyz = matrix_rec2020_to_xyz;
else if (in_gamut == rec709) in_to_xyz = matrix_rec709_to_xyz;
else if (in_gamut == awg3) in_to_xyz = matrix_arriwg_to_xyz;
else if (in_gamut == rwg) in_to_xyz = matrix_redwg_to_xyz;
else if (in_gamut == sgamut3) in_to_xyz = matrix_sonysgamut3;
else if (in_gamut == blackmagicwg) in_to_xyz = matrix_blackmagicwg_to_xyz;
else if (in_gamut == canoncinema) in_to_xyz = matrix_canoncinema_to_xyz;
else if (in_gamut == davinciwg) in_to_xyz = matrix_davinciwg_to_xyz;
else if (in_gamut == egamut) in_to_xyz = matrix_egamut_to_xyz;
else if (in_gamut == awg4) in_to_xyz = RGBtoXYZ(ARRI_ALEXA_WG4_PRI);
else if (in_gamut == sgamut3cine) in_to_xyz = RGBtoXYZ(SGAMUT3cine_PRI);
const float3x3 xyz_to_in = inv_f33(in_to_xyz);
int tf;
if (in_curve == linear) tf = 0;
else if (in_curve == acescct) tf = 1;
else if (in_curve == arri_logc) tf = 2;
else if (in_curve == red_log3g10) tf = 3;
else if (in_curve == sony_slog3) tf = 4;
else if (in_curve == filmlight_tlog) tf = 5;
else if (in_curve == davinci_intermediate) tf = 6;
else if (in_curve == blackmagic_film_gen5) tf = 7;
else if (in_curve == canonlog3) tf = 8;
else if (in_curve == arri_logc4) tf = 9;
//Pre calculate parameters
//SB2383 scale parameters
//float rc = 0.15;
//float gc = 0.15;
//float bc = 0.1;
Chromaticities rec709_inset = InsetPrimaries(REC709_PRI,rc,gc,bc,ored,og,ob);
float3x3 outsetmat= RGBtoRGB(REC709_PRI,rec709_inset);
float3x3 insetmat= inv_f33(outsetmat);
float mg = _powf(0.18,1/2.2);
float lmg = ((_logf(0.18/0.18)/_logf(2))+10)/16.5;
float gm = 1/2.2;
//Troy Curve Parameters
//float sp = 1.5;
//float tp = 1.5;
//float slope = 2.4;
//Calculate Matrices
const float3x3 xyz_to_rec709 = inv_f33(matrix_rec709_to_xyz);
//Input
float3 rgb = make_float3(p_R, p_G, p_B);
float3 agx = rgb;
rgb = log2lin(rgb, tf);
float3 xyz = mult_f3_f33(rgb, in_to_xyz);
rgb = mult_f3_f33(xyz, xyz_to_rec709);
rgb = maxf3(0.0,rgb);
//Guardrail chroma to rec2020,reduces chroma until no negative values exist
//rgb = Lowrail(rgb,REC709_PRI_2012);
//rgb= Gamutlimiter(rgb,REC709_PRI_2012);
//Black and White option
//rgb = Blackandwhite == 1? desaturate(rgb,REC709_PRI_2012,0.0):rgb;
//apply inset matrix
rgb = mult_f3_f33(rgb,insetmat);
rgb.x = Lintolog(rgb.x,-10,6.5);
rgb.y = Lintolog(rgb.y,-10,6.5);
rgb.z = Lintolog(rgb.z,-10,6.5);
float3 log = rgb;
if (Loginput == 1)
rgb=agx;
rgb.x = tonescale(rgb.x, sp, tp, slope, lmg, mg,1,0);
rgb.y = tonescale(rgb.y, sp, tp, slope, lmg, mg,1,0);
rgb.z = tonescale(rgb.z, sp, tp, slope, lmg, mg,1,0);
rgb = clampf3(rgb,0,1);
float3 img = rgb;
//img = clampf3(img,0,1);
switch (Output) {
case BaseRec709:
img = img;
img = spowf3(img,2.2);
img = mult_f3_f33(img,outsetmat);
img = (spowf3(img,gm));
img = maxf3(0.0,img);
//img.x = _fabs(img.x);
//img.y = _fabs(img.y);
//img.z = _fabs(img.z);
break;
case AgxLog:
img=log;
//img=img;
break;
}
//img= Gamutlimiter(img,REC709_PRI_2012);
//img = Lowrail(img,REC709_PRI_2012);
//img = RGB2HCL(REC709_PRI_2012,img);
//img.y = tonescale3(img.y, 4.115, 1.54, 1.01 , 0.344, 0.14 , 0.5 , 0.5 , 0.95 , 1.0 , 0.0 ,0.0);
//img = HCL2RGB(REC709_PRI_2012,img);
//img = highguardrail(img,REC709_PRI_2012,1.0,1.0);
return img;
}