Fix blending transparent colors

This commit is contained in:
Nikita Lisitsa 2023-06-06 13:21:04 +03:00
parent 1770a83bdc
commit 48a85dfd66

View file

@ -83,19 +83,6 @@ 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 <std::size_t N>
auto blend(geom::vector<std::uint8_t, N> const & c0, geom::vector<std::uint8_t, N> const & c1, float t)
{
return to_coloru8(blend(to_colorf(c0), to_colorf(c1), t));
}
template <std::size_t N>
auto to_srgb(geom::vector<float, N> const & c, float g = 1.f / 2.2f)
{
@ -182,6 +169,19 @@ namespace psemek::gfx
};
}
inline color_4f blend(color_4f const & c0, color_4f const & c1)
{
color_4f result = c0 * c0[3] * (1.f - c1[3]) + c1 * c1[3];
result[3] = c0[3] + c1[3] - c0[3] * c1[3];
return unpremult(result);
}
template <std::size_t N>
auto blend(geom::vector<std::uint8_t, N> const & c0, geom::vector<std::uint8_t, N> const & c1, float t)
{
return to_coloru8(blend(to_colorf(c0), to_colorf(c1), t));
}
template <std::size_t N>
struct as_hex
{