Skip to content

Commit da38f23

Browse files
committed
Added clamp & adjustable height
1 parent f379b31 commit da38f23

File tree

2 files changed

+71
-43
lines changed

2 files changed

+71
-43
lines changed

Inverse-S-Curves.dctl

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ DEFINE_UI_PARAMS(sSteep, Curve Steepness, DCTLUI_SLIDER_FLOAT, 6, 1, 30, 1.0)
22
DEFINE_UI_PARAMS(sMid, Mid Point, DCTLUI_SLIDER_FLOAT, 0.41, 0, 1, 0.1)
33
DEFINE_UI_PARAMS(curveChoice, Inverse Curve Type, DCTLUI_COMBO_BOX, 0, {logType, abType, alType, tanType}, {Logistic,Absolute,Square,Hyperbolic Tangent})
44
DEFINE_UI_PARAMS(timeGamma, Timeline Gamma, DCTLUI_COMBO_BOX, 0, {recGam, linGam}, {Scene,Linear})
5+
DEFINE_UI_PARAMS(sHeight, Height, DCTLUI_SLIDER_FLOAT, 1.0, 1.0, 13, 0.1)
6+
DEFINE_UI_PARAMS(isClamp, Clamp, DCTLUI_CHECK_BOX, 1)
57

6-
__CONSTANT__ float sHeight = 1.0f;
78

