From 6f050bd1c8f8689f2f33683b46a258264c3f30c4 Mon Sep 17 00:00:00 2001 From: Colby Klein Date: Mon, 10 Aug 2015 18:59:43 -0700 Subject: [PATCH] Add utils.smoothstep (smooth hermite interpolation) --- modules/utils.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/utils.lua b/modules/utils.lua index 939e819..68494a3 100644 --- a/modules/utils.lua +++ b/modules/utils.lua @@ -12,6 +12,11 @@ function utils.lerp(v, l, h) return v * (h - l) + l end +function utils.smoothstep(v, l, h) + local t = utils.clamp((v - l) / (h - l), 0.0, 1.0) + return t * t * (3.0 - 2.0 * t) +end + function utils.round(v, precision) if precision then return utils.round(v / precision) * precision end return v >= 0 and math.floor(v+0.5) or math.ceil(v-0.5)