-
Notifications
You must be signed in to change notification settings - Fork 8
/
S-Curves.dctl
88 lines (74 loc) · 2.78 KB
/
S-Curves.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
DEFINE_UI_PARAMS(sSteep, Curve Steepness, DCTLUI_SLIDER_FLOAT, 6, 1, 30, 1.0)
DEFINE_UI_PARAMS(sMid, Mid Point, DCTLUI_SLIDER_FLOAT, 0.41, 0, 1, 0.1)
DEFINE_UI_PARAMS(curveChoice, Curve Type, DCTLUI_COMBO_BOX, 0, {logType, abType, alType, tanType}, {Logistic,Absolute,Square,Hyperbolic Tangent})
DEFINE_UI_PARAMS(timeGamma, Timeline Gamma, DCTLUI_COMBO_BOX, 0, {recGam, linGam}, {Scene,Linear})
DEFINE_UI_PARAMS(sHeight, Height, DCTLUI_SLIDER_FLOAT, 1.0, 1.0, 13, 0.1)
DEFINE_UI_PARAMS(isClamp, Clamp, DCTLUI_CHECK_BOX, 1)
__DEVICE__ float logFunc(float s_H, float s_S, float s_M, float x) {
return (s_H / (1.0f + _expf(- s_S * (x - s_M))));
}
__DEVICE__ float tanFunc(float s_H, float s_S, float s_M, float x) {
return (s_H / 2.0f) * _tanhf( s_S * (x - s_M)) + (s_H / 2.0f);
}
__DEVICE__ float abFunc(float s_H, float s_S, float s_M, float x) {
//return s_H * 0.5f * ((x - s_M) / _sqrtf((1.0f/s_S) + _powf((x - s_M), 2.0f)) + 1.0f);
return s_H * 0.5f * ((x - s_M) / ((1.0f / s_S) + _fabs(x - s_M)) + 1.0f);
}
__DEVICE__ float alFunc(float s_H, float s_S, float s_M, float x) {
return s_H * 0.5f * ((x - s_M) / _sqrtf((1.0f / s_S) + (x - s_M)*(x - s_M)) + 1.0f);
}
__DEVICE__ float rec_to_lin(float x) {
if(x < 0.081f) return (x / 4.5f);
else return _powf((x + 0.099f)/1.099f,(1.0f/0.45f));
}
__DEVICE__ float lin_to_rec(float x) {
if(x < .0018f) return 4.5f * x;
else return 1.099f * _powf(x,0.45f) - 0.099f;
}
__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 pRGB = {p_R, p_G, p_B};
if(isClamp) {
pRGB.x = _clampf(pRGB.x, 0.0f, sHeight);
pRGB.y = _clampf(pRGB.y, 0.0f, sHeight);
pRGB.z = _clampf(pRGB.z, 0.0f, sHeight);
}
if(timeGamma == linGam) {
pRGB.x = lin_to_rec(pRGB.x);
pRGB.y = lin_to_rec(pRGB.y);
pRGB.z = lin_to_rec(pRGB.z);
}
switch(curveChoice) {
case tanType:
pRGB.x = tanFunc(sHeight,sSteep,sMid,pRGB.x);
pRGB.y = tanFunc(sHeight,sSteep,sMid,pRGB.y);
pRGB.z = tanFunc(sHeight,sSteep,sMid,pRGB.z);
break;
case abType:
pRGB.x = abFunc(sHeight,sSteep,sMid,pRGB.x);
pRGB.y = abFunc(sHeight,sSteep,sMid,pRGB.y);
pRGB.z = abFunc(sHeight,sSteep,sMid,pRGB.z);
break;
case alType:
pRGB.x = alFunc(sHeight,sSteep,sMid,pRGB.x);
pRGB.y = alFunc(sHeight,sSteep,sMid,pRGB.y);
pRGB.z = alFunc(sHeight,sSteep,sMid,pRGB.z);
break;
default: //Logistic
pRGB.x = logFunc(sHeight,sSteep,sMid,pRGB.x);
pRGB.y = logFunc(sHeight,sSteep,sMid,pRGB.y);
pRGB.z = logFunc(sHeight,sSteep,sMid,pRGB.z);
break;
}
if(timeGamma == linGam) {
pRGB.x = rec_to_lin(pRGB.x);
pRGB.y = rec_to_lin(pRGB.y);
pRGB.z = rec_to_lin(pRGB.z);
}
if(isClamp) {
pRGB.x = _clampf(pRGB.x, 0.0f, sHeight);
pRGB.y = _clampf(pRGB.y, 0.0f, sHeight);
pRGB.z = _clampf(pRGB.z, 0.0f, sHeight);
}
return pRGB;
}