89
__DEVICE__ float invLogFunc(float s_H, float s_S, float s_M, float x) {
910
return (_logf((s_H / x) - 1.0f) / (- s_S)) + s_M ;
@@ -14,7 +15,7 @@ __DEVICE__ float invTanFunc(float s_H, float s_S, float s_M, float x) {
1415
}
1516

1617
__DEVICE__ float invAbFunc(float s_H, float s_S, float s_M, float x) {
17-
if(x >= 0.5f) return (- s_H * s_S * s_M + 0.5 * s_H + x * s_S * s_M - x) / (s_S * (x - s_H));
18+
if(x >= 0.5f * s_H) return (- s_H * s_S * s_M + 0.5 * s_H + x * s_S * s_M - x) / (s_S * (x - s_H));
1819
else return -1.0f * ((0.5 * s_H - x * s_S * s_M - x) / (x * s_S));
1920
}
2021

@@ -23,7 +24,7 @@ __DEVICE__ float invAlFunc(float s_H, float s_S, float s_M, float x) {
2324
float xVal = (2.0f * x / s_H - 1.0f) * (2.0f * x / s_H - 1.0f);
2425
float val = _sqrtf((1.0f / s_S) / (1.0f / xVal - 1.0f));
2526

26-
if(x >= 0.5f) return val + s_M;
27+
if(x >= 0.5f * s_H) return val + s_M;
2728
else return (-1.0f * val) + s_M;
2829
}
2930

@@ -41,40 +42,54 @@ __DEVICE__ float lin_to_rec(float x) {
4142
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B)
4243
{
4344

45+
float3 pRGB = {p_R, p_G, p_B};
46+
47+
if(isClamp) {
48+
pRGB.x = _clampf(pRGB.x, 0.0f, sHeight);
49+
pRGB.y = _clampf(pRGB.y, 0.0f, sHeight);
50+
pRGB.z = _clampf(pRGB.z, 0.0f, sHeight);
51+
}
52+
4453
if(timeGamma == linGam) {
45-
p_R = lin_to_rec(p_R);
46-
p_G = lin_to_rec(p_G);
47-
p_B = lin_to_rec(p_B);
54+
pRGB.x = lin_to_rec(pRGB.x);
55+
pRGB.y = lin_to_rec(pRGB.y);
56+
pRGB.z = lin_to_rec(pRGB.z);
4857
}
4958

5059
switch(curveChoice) {
5160
case tanType:
52-
p_R = invTanFunc(sHeight,sSteep,sMid,p_R);
53-
p_G = invTanFunc(sHeight,sSteep,sMid,p_G);
54-
p_B = invTanFunc(sHeight,sSteep,sMid,p_B);
61+
pRGB.x = invTanFunc(sHeight,sSteep,sMid,pRGB.x);
62+
pRGB.y = invTanFunc(sHeight,sSteep,sMid,pRGB.y);
63+
pRGB.z = invTanFunc(sHeight,sSteep,sMid,pRGB.z);
5564
break;
5665
case abType:
57-
p_R = invAbFunc(sHeight,sSteep,sMid,p_R);
58-
p_G = invAbFunc(sHeight,sSteep,sMid,p_G);
59-
p_B = invAbFunc(sHeight,sSteep,sMid,p_B);
66+
pRGB.x = invAbFunc(sHeight,sSteep,sMid,pRGB.x);
67+
pRGB.y = invAbFunc(sHeight,sSteep,sMid,pRGB.y);
68+
pRGB.z = invAbFunc(sHeight,sSteep,sMid,pRGB.z);
6069
break;
6170
case alType:
62-
p_R = invAlFunc(sHeight,sSteep,sMid,p_R);
63-
p_G = invAlFunc(sHeight,sSteep,sMid,p_G);
64-
p_B = invAlFunc(sHeight,sSteep,sMid,p_B);
71+
pRGB.x = invAlFunc(sHeight,sSteep,sMid,pRGB.x);
72+
pRGB.y = invAlFunc(sHeight,sSteep,sMid,pRGB.y);
73+
pRGB.z = invAlFunc(sHeight,sSteep,sMid,pRGB.z);
6574
break;
6675
default: //Logistic
67-
p_R = invLogFunc(sHeight,sSteep,sMid,p_R);
68-
p_G = invLogFunc(sHeight,sSteep,sMid,p_G);
69-
p_B = invLogFunc(sHeight,sSteep,sMid,p_B);
76+
pRGB.x = invLogFunc(sHeight,sSteep,sMid,pRGB.x);
77+
pRGB.y = invLogFunc(sHeight,sSteep,sMid,pRGB.y);
78+
pRGB.z = invLogFunc(sHeight,sSteep,sMid,pRGB.z);
7079
break;
7180
}
7281

7382
if(timeGamma == linGam) {
74-
p_R = rec_to_lin(p_R);
75-
p_G = rec_to_lin(p_G);
76-
p_B = rec_to_lin(p_B);
83+
pRGB.x = rec_to_lin(pRGB.x);
84+
pRGB.y = rec_to_lin(pRGB.y);
85+
pRGB.z = rec_to_lin(pRGB.z);
86+
}
87+
88+
if(isClamp) {
89+
pRGB.x = _clampf(pRGB.x, 0.0f, sHeight);
90+
pRGB.y = _clampf(pRGB.y, 0.0f, sHeight);
91+
pRGB.z = _clampf(pRGB.z, 0.0f, sHeight);
7792
}
7893

79-
return make_float3(p_R,p_G,p_B);
94+
return pRGB;
8095
}

S-Curves.dctl

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ DEFINE_UI_PARAMS(sSteep, Curve Steepness, DCTLUI_SLIDER_FLOAT, 6, 1, 30, 1.0)
22
DEFINE_UI_PARAMS(sMid, Mid Point, DCTLUI_SLIDER_FLOAT, 0.41, 0, 1, 0.1)
33
DEFINE_UI_PARAMS(curveChoice, Curve Type, DCTLUI_COMBO_BOX, 0, {logType, abType, alType, tanType}, {Logistic,Absolute,Square,Hyperbolic Tangent})
44
DEFINE_UI_PARAMS(timeGamma, Timeline Gamma, DCTLUI_COMBO_BOX, 0, {recGam, linGam}, {Scene,Linear})
5-
6-
__CONSTANT__ float sHeight = 1.0f;
5+
DEFINE_UI_PARAMS(sHeight, Height, DCTLUI_SLIDER_FLOAT, 1.0, 1.0, 13, 0.1)
6+
DEFINE_UI_PARAMS(isClamp, Clamp, DCTLUI_CHECK_BOX, 1)
77

88
__DEVICE__ float logFunc(float s_H, float s_S, float s_M, float x) {
99
return (s_H / (1.0f + _expf(- s_S * (x - s_M))));
@@ -35,41 +35,54 @@ __DEVICE__ float lin_to_rec(float x) {
3535

3636
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B)
3737
{
38+
float3 pRGB = {p_R, p_G, p_B};
39+
40+
if(isClamp) {
41+
pRGB.x = _clampf(pRGB.x, 0.0f, sHeight);
42+
pRGB.y = _clampf(pRGB.y, 0.0f, sHeight);
43+
pRGB.z = _clampf(pRGB.z, 0.0f, sHeight);
44+
}
3845

3946
if(timeGamma == linGam) {
40-
p_R = lin_to_rec(p_R);
41-
p_G = lin_to_rec(p_G);
42-
p_B = lin_to_rec(p_B);
47+
pRGB.x = lin_to_rec(pRGB.x);
48+
pRGB.y = lin_to_rec(pRGB.y);
49+
pRGB.z = lin_to_rec(pRGB.z);
4350
}
4451

4552
switch(curveChoice) {
4653
case tanType:
47-
p_R = tanFunc(sHeight,sSteep,sMid,p_R);
48-
p_G = tanFunc(sHeight,sSteep,sMid,p_G);
49-
p_B = tanFunc(sHeight,sSteep,sMid,p_B);
54+
pRGB.x = tanFunc(sHeight,sSteep,sMid,pRGB.x);
55+
pRGB.y = tanFunc(sHeight,sSteep,sMid,pRGB.y);
56+
pRGB.z = tanFunc(sHeight,sSteep,sMid,pRGB.z);
5057
break;
5158
case abType:
52-
p_R = abFunc(sHeight,sSteep,sMid,p_R);
53-
p_G = abFunc(sHeight,sSteep,sMid,p_G);
54-
p_B = abFunc(sHeight,sSteep,sMid,p_B);
59+
pRGB.x = abFunc(sHeight,sSteep,sMid,pRGB.x);
60+
pRGB.y = abFunc(sHeight,sSteep,sMid,pRGB.y);
61+
pRGB.z = abFunc(sHeight,sSteep,sMid,pRGB.z);
5562
break;
5663
case alType:
57-
p_R = alFunc(sHeight,sSteep,sMid,p_R);
58-
p_G = alFunc(sHeight,sSteep,sMid,p_G);
59-
p_B = alFunc(sHeight,sSteep,sMid,p_B);
64+
pRGB.x = alFunc(sHeight,sSteep,sMid,pRGB.x);
65+
pRGB.y = alFunc(sHeight,sSteep,sMid,pRGB.y);
66+
pRGB.z = alFunc(sHeight,sSteep,sMid,pRGB.z);
6067
break;
6168
default: //Logistic
62-
p_R = logFunc(sHeight,sSteep,sMid,p_R);
63-
p_G = logFunc(sHeight,sSteep,sMid,p_G);
64-
p_B = logFunc(sHeight,sSteep,sMid,p_B);
69+
pRGB.x = logFunc(sHeight,sSteep,sMid,pRGB.x);
70+
pRGB.y = logFunc(sHeight,sSteep,sMid,pRGB.y);
71+
pRGB.z = logFunc(sHeight,sSteep,sMid,pRGB.z);
6572
break;
6673
}
6774

6875
if(timeGamma == linGam) {
69-
p_R = rec_to_lin(p_R);
70-
p_G = rec_to_lin(p_G);
71-
p_B = rec_to_lin(p_B);
76+
pRGB.x = rec_to_lin(pRGB.x);
77+
pRGB.y = rec_to_lin(pRGB.y);
78+
pRGB.z = rec_to_lin(pRGB.z);
79+
}
80+
81+
if(isClamp) {
82+
pRGB.x = _clampf(pRGB.x, 0.0f, sHeight);
83+
pRGB.y = _clampf(pRGB.y, 0.0f, sHeight);
84+
pRGB.z = _clampf(pRGB.z, 0.0f, sHeight);
7285
}
7386

74-
return make_float3(p_R,p_G,p_B);
87+
return pRGB;
7588
}

0 commit comments

Comments
 (0)