GMLscripts.com

gain

A fast variation of Ken Perlin's gain function developed by Christophe Schlick.

gain

gain(g, x)
Returns the given value with a gain function applied to it.
COPY
  1. /// @func gain(g, x)
  2. ///
  3. /// @desc Returns the given value with a gain function applied to it.
  4. ///
  5. /// If x varies over the [0,1] interval, then the result also
  6. /// varies over that interval. The 0 and 1 endpoints of the
  7. /// interval are mapped onto themselves. Regardless of the value
  8. /// of g, all gain functions return 0.5 when x is 0.5. Above
  9. /// and below 0.5 the gain function consists of two scaled-down
  10. /// bias curves forming an S-shaped curve.
  11. ///
  12. /// @param {real} g gain
  13. /// @param {real} x value
  14. ///
  15. /// @return {real} adjusted value
  16. ///
  17. /// GMLscripts.com/license
  18.  
  19. function gain(g, x)
  20. {
  21. var p;
  22. p = (1 / g - 2) * (1 - 2 * x);
  23. if (x < 0.5) return x / (p + 1);
  24. return (p - x) / (p - 1);
  25. }

Contributors: xot

GitHub: View · Commits · Blame · Raw