33 lines
996 B
C++
33 lines
996 B
C++
#include <psemek/vecr/colorizer.hpp>
|
|
#include <psemek/geom/swizzle.hpp>
|
|
|
|
namespace psemek::vecr
|
|
{
|
|
|
|
gfx::color_4f colorize(gfx::color_rgba const & color, geom::point<float, 2> const &, sdf_sample const &)
|
|
{
|
|
return gfx::to_colorf(color);
|
|
}
|
|
|
|
gfx::color_4f colorize(gradient const & gradient, geom::point<float, 2> const & p, sdf_sample const &)
|
|
{
|
|
return gfx::lerp(
|
|
gfx::to_colorf(gradient.color0),
|
|
gfx::to_colorf(gradient.color1),
|
|
geom::clamp(sdf(gradient.shape, p).value + 0.5f, {0.f, 1.f})
|
|
);
|
|
}
|
|
|
|
gfx::color_4f colorize(lighting const & lighting, geom::point<float, 2> const & p, sdf_sample const & sample)
|
|
{
|
|
auto const real_sample = lighting.shape ? sdf(lighting.shape, p) : sample;
|
|
|
|
auto normal = geom::swizzle<0, 1, -1>(real_sample.gradient * lighting.slope);
|
|
normal[2] = 1.f;
|
|
|
|
auto factor = 0.5f + 0.5f * geom::dot(geom::normalized(normal), lighting.direction);
|
|
|
|
return gfx::lerp(gfx::to_colorf(lighting.color0), gfx::to_colorf(lighting.color1), factor);
|
|
}
|
|
|
|
}
|