libs/core/src/eu/core/scurve.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | namespace eu::core | ||
| 4 | { | ||
| 5 | |||
| 6 | /** \addtogroup scurcve S-Curve | ||
| 7 | * \brief A tweakable curve similar to easing functions. | ||
| 8 | * Discovered by Yann van der Cruyssen/Morusque on [twitter](https://x.com/Morusque/status/1352569197499441155). | ||
| 9 | * From [A Convenient Generalization of Schlick’s Bias and Gain Functions (pdf)](https://arxiv.org/pdf/2010.09714) by Jonathan T. Barron. | ||
| 10 | * @{ | ||
| 11 | */ | ||
| 12 | |||
| 13 | /// Contains the parameters for an S-Curve. | ||
| 14 | struct SCurve | ||
| 15 | { | ||
| 16 | float slope = 1.0f; ///< >=0 | ||
| 17 | float threshold = 0.75f; ///< [0,1] | ||
| 18 | |||
| 19 | constexpr SCurve() = default; | ||
| 20 | |||
| 21 | 6 | constexpr SCurve(float s, float t) | |
| 22 | 6 | : slope(s) | |
| 23 | 6 | , threshold(t) | |
| 24 | 6 | {} | |
| 25 | |||
| 26 | // todo(Gustav): give a better name | ||
| 27 | ✗ | constexpr static SCurve light_curve() | |
| 28 | { | ||
| 29 | ✗ | return {5.0f, 1.0f}; | |
| 30 | } | ||
| 31 | }; | ||
| 32 | |||
| 33 | /// Generate an S-Curve from user input. | ||
| 34 | /// Adapted from [Colugo's](https://twitter.com/ColugoMusic/status/1363071439679729665?s=20) S curve editor implemented in/on [desmos](https://www.desmos.com/calculator/ibek4vkdiw) | ||
| 35 | /// @param x [0,1] 0=left, 1=right | ||
| 36 | /// @param y [0,1] 0=bottom, 1=top | ||
| 37 | SCurve s_curve_from_input(float x, float y); | ||
| 38 | |||
| 39 | /// Calculates an S-Curve. | ||
| 40 | /// this takes floats instead of the curve since that means it could more easily be copied to glsl | ||
| 41 | /// @param x [0,1] | ||
| 42 | /// @param slope >=0 | ||
| 43 | /// @param threshold [0,1] | ||
| 44 | float calculate_s_curve(float x, float slope, float threshold); | ||
| 45 | |||
| 46 | /** | ||
| 47 | * @} | ||
| 48 | */ | ||
| 49 | |||
| 50 | } // namespace klotter | ||
| 51 |