From 63f576aee53caec2589181f3e14cee5dc0970729 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sun, 15 Jan 2023 14:23:06 +0300 Subject: [PATCH] Add gfx::blend for colors --- libs/gfx/include/psemek/gfx/color.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/gfx/include/psemek/gfx/color.hpp b/libs/gfx/include/psemek/gfx/color.hpp index f70e1f20..845776c6 100644 --- a/libs/gfx/include/psemek/gfx/color.hpp +++ b/libs/gfx/include/psemek/gfx/color.hpp @@ -83,6 +83,19 @@ namespace psemek::gfx return to_coloru8(lerp(to_colorf(c0), to_colorf(c1), t)); } + inline color_4f blend(color_4f const & c0, color_4f const & c1) + { + color_4f result = lerp(c0, c1, c1[3]); + result[3] = c0[3] * (1.f - c1[3]) + c1[3]; + return result; + } + + template + auto blend(geom::vector const & c0, geom::vector const & c1, float t) + { + return to_coloru8(blend(to_colorf(c0), to_colorf(c1), t)); + } + template auto to_srgb(geom::vector const & c, float g = 1.f / 2.2f) {