Skip to content

Commit

Permalink
Added clamp & adjustable height
Browse files Browse the repository at this point in the history
  • Loading branch information
RikshaDriver committed Sep 3, 2022
1 parent f379b31 commit da38f23
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 43 deletions.
59 changes: 37 additions & 22 deletions Inverse-S-Curves.dctl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ 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, Inverse 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)

__CONSTANT__ float sHeight = 1.0f;

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

__DEVICE__ float invAbFunc(float s_H, float s_S, float s_M, float x) {
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));
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));
else return -1.0f * ((0.5 * s_H - x * s_S * s_M - x) / (x * s_S));
}

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

if(x >= 0.5f) return val + s_M;
if(x >= 0.5f * s_H) return val + s_M;
else return (-1.0f * val) + s_M;
}

Expand All @@ -41,40 +42,54 @@ __DEVICE__ float lin_to_rec(float 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)
{

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) {
p_R = lin_to_rec(p_R);
p_G = lin_to_rec(p_G);
p_B = lin_to_rec(p_B);
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:
p_R = invTanFunc(sHeight,sSteep,sMid,p_R);
p_G = invTanFunc(sHeight,sSteep,sMid,p_G);
p_B = invTanFunc(sHeight,sSteep,sMid,p_B);
pRGB.x = invTanFunc(sHeight,sSteep,sMid,pRGB.x);
pRGB.y = invTanFunc(sHeight,sSteep,sMid,pRGB.y);
pRGB.z = invTanFunc(sHeight,sSteep,sMid,pRGB.z);
break;
case abType:
p_R = invAbFunc(sHeight,sSteep,sMid,p_R);
p_G = invAbFunc(sHeight,sSteep,sMid,p_G);
p_B = invAbFunc(sHeight,sSteep,sMid,p_B);
pRGB.x = invAbFunc(sHeight,sSteep,sMid,pRGB.x);
pRGB.y = invAbFunc(sHeight,sSteep,sMid,pRGB.y);
pRGB.z = invAbFunc(sHeight,sSteep,sMid,pRGB.z);
break;
case alType:
p_R = invAlFunc(sHeight,sSteep,sMid,p_R);
p_G = invAlFunc(sHeight,sSteep,sMid,p_G);
p_B = invAlFunc(sHeight,sSteep,sMid,p_B);
pRGB.x = invAlFunc(sHeight,sSteep,sMid,pRGB.x);
pRGB.y = invAlFunc(sHeight,sSteep,sMid,pRGB.y);
pRGB.z = invAlFunc(sHeight,sSteep,sMid,pRGB.z);
break;
default: //Logistic
p_R = invLogFunc(sHeight,sSteep,sMid,p_R);
p_G = invLogFunc(sHeight,sSteep,sMid,p_G);
p_B = invLogFunc(sHeight,sSteep,sMid,p_B);
pRGB.x = invLogFunc(sHeight,sSteep,sMid,pRGB.x);
pRGB.y = invLogFunc(sHeight,sSteep,sMid,pRGB.y);
pRGB.z = invLogFunc(sHeight,sSteep,sMid,pRGB.z);
break;
}

if(timeGamma == linGam) {
p_R = rec_to_lin(p_R);
p_G = rec_to_lin(p_G);
p_B = rec_to_lin(p_B);
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 make_float3(p_R,p_G,p_B);
return pRGB;
}
55 changes: 34 additions & 21 deletions S-Curves.dctl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ 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})

__CONSTANT__ float sHeight = 1.0f;
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))));
Expand Down Expand Up @@ -35,41 +35,54 @@ __DEVICE__ float lin_to_rec(float 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)
{
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) {
p_R = lin_to_rec(p_R);
p_G = lin_to_rec(p_G);
p_B = lin_to_rec(p_B);
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:
p_R = tanFunc(sHeight,sSteep,sMid,p_R);
p_G = tanFunc(sHeight,sSteep,sMid,p_G);
p_B = tanFunc(sHeight,sSteep,sMid,p_B);
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:
p_R = abFunc(sHeight,sSteep,sMid,p_R);
p_G = abFunc(sHeight,sSteep,sMid,p_G);
p_B = abFunc(sHeight,sSteep,sMid,p_B);
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:
p_R = alFunc(sHeight,sSteep,sMid,p_R);
p_G = alFunc(sHeight,sSteep,sMid,p_G);
p_B = alFunc(sHeight,sSteep,sMid,p_B);
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
p_R = logFunc(sHeight,sSteep,sMid,p_R);
p_G = logFunc(sHeight,sSteep,sMid,p_G);
p_B = logFunc(sHeight,sSteep,sMid,p_B);
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) {
p_R = rec_to_lin(p_R);
p_G = rec_to_lin(p_G);
p_B = rec_to_lin(p_B);
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 make_float3(p_R,p_G,p_B);
return pRGB;
}

0 comments on commit da38f23

Please sign in to comment.