Add color lighting & darkening functions
This commit is contained in:
parent
4d9b8dde29
commit
e5c869f27b
1 changed files with 40 additions and 0 deletions
|
|
@ -100,4 +100,44 @@ namespace psemek::gfx
|
||||||
static const generic_color magenta{{1.f, 0.f, 1.f, 1.f}};
|
static const generic_color magenta{{1.f, 0.f, 1.f, 1.f}};
|
||||||
static const generic_color yellow {{1.f, 1.f, 0.f, 1.f}};
|
static const generic_color yellow {{1.f, 1.f, 0.f, 1.f}};
|
||||||
|
|
||||||
|
static const generic_color gray {{0.50f, 0.50f, 0.50f, 1.f}};
|
||||||
|
|
||||||
|
template <std::size_t N>
|
||||||
|
geom::vector<float, N> light(geom::vector<float, N> c, float lightness = 0.5f)
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
c[i] = geom::lerp(c[i], 1.f, lightness);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::size_t N>
|
||||||
|
geom::vector<float, N> dark(geom::vector<float, N> c, float darkness = 0.5f)
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
c[i] = geom::lerp(c[i], 0.f, darkness);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::size_t N>
|
||||||
|
geom::vector<std::uint8_t, N> light(geom::vector<std::uint8_t, N> c, float lightness = 0.5f)
|
||||||
|
{
|
||||||
|
return to_coloru8(light(to_colorf(c), lightness));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::size_t N>
|
||||||
|
geom::vector<std::uint8_t, N> dark(geom::vector<std::uint8_t, N> c, float darkness = 0.5f)
|
||||||
|
{
|
||||||
|
return to_coloru8(dark(to_colorf(c), darkness));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline generic_color light(generic_color const & c, float lightness = 0.5f)
|
||||||
|
{
|
||||||
|
return generic_color{light(c.c, lightness)};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline generic_color dark(generic_color const & c, float darkness = 0.5f)
|
||||||
|
{
|
||||||
|
return generic_color{dark(c.c, darkness)};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue