procedurals
Procedural generation building blocks
Loading...
Searching...
No Matches
Smoothing.hpp
Go to the documentation of this file.
1
11#include "Deterministic.hpp"
12
13inline float Lerp(float a, float b, float t) noexcept {
14 return a + t * (b - a);
15}
16
17inline float Clamp(float x, float minVal, float maxVal) noexcept {
18 if (x < minVal) return minVal;
19 if (x > maxVal) return maxVal;
20 return x;
21}
22
23inline float EaseIn(float t) noexcept {
24 t = Clamp(t, 0.0f, 1.0f);
25 return t * t;
26}
27inline float EaseOut(float t) noexcept {
28 t = Clamp(t, 0.0f, 1.0f);
29 return 2.0 * t - t * t;
30}
31
32inline float EaseInOut(float t) noexcept {
33 return EaseIn(EaseOut(t));
34}
35
36inline float InterpolateEaseInOut(float a, float b, float t) noexcept {
37 float s = EaseInOut(t); // easing
38 return Lerp(a, b, s);
39}
40
48template<int Levels = 10>
49inline float Quantize(float v) {
50 constexpr float step = 1.0f / (Levels);
51 int bucket = (int)(v / step);
52 return bucket * step;
53}
float EaseInOut(float t) noexcept
Definition Smoothing.hpp:32
float InterpolateEaseInOut(float a, float b, float t) noexcept
Definition Smoothing.hpp:36
float EaseIn(float t) noexcept
Definition Smoothing.hpp:23
float EaseOut(float t) noexcept
Definition Smoothing.hpp:27
float Lerp(float a, float b, float t) noexcept
Definition Smoothing.hpp:13
float Quantize(float v)
Quantize a float value into discrete levels, useful for stylized effects.
Definition Smoothing.hpp:49
float Clamp(float x, float minVal, float maxVal) noexcept
Definition Smoothing.hpp:17