Skip to content

Instantly share code, notes, and snippets.

@memononen
Last active February 2, 2022 10:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save memononen/df1728511aed9e410d871bbff0a58c83 to your computer and use it in GitHub Desktop.
Save memononen/df1728511aed9e410d871bbff0a58c83 to your computer and use it in GitHub Desktop.
bias gain inflection point
float evalCurve(float x, float tx, float ty, float sa, float sb)
{
const float EPS = 1e-6f;
if (x < tx) {
return (ty * x) / (x + sa * (tx - x) + EPS);
} else {
return ((1-ty) * (x-1)) / ((1-x) - sb * (tx - x) + EPS) + 1.0f;
}
}
float tx = pts[0].x; // Inflection point
float ty = pts[0].y;
float slope = (pts[0].y - pts[1].y) / (pts[0].x - pts[1].x); // Second control point controls slope
float slopea = slope * ((tx-0)/(ty-0));
float slopeb = slope * ((1-tx)/(1-ty));
float y = evalCurve(x, tx, ty, slopea, slopeb);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